Re: Returning values from an array of JSONB objects.

Поиск
Список
Период
Сортировка
От sighup
Тема Re: Returning values from an array of JSONB objects.
Дата
Msg-id 570E277A.9060004@sighup.eu
обсуждение исходный текст
Ответ на Re: Returning values from an array of JSONB objects.  (Vitaly Burovoy <vitaly.burovoy@gmail.com>)
Список pgsql-general
On 13/04/2016 11:53, Vitaly Burovoy wrote:
> On 4/13/16, Vitaly Burovoy <vitaly.burovoy@gmail.com> wrote:
>> On 4/13/16, sighup <rts@sighup.eu> wrote:
>>> Hi, please excuse either my stupidity or naivety regarding this but I'm
>>> a bit confused. Give the following basic table structure :
>>>
>>> TABLE Data (
>>>     ID INT NOT NULL,
>>>     Markers jsonb NOT NULL
>>> );
>>>
>>> And the following data:
>>>
>>> INSERT INTO Data (ID, Markers) VALUES(1, '[ {"idle": true, "items": 8,
>>> "done": 0}, {"idle": true, "items": 8, "done": 0}]') ;
>
> Prerequisite:
> CREATE TYPE myrowtype AS (idle bool, items int, done int);
>
> Couple examples:
>
>>> How can I extract the value of the 'items' key either as two rows
>
> SELECT (jsonb_populate_recordset(NULL::myrowtype, Markers)).items
> FROM Data WHERE (ID = X);
>
>>> and or a sum of both.
>
> SELECT sum(items) FROM(
>      SELECT (jsonb_populate_recordset(NULL::myrowtype, Markers)).items
>      FROM Data WHERE (ID = X)
> )AS t;
>
>> You should use a proper function "jsonb_populate_recordset" [1].
>>
>> [1] http://www.postgresql.org/docs/9.5/static/functions-json.html
>

Hello Vitaly,

I have just tried this and of course it works, thank you ever so much
for your time and effort I genuinely appreciate it.

--
Bill



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

Предыдущее
От: Vitaly Burovoy
Дата:
Сообщение: Re: Returning values from an array of JSONB objects.
Следующее
От: Alex Ignatov
Дата:
Сообщение: Re: Freezing localtimestamp and other time function on some value