This PostgreSQL COPY command works:
copy tablename from E'c:\\abc\\a.txt';
but I want the tablename to be dynamically generated. How can I do this?
This PostgreSQL COPY command works:
but I want the tablename to be dynamically generated. How can I do this? |
||||
|
You need to build a string, concatenating in the dynamic table name, and then use execute. Note that you escape the ' by ''. This also includes a dynamic name to save the file too. You need to replace savedir with the actual directory you are using.
EDIT: Since I first wrote this, I have discovered the format function, which I think is generally easier to read than sql generated with the concatenation operator || and has other advantages in other contexts.
See the official docs for a full discussion: http://www.postgresql.org/docs/9.1/static/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE |
|||||||||||||||||
|