pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: Svante Richter <pgsql-bugs@richter.id>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: COPY TO CSV produces data that is incompatible/unsafe for \COPY FROM CSV
Date: Sun, 14 Aug 2022 00:00:53 -0700
Message-ID: <20220814070053.GA92855@rfd.leadboat.com> (raw)
In-Reply-To: <bfcd57e4-8f23-4c3e-a5db-2571d09208e2@beta.fastmail.com>
References: <bfcd57e4-8f23-4c3e-a5db-2571d09208e2@beta.fastmail.com>

On Wed, Jun 15, 2022 at 02:16:14PM +0200, Svante Richter wrote:
> The documentation for COPY says "To avoid any misinterpretation, a `\.` data value appearing as a lone entry on a line is automatically quoted on output, and on input, if quoted, is not interpreted as the end-of-data marker".
> 
> The input part only seems to work when using the COPY FROM CSV command, not \COPY FROM CSV. This is mentioned in a previous message here https://www.postgresql.org/message-id/a89f47e1-f716-4ae3-b882-cab5032a5d66%40manitou-mail.org but not documented.

I agree this warrants a doc mention.  Also, the previous thread seems to have
ended with a focus on [\copy ... from stdin], but it's broader than that:

> COPY testtable FROM '/run/postgresql/test.csv' CSV; -- This one works
> \COPY testtable FROM '/run/postgresql/test.csv' CSV; -- This one does not work

The psql documentation says [\copy ... from stdin] looks for "\.".  It says
nothing about doing that for [\copy ... from filename].  I wonder if psql
should change the filename case to send the whole file to the server, ignoring
"\." inside.  (That is to say, change to match the psql documentation.)  This,
too, has an avoidable case of the problem:

  create table t (c text);
  \copy t from program 'printf ''"foo\n\\.\nbar"''' with csv





view thread (8+ messages)  latest in thread

Message-ID: <20220814070053.GA92855@rfd.leadboat.com>
Permalink:  ../20220814070053.GA92855@rfd.leadboat.com/
Also on:    postgresql.org/message-id/20220814070053.GA92855@rfd.leadboat.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noah@leadboat.com, pgsql-bugs@richter.id, pgsql-bugs@lists.postgresql.org
  Subject: Re: COPY TO CSV produces data that is incompatible/unsafe for \COPY FROM CSV
  In-Reply-To: <20220814070053.GA92855@rfd.leadboat.com>

* 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