\copy
is a psql
command, not an SQL command. psql
commands only work inside the psql
shell. Since you're talking directly to the database, you'd need to use the COPY
SQL command. However, COPY
usually works with the server's file system rather than the client's:
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the server. When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.
You'll probably need to use the STDIN option and PQputCopyData
to send the data over to the PostgreSQL server.