Re: mogrify and indent features for jsonb

Поиск
Список
Период
Сортировка
От Sehrope Sarkuni
Тема Re: mogrify and indent features for jsonb
Дата
Msg-id CAH7T-aq0wuNwShpjKW9G35-KOtqUG0qaUTHjoqYWG8Qav+kfrQ@mail.gmail.com
обсуждение исходный текст
Ответ на mogrify and indent features for jsonb  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: mogrify and indent features for jsonb  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
For jsonb_indent, how about having it match up closer to the
JavaScript JSON.stringify(value, replacer, space)[1]? That way a user
can specify the indentation level and optionally filter the fields
they'd like to output.

In JS, the "replacer" parameter can be either a JS function or an
array of property names. I don't think the former is really possible
(in a SQL callable function) but the latter would be a text[]. The
"space" parameter can be either a string (used directly) or a number
(corresponding number of spaces).

The PG function signatures would be something like:

CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, replacer text[],
space text)
CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, replacer text[],
space int)

For convenience we could also include overloads with replacer removed
(since most people probably want the entire object):

CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, space text)
CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, space int)

Having json_stringify versions of these would be useful as well.

Regards,
-- Sehrope Sarkuni

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Allow "snapshot too old" error, to prevent bloat
Следующее
От: Andres Freund
Дата:
Сообщение: NOT NULL markings for BKI columns