I am writing a PSQL script and using variables (for psql -variable key = value command line syntax).
This works fine for a top-level area, for example, select * from: key, but I create functions with a script and need a variable in them.
So the syntax is kind of
create function foo() returns void as
$$
declare
begin
grant select on my_table to group :user;
end;
$$
language plpgsql;
crash: user.
As far as I understand psql variables, this is a simple macro replacement function, but it does not process function bodies. Is there any syntax for such cases? Environment: a user with $$ is working on a replacement, but psql is not working on $$.
Is there any other way to do this other than offline macro processing (sed, awk, etc.)?