From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: tgarnett@panjiva.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7709: psql \copy csv terminates with \. in quoted region
Date: Thu, 4 Jul 2013 13:10:01 -0400
Message-ID: <20130704171001.GD17790@momjian.us> (raw)
In-Reply-To: <24679.1354037624@sss.pgh.pa.us>
References: <E1TdNVQ-0001ju-GO@wrigleys.postgresql.org>
<24679.1354037624@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Tue, Nov 27, 2012 at 12:33:44PM -0500, Tom Lane wrote:
> tgarnett@panjiva.com writes:
> > psql \copy terminates at \. by itself in a line even if the format is csv
> > and the \. is inside a quoted region. This means that some values can't be
> > round-tripped by psql \copy. Tested and the native postgresql COPY handles
> > this case correctly.
>
> Ugh. This seems like a rather fundamental oversight in the CSV feature.
> The problem is that psql has no idea whether the copy is being done in
> CSV mode or not --- and even if it did, it doesn't parse the data fully
> enough to realize whether a \. line is inside quotes or not.
>
> In the case of out-of-line data files, it might be reasonable to just
> dispense with the check for \. altogether and always ship the whole file
> to the backend; I think there's a \. check on the backend side. (Not
> sure this is safe in V2 protocol, but I doubt anyone cares anymore
> about that.)
>
> In the case of in-line data in a script file, CSV mode seems a bit
> broken in any case; there's no concept of a terminator in CSV, AFAIK.
> So maybe we don't have to worry about that.
I have added a C comment documenting this bug; patch attached.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:copy.diff (text/x-diff, 646B) downloaddiff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.cnew file mode 100644index b5732c7..c1e7cfe
*** a/src/bin/psql/copy.c
--- b/src/bin/psql/copy.c
*************** handleCopyIn(PGconn *conn, FILE *copystr
*** 635,640 ****
--- 635,645 ----
/* check for EOF marker, but not on a partial line */
if (firstload)
{
+ /*+ * This code erroneously assumes '\.' on a line alone+ * inside a quoted CSV string terminates the \copy.+ * http://www.postgresql.org/message-id/E1TdNVQ-0001ju-GO@wrigleys.postgresql.org+ */
if (strcmp(buf, "\\.\n") == 0 ||
strcmp(buf, "\\.\r\n") == 0)
{
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, tgarnett@panjiva.com
Subject: Re: BUG #7709: psql \copy csv terminates with \. in quoted region
In-Reply-To: <20130704171001.GD17790@momjian.us>
References: <E1TdNVQ-0001ju-GO@wrigleys.postgresql.org> <24679.1354037624@sss.pgh.pa.us> <20130704171001.GD17790@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox