How can I escape a probable hyphen in a comand line like the following:
$ for i in db1 db2 db1-db2; do su - postgres -c "psql -c \"alter database \"$i\" with connection limit = 0;\""; done
ALTER DATABASE
ALTER DATABASE ERROR: syntax error at or near "-" at character 19 LINE 1: alter database db1-db2 with connection limit = 0;
^
The “quoting hell” can be somehow alleviated by providing the SQL in standard input as a here-string.
In your case I think this should do the job: