Fwd: row_to_json() with numerical indices in stead of associative indices

Поиск
Список
Период
Сортировка
От Tjibbe
Тема Fwd: row_to_json() with numerical indices in stead of associative indices
Дата
Msg-id CAF_dx11b+MNy+ta+WPf6pDkapHVF-7vqzGSNYgVqnQ1_EXaReQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Fwd: row_to_json() with numerical indices in stead of associative indices  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-general
Hello there,

Is it possible to add an parameter for the function row_to_json()? So
you can choose for:

numerical indices:  [1, true, "string", null]
associative indices:   ["f1":1,"f2": true, "f3":"string","f4": null]

The this extra parameter can save bandwidth between the
webserver(postgresql/php) and client(javascript).

Now i'm doing it like this:

CREATE FUNCTION to_num_json(_in json) RETURNS json AS $$
DECLARE
_pair RECORD;
_arr json[];
BEGIN
   FOR _pair IN SELECT * FROM json_each(_in) LOOP
      _arr := _arr || _pair.value;
   END LOOP;
   RETURN to_json(_arr);
END 
$$ language plpgsql;

SELECT to_num_json(
    row_to_json((5, TRUE, 'string', NULL))
);

greetings

Tjibbe

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

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: What query optimisations are included in Postgresql?
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Trust intermediate CA for client certificates