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

From Bruce Momjian
Subject Re: backslash-dot quoting in COPY CSV
Date
Msg-id 20190128214009.GG26761@momjian.us
Whole thread Raw
In response to Re: backslash-dot quoting in COPY CSV  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
On Sun, Jan 27, 2019 at 10:10:36PM +0900, Michael Paquier wrote:
> 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..

The killer is I committed this C comment six years ago, and didn't
remember it.  :-O

    commit 361b94c4b98b85b19b850cff37be76d1f6d4f8f7
    Author: Bruce Momjian <bruce@momjian.us>
    Date:   Thu Jul 4 13:09:52 2013 -0400
    
        Add C comment about \copy bug in CSV mode
        Comment: 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

Glad I mentioned the URL, at least.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Proposed refactoring of planner header files
Next
From: Peter Geoghegan
Date:
Subject: Re: Making all nbtree entries unique by having heap TIDs participatein comparisons