Re: csv format for psql

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "Fabien COELHO" <coelho(at)cri(dot)ensmp(dot)fr>,"Pg Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: csv format for psql
Date: 2018-03-09 22:18:22
Message-ID: cd6020e3-fe39-4fdb-ba14-554d39d37c16@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

David G. Johnston wrote:

> I'm not following - if recordsep is not something that would
> interpreted as a newline then the file we output would have not
> structural newlines.
> It might have data newlines but those would be quoted.

They would be, but I don't quite understand the point
in your first sentence.
All I'm saying is that setting recordsep to '\r\n' does
not achieve the goal of obtaining CRLF line endings.

Here's an example with the unaligned mode, linux host:

(psql -At -P recordsep=$'\r\n' << EOF
select E'A\nB' union E'C\nD';
EOF
) | hexdump -C

The result is:
00000000 41 0a 42 0d 0a 43 0a 44 0a |A.B..C.D.|

The expectation of CRLF line endings is that every LF would be
preceded by CR, but here we get that only for 1 LF out of 4. That's
useless.

It's not a bug. We asked for a CRLF to separate our two
records and that's exactly what we got, no more no less.

In csv output, the difference would be that there would a double quote
character before A and after B, and before C and after D but otherwise
it would be the same mix of LF and CRLF.

I think that the point of recordsep in unaligned mode is you can set it
to something that never appears in the data, especially when embedded
newlines might be in the data. In CSV this is solved differently so
we don't need it.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2018-03-09 22:23:48 Re: PATCH: Unlogged tables re-initialization tests
Previous Message Peter Eisentraut 2018-03-09 21:42:30 Re: PQHost() undefined behavior if connecting string contains both host and hostaddr types