Failed to invoke copy to remote psql server

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for PostgreSQL in Delphi and C++Builder
Post Reply
jaheon
Posts: 5
Joined: Tue 24 Apr 2012 06:33

Failed to invoke copy to remote psql server

Post by jaheon » Tue 24 Apr 2012 06:50

Hi..
I have failed to invoke copy query to remote psql server through dbx driver with message 'sntax error at or near "\"'
ex) SQLConnection1.ExecuteDirect('/copy test from ''d:\a.txt''');
It was successful to invoke same query through SQL shell provided psql.

Please let me know how to invoke remote copy query through dbx driver.

Thanks and regards.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 24 Apr 2012 09:01

Hello,

For running the copy [table_name] FROM/TO command, you haven't to specify the '/' symbol before the command, i.e.

Code: Select all

SQLConnection1.ExecuteDirect('copy test from ''d:\a.txt''');

jaheon
Posts: 5
Joined: Tue 24 Apr 2012 06:33

Post by jaheon » Wed 25 Apr 2012 03:51

Hello,

As you know, I have already been using copy command to a local psql server without '\ symbol through psql shell or dbx driver.
But now I have failed to invoke copy command to a remote psql server.

Following is that I refered to states of PSQL documentation 'sql-copy.html'.
"Do not confuse COPY with the psql instruction \copy. \copy invokes COPY FROM STDIN or COPY TO STDOUT, and then fetches/stores the data in a file accessible to the psql client. Thus, file accessibility and access rights depend on the client rather than the server when \copy is used."
from http://www.postgresql.org/docs/9.1/static/sql-copy.html

Repeatly, It was successful to invoke copy command with '\ to remote psql server through psql shell, but failed to remote psql server through dbx driver.

Please let me know how to invoke copy command to remote psql server through dbx driver.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 25 Apr 2012 09:14

hello,

In the previous post, I have made you an example of loading data from a file to table with the help of the COPY command using dbExpress driver. If you cannot load data - please send the error text and the whole code demonstrating the problem to alexp*devart*com in order that we can reproduce the problem and advice you a solution.

jaheon
Posts: 5
Joined: Tue 24 Apr 2012 06:33

Post by jaheon » Fri 27 Apr 2012 10:04

Hi.

I think that you are being confused 'copy' and '\copy' or you don't know '\copy' command.
I know how to use 'copy' with a file existing on a psql server.
But my concern is that it has failed to invoke 'copy' with a query data file existing on client side through dbx driver connected with network.
The file is not existing on a psql server but client side.

In addition, it was successful to invoke '\copy' with a query data file existing on client side by psql shell on client side, but failed through dbx driver with error message 'syntax error at or near "\"'.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Failed to invoke copy to remote psql server

Post by AlexP » Sat 28 Apr 2012 12:42

hello,

The \copy command is just a psql console command, and it cannot be executed in a SQL query. You can get help on available psql console commands by typing \? in the psql console, and on SQL commands - by typing \help in the psql console

Post Reply