Search Postgresql Archives

\copy Variable Substitution in 9.1.2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All,

I'm trying to use a variable for the filename portion of \copy.  I'm calling
psql on some SQL commands in a file from a shell script:

FILETOLOAD="/var/tmp/filetoload.${$}"
OPTIONS="--variable=outfile='${FILETOLOAD}'"
psql ${OPTIONS} -f /some/file.sql

In /some/file.sql:

\copy table(f1, f2, f3) from :outfile with delimiter '|';

Which yields:

psql:/some/file.sql:4: :outfile: No such file or directory

An \echo :outfile command confirms that the single-quoted filename is making
it to the SQL script, but it's not being used in the substitution by the
\copy command.

The only thing applicable to variable substitution with \copy I could find
was a somewhat contradictory paragraph in the psql man page:

The syntax of the command is similar to that of the SQL COPY(7) command.
Note that, because of this, special parsing rules apply to the \copy
command.  In particular, the variable substitution rules and backslash
escapes do not apply.

Thanks for any suggestions.

--
Gary Chambers

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux