Issue
I have a script with this command
/usr/bin/psql postgres -h localhost -U postgres -c "GRANT CONNECT ON DATABASE "famdb-develop" TO fullwood;"
When I ran it, I got this error:
ERROR: syntax error at or near "-"
LINE 1: GRANT CONNECT ON DATABASE famdb-develop TO fullwood;
How can I escape the dash in this command?
Solution
Looks like the quotes aren't being passed down to PostgreSQL. You need to escape them by prefixing them with backslashes (\
):
/usr/bin/psql postgres -h localhost -U postgres -c "GRANT CONNECT ON DATABASE \"famdb-develop\" TO fullwood;"
# Here -----------------------------------------------------------------------^--------------^
Answered By - Mureinik Answer Checked By - Candace Johnson (WPSolving Volunteer)