From e713a8a7c5373a137d417d0001b11e296b841f5a Mon Sep 17 00:00:00 2001 From: Craig Ringer 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