pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Matthias Apitz <guru@unixarea.de>
Cc: Postgres general <pgsql-general@postgresql.org>
Subject: Re: Two small questions re/ COPY CSV data into table
Date: Tue, 04 Jun 2019 11:32:45 +0100
Message-ID: <877ea1aby6.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <20190604100247.GA2800@c720-r342378>
References: <20190604100247.GA2800@c720-r342378>

>>>>> "Matthias" == Matthias Apitz <guru@unixarea.de> writes:

 Matthias>    ... WITH DELIMITER '|', FORMAT CSV ;

I think you misread the docs; the new-style syntax would be

COPY ... WITH (DELIMITER '|', FORMAT CSV);

where the parens are not optional. The old-style syntax with no parens
after WITH is what you were using before.

 Matthias> 2. The CSV export is done by some Sybase tool which escapes
 Matthias> the delimiter as '\|', i.e. putting a backslash before the
 Matthias> delimiter. I found no way that COPY understands this
 Matthias> excaping. Any ideas?

That sounds like the file is not actually a CSV - why do you think it
is?

PG accepts two formats (actually 3 if you count binary format which is
rarely used):

TEXT: records are delimited by newlines, columns are delimited by a
delimiter character (default tab), there are no quotation marks, any
newline, backslash, or delimiter in the data must be escaped as a
backslash-sequence (e.g. \n or \012)

CSV: columns may be quoted (in which case delimiters and newlines inside
them are ignored), records are delimited by newlines _outside_ quoted
fields, there are no backslash-sequences or escapes outside of quoted
fields, quote characters inside quoted fields are doubled (though
there's an option to change this).

PG follows the CSV spec at https://www.ietf.org/rfc/rfc4180.txt fairly
closely.

-- 
Andrew (irc:RhodiumToad)





view thread (10+ messages)  latest in thread

Message-ID: <877ea1aby6.fsf@news-spur.riddles.org.uk>
Permalink:  ../877ea1aby6.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/877ea1aby6.fsf@news-spur.riddles.org.uk

 · 

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 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-general@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, guru@unixarea.de
  Subject: Re: Two small questions re/ COPY CSV data into table
  In-Reply-To: <877ea1aby6.fsf@news-spur.riddles.org.uk>
  References: <20190604100247.GA2800@c720-r342378> <877ea1aby6.fsf@news-spur.riddles.org.uk>

* 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