Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines - Mailing list pgsql-general

From Daniel Verite
Subject Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines
Date
Msg-id 6f5b0072-c629-413a-a79b-6633160cd75c@manitou-mail.org
Whole thread Raw
In response to COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines  (Dominique Devienne <ddevienne@gmail.com>)
Responses Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines
Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines
List pgsql-general
    Dominique Devienne wrote:

> These values are 'normal'. I'm not use to CSV, but I suppose
> such newlines
> must be encoded, perhaps as \n, since AFAIK CSV needs to be 1 line per row,
> no?

No, but such fields must be enclosed by double quotes, as documented
in RFC 4180 https://datatracker.ietf.org/doc/html/rfc4180

Consider this output:

psql> COPY (values (1, E'ab\ncd'), (2,'efgh')) TO STDOUT CSV;
1,"ab
cd"
2,efgh

That's 2 records on 3 lines.
If you feed this to a parser and it chokes on it, it means that it's
not a valid CSV parser.

Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines
Next
From: Dominique Devienne
Date:
Subject: Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines