Re: \copy produces CSV output that cannot be read by \copy

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Nicolas Barbier <nicolas(dot)barbier(at)gmail(dot)com>
Cc: PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: \copy produces CSV output that cannot be read by \copy
Date: 2017-08-05 16:39:19
Message-ID: CAB7nPqQvFQz=C2q8aTs5YGRe==796EwnjcmjXmW4J4McZUF8Ow@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Aug 4, 2017 at 2:38 PM, Nicolas Barbier
<nicolas(dot)barbier(at)gmail(dot)com> wrote:
> Analysis: I think that neither the writing nor the reading is incompatible
> with the documentation. Rather, there doesn’t seem to be a way to write such
> values to CSV that will be read back correctly (or at least I couldn‘t find
> such a way), as the reader always stops when encountering \. on a line by
> itself, and because there doesn’t seem to be a way to escape such a value in
> a way that wouldn’t produce a \. on a line by itself.

The format produced by COPY OUT looks fine to me, and can be reloaded
with a plain COPY (not \copy). And you may be interested in this bit
from src/bin/psql/copy.c:
/*
* 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)
{
copydone = true;
break;
}
postgresql.org is offline now, and I don't have this thread at hand,
but I guess that the answer is there...
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-08-05 16:52:28 Re: \copy produces CSV output that cannot be read by \copy
Previous Message Igor Neyman 2017-08-04 13:23:26 Re: Replication to Postgres 10 on Windows is broken