Re: psql JSON output format

Поиск
Список
Период
Сортировка
От Dean Rasheed
Тема Re: psql JSON output format
Дата
Msg-id CAEZATCWZWEapZU8AOc8rwEukaO_FBG-=Xue0y+FCFaDFHDPUAQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: psql JSON output format  (Jelte Fennema-Nio <postgres@jeltef.nl>)
Ответы Re: psql JSON output format  (Laurenz Albe <laurenz.albe@cybertec.at>)
Re: psql JSON output format  (Christoph Berg <myon@debian.org>)
Список pgsql-hackers
On Mon, 18 Dec 2023 at 16:34, Jelte Fennema-Nio <postgres@jeltef.nl> wrote:
>
> On Mon, 18 Dec 2023 at 16:38, Christoph Berg <myon@debian.org> wrote:
> > We'd want both patches even if they do the same thing on two different
> > levels, I'd say.
>
> Makes sense.
>

I can see the appeal in this feature. However, as it stands, this
isn't compatible with copy format json, and I think it would need to
duplicate quite a lot of the JSON output code in client-side code to
make it compatible.

Consider, for example:

CREATE TABLE foo(col json);
INSERT INTO foo VALUES ('"str_value"');

copy foo to stdout with (format json) produces this:

{"col":"str_value"}

which is as expected. However, psql -Jc "select * from foo" produces

[
{ "col": "\"str_value\"" }
]

The problem is, various datatypes such as boolean, number types, json,
and jsonb must not be quoted and escaped, since that would change them
to strings or double-encode them in the result. And then there are
domain types built on top of those types, and arrays, etc. See, for
example, the logic in json_categorize_type(). I think that trying to
duplicate that client-side is doomed to failure.

Regards,
Dean



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

Предыдущее
От: Nathan Bossart
Дата:
Сообщение: Re: add AVX2 support to simd.h
Следующее
От: Paul Jungwirth
Дата:
Сообщение: Re: SQL:2011 application time