I can use the -v v1=foo syntax just fine for queries in my sql script, but I can't figure out how to use that parameter in a copy statement. I'd like to execute the script like:
psql -d my_db -f ./exports.sql -v v1="'/Users/username/test.json'"
And in the script do some version of:
copy (
select * from bar
) to :v1;
or
DO $$
BEGIN
EXECUTE
'copy (select * from bar) to ' || :v1;
END $$
or
DO $$
BEGIN
EXECUTE
format('copy (select * from bar) to %L',:v1);
END $$
But none of the above work :(