1

I'm using the COPY ... FROM ... WITH CSV... syntax however I'm finding that the filename can be easily derived from the value stored elsewhere in the database and that changing it in a script all the time is a maintenance nightmare.

Is it possible to SELECT the filename ie:

COPY ... FROM (SELECT filename FROM mytable WHERE x=1) WITH CSV...

Thanks, p.

0

1 Answer 1

1

No you can't, you can't use a subquery to get the filename.

You can however use dynamic SQL inside a stored procedure. As of version 9.0 you can use DO:

DO $$ DECLARE _file TEXT; BEGIN SELECT filename INTO _file FROM mytable WHERE x=1; EXECUTE 'COPY ... FROM ' || _file || ' WITH CSV...;'; RAISE INFO 'File % imported', _file; END; $$; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.