[PATCH] COPY vs \copy HINT - Mailing list pgsql-hackers

From Craig Ringer
Subject [PATCH] COPY vs \copy HINT
Date
Msg-id CAMsr+YEqtD97qPEzQDqrCt5QiqPbWP_X4hmvy2pQzWC0GWiyPA@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] COPY vs \copy HINT  (Christoph Berg <myon@debian.org>)
List pgsql-hackers
Hi all

I see this sort of question quite a bit:


where the user wonders why

COPY gemeenten 
  FROM 'D:\CBS_woningcijfers_2014.csv'
  DELIMITER ';' CSV

fails with 

ERROR:  could not open file "D:\CBS_woningcijfers_2014.csv" for reading: No such file or directory'

and as usual, it's because the path is on their local host not the Pg server.

I think we should emit a HINT here, something like:

ERROR:  could not open file "D:\CBS_woningcijfers_2014.csv" for reading: No such file or directory'
HINT:  Paths for COPY are on the PostgreSQL server, not the client. You may want psql's \copy or a driver COPY ... FROM STDIN wrapper


as a usability improvement. Trivial patch attached. 

I'm not sure how to avoid the need to translate the string multiple times, or if the tooling will automatically flatten them. I haven't bothered with the stat() failure or isdir cases, since they seem less likely to be the cause of users being confused between client and server.

Sample output:

postgres=# COPY x FROM '/tmp/somepath';
ERROR:  could not open file "/tmp/somepath" for reading: No such file or directory
HINT:  Paths for COPY are on the PostgreSQL server, not the client. You may want psql's \copy or a driver COPY ... FROM STDIN wrapper

postgres=# COPY x TO '/root/nopermissions';
ERROR:  could not open file "/root/nopermissions" for writing: Permission denied
HINT:  Paths for COPY are on the PostgreSQL server, not the client. You may want psql's \copy or a driver COPY ... FROM STDIN wrapper

postgres=# COPY x TO 'relpath';
ERROR:  relative path not allowed for COPY to file
HINT:  Paths for COPY are on the PostgreSQL server, not the client. You may want psql's \copy or a driver COPY ... FROM STDIN wrapper



--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Forbid use of LF and CR characters in database and role names
Next
From: Masahiko Sawada
Date:
Subject: Re: new autovacuum criterion for visible pages