On 12 August 2016 at 16:34, Christoph Berg <m...@debian.org> wrote:
> > 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 > > TO STDOUT. > Ahem, whoops. It's the simple things sometimes... Attached amended. > Also, I vaguely get what you wanted to say with "a driver ... > wrapper", but it's pretty nonsensical if one doesn't know about the > protocol details. I don't have a better suggestion now, but I think it > needs rephrasing. I don't like it either, but didn't come up with anything better. The problem is that every driver calls it something different. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
From e713a8a7c5373a137d417d0001b11e296b841f5a Mon Sep 17 00:00:00 2001 From: Craig Ringer <cr...@2ndquadrant.com> Date: Fri, 12 Aug 2016 15:42:12 +0800 Subject: [PATCH] Emit a HINT when COPY can't find a file Users often get confused between COPY and \copy and try to use client-side paths with COPY. The server of course cannot find the file. Emit a HINT in the most common cases to help users out. --- src/backend/commands/copy.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index f45b330..c902e8b 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1761,7 +1761,9 @@ BeginCopyTo(Relation rel, if (!is_absolute_path(filename)) ereport(ERROR, (errcode(ERRCODE_INVALID_NAME), - errmsg("relative path not allowed for COPY to file"))); + errmsg("relative path not allowed for COPY to file"), + errhint("Paths for COPY are on the PostgreSQL server, not the client. " + "You may want psql's \\copy or a driver COPY ... TO STDOUT wrapper"))); oumask = umask(S_IWGRP | S_IWOTH); cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W); @@ -1770,7 +1772,9 @@ BeginCopyTo(Relation rel, ereport(ERROR, (errcode_for_file_access(), errmsg("could not open file \"%s\" for writing: %m", - cstate->filename))); + cstate->filename), + errhint("Paths for COPY are on the PostgreSQL server, not the client. " + "You may want psql's \\copy or a driver COPY ... TO STDOUT wrapper"))); if (fstat(fileno(cstate->copy_file), &st)) ereport(ERROR, @@ -2796,7 +2800,9 @@ BeginCopyFrom(Relation rel, ereport(ERROR, (errcode_for_file_access(), errmsg("could not open file \"%s\" for reading: %m", - cstate->filename))); + cstate->filename), + errhint("Paths for COPY are on the PostgreSQL server, not the client. " + "You may want psql's \\copy or a driver COPY ... FROM STDIN wrapper"))); if (fstat(fileno(cstate->copy_file), &st)) ereport(ERROR, -- 2.5.5
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers