Reputation: 4742
I have the following script:
DO $$
DECLARE
i INTEGER;
BEGIN
i := 5;
COPY public.mytable (id, name) FROM stdin;
i abc
\.
END $$;
I run the above script using psql. I want to take the value from the variable i
and use it in the COPY
command. How can I do this in PL/pgSQL? Can \echo be used?
Upvotes: 1
Views: 727
Reputation: 246848
You can use a variable with dynamic SQL:
EXECUTE format('COPY %I FROM ''/path/file''', i);
But you cannot use COPY ... FROM STDIN
in PL/pgSQL, because there is no standard input in a function.
Upvotes: 1