I just learned about the meaning of dollar-quoting in PostgreSQL. Now I was wondering, how would I handle dollar-quoting when executing an SQL statement from psql commandline?
If possible, I would like to avoid using escaping with single quotes.
The statement I want to execute looks something like this:
sudo -u postgres psql -d db_name -c "CREATE FUNCTION my_function(name text)
RETURNS void AS
$BODY$
...
$BODY$
LANGUAGE plpgsql;"
But I get a syntax error at or near "$"
and don't know how to handle this. I couldn't find any hint out there.