Re: backslash-dot quoting in COPY CSV - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: backslash-dot quoting in COPY CSV
Date
Msg-id 20190127131036.GC4672@paquier.xyz
Whole thread Raw
In response to Re: backslash-dot quoting in COPY CSV  (Bruce Momjian <bruce@momjian.us>)
Responses Re: backslash-dot quoting in COPY CSV
Re: backslash-dot quoting in COPY CSV
List pgsql-hackers
On Thu, Jan 24, 2019 at 10:09:30PM -0500, Bruce Momjian wrote:
> This seems like a bug to me.  Looking at the code, psql issues the
> prompts for STDIN, but when it sees \. alone on a line, it has no idea
> you are in a quoted CSV string, so it thinks the copy is done and sends
> the result to the server.  I can't see an easy way to fix this.  I guess
> we could document it.

In src/bin/psql/copy.c, handleCopyIn():

/*
 * 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;
}

This story pops up from time to time..
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: pg_basebackup, walreceiver and wal_sender_timeout
Next
From: Andrew Gierth
Date:
Subject: Re: Early WIP/PoC for inlining CTEs