I have a loop command script on psql
that looks like this:
script.sql
DO $$DECLARE
data_rec RECORD;
r RECORD;
r2 RECORD;
BEGIN
select mytables.data_id into data_rec from mytables where id = :arg1;
FOR r IN select * from
(select * from ...)
LOOP
FOR r2 IN select * from
(...)
LOOP
......
END LOOP;
END LOOP;
END$$;
And I want to pass arg1
as a argument from the command line:
psql -h db.server.com -f script.sql -v arg1=1234 > foo.out
But I keep getting a syntax error at where id = :arg1
, so I'm out of ideas how to pass a simple parameter to this script. Suggestions welcome