Re: Emitting JSON to file using COPY TO

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Emitting JSON to file using COPY TO
Дата
Msg-id CAKFQuwZf_B_CCA2+sVHG+KU+fDdaKyp4mUOoDQt5HmDD6neOPg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Emitting JSON to file using COPY TO  ("Daniel Verite" <daniel@manitou-mail.org>)
Ответы Re: Emitting JSON to file using COPY TO  (Dave Cramer <davecramer@postgres.rocks>)
Список pgsql-hackers
On Thursday, December 7, 2023, Daniel Verite <daniel@manitou-mail.org> wrote:
        Joe Conway wrote:

> The attached should fix the CopyOut response to say one column. I.e. it
> ought to look something like:

Spending more time with the doc I came to the opinion that in this bit
of the protocol, in CopyOutResponse (B)
...
Int16
The number of columns in the data to be copied (denoted N below).
...

this number must be the number of columns in the source.
That is for COPY table(a,b,c)   the number is 3, independently
on whether the result is formatted in text, cvs, json or binary.

I think that changing it for json can reasonably be interpreted
as a protocol break and we should not do it.

The fact that this value does not help parsing the CopyData
messages that come next is not a new issue. A reader that
doesn't know the field separator and whether it's text or csv
cannot parse these messages into fields anyway.
But just knowing how much columns there are in the original
data might be useful by itself and we don't want to break that.

This argument for leaving 3 as the column count makes sense to me.  I agree this content is not meant to facilitate interpreting the contents at a protocol level.
 


The other question for me is, in the CopyData message, this
bit:
" Messages sent from the backend will always correspond to single data rows"

ISTM that considering that the "[" starting the json array is a
"data row" is a stretch.
That might be interpreted as a protocol break, depending
on how strict the interpretation is.

We already effectively interpret this as “one content line per copydata message” in the csv text with header line case.  I’d probably reword it to state that explicitly and then we again don’t have to worry about the protocol caring about any data semantics of the underlying content, only physical semantics.

David J.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Sacha Hottinger
Дата:
Сообщение: AW: Building PosgresSQL with LLVM fails on Solaris 11.4
Следующее
От: Matthias van de Meent
Дата:
Сообщение: Re: initdb caching during tests