Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Dominique Devienne <ddevienne(at)gmail(dot)com>
Cc: Daniel Verite <daniel(at)manitou-mail(dot)org>, david(dot)g(dot)johnston(at)gmail(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines
Date: 2022-03-13 08:53:49
Message-ID: CA+bJJbxZGr6EJwEzhuk8krWJ0T5isCzrv5u1jxWsRupvmwY-iw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dominique:

On Fri, 11 Mar 2022 at 21:13, Dominique Devienne <ddevienne(at)gmail(dot)com> wrote:
> But sure, if TEXT does the kind of pseudo-CSV I need, I'd change it to use it.

Text, the original format for copy, is much easier to manage than CSV.
It can easily be managed as you can split the whole input on newlines
to get records, split each record on tabs to get fields, then unescape
each field.

In C++ you can easily read it a char at a time and build along the way
or, if you have a whole line, unescape it in place and build a
vector<char*> pointing two the buffer. If you are testing, the split
on newline/split on tab approach gives you a list of escaped strings
easily compared to escaped patterns.

I've never had problems with it in decades, and in fact I use a
extension of it ( with a \E code similar to the \N trick for nulls
for 0-element lines, which are not useful in db dumps, but I and I
need to use, as "\n" decodes to {""} but I need to express {}, which I
emit as "\\E\n". It is and old problem, "join by tabs join by
newlines" makes things "prettier" but can lead to no final new line
and no way to express empty sets, "terminate with tabs terminate with
newlines" leads to uglier/harder to read lines but can express them).

Francisco Olarte.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dilip Kumar 2022-03-13 11:35:18 Re: Support logical replication of DDLs
Previous Message Francisco Olarte 2022-03-13 08:41:09 Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines