Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Variable substitution cannot be directly applied in psql's \copy command. However, you can use psql's built-in variable substitution to achieve the effect of variable substitution in a workaround.

Here's an example:

-- Set the variable
\set mypath '/path/to/myfile.csv'

-- Use the variable in the \copy command
\copy mytable from :'mypath' delimiter ',' csv;

This will substitute the value of the variable mypath in the \copy command.