Re: generating json without nulls

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: generating json without nulls
Дата
Msg-id CAKFQuwajBFsDgLqjkfbQGKM7tm9i0mUeqhR87pdfk0o027emOQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: generating json without nulls  (Tim Dudgeon <tdudgeon.ml@gmail.com>)
Ответы Re: generating json without nulls  (Tim Dudgeon <tdudgeon.ml@gmail.com>)
Список pgsql-sql
On Thu, May 7, 2015 at 8:29 AM, Tim Dudgeon <tdudgeon.ml@gmail.com> wrote:
That's not going to work. I want the row, I just don't want the values that are null.

Only thing that comes to mind:
1. Use the conversion function to get the json structure with nulls.
2. Use an explode function to convert the json into a table structure with (key, value) columns.
3. Filter that table where value is not null.
4. Convert the remaining entries into arrays
5. Pass the two arrays back into the json_object(keys text[], values text[])

You could dynamically build up a literal string array but the syntax challenges scare me:
json_object('{' ||
CASE WHEN col1 IS NULL THEN '' ELSE '"col1",' || val1 || '"' END ||
CASE WHEN col2 IS NULL THEN '' ELSE '"col2",' || val2 || '"' END ||
'}'::text[])

David J.

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

Предыдущее
От: Tim Dudgeon
Дата:
Сообщение: Re: generating json without nulls
Следующее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: generating json without nulls