I write PSQL script and using variables (for *psql --variable key=value* commandline syntax).

This works perfectly for top level scope like *select \* from :key*, but I create functions with the script and need variable value inside them.

So, the syntax like

```
create function foo() returns void as
$$
declare
begin
    grant select on my_table to group :user;
end;
$$
language plpgsql;

```

fails at *:user*.

As far as I understand psql variables is a plain macro substitution feature, but it doesn't process function bodies.
Are there any escaping syntax for such cases? Surrounding *:user* with *$$* works regarding substitution, but psql fails at *$$*.

Are there any other way to do this besides standalone macro processing (sed, awk, etc)?