Re: Selecting a JSON object of arrays from a PostgreSQL table

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Selecting a JSON object of arrays from a PostgreSQL table
Date: 2018-01-02 09:28:14
Message-ID: CAADeyWjGX8iWMkYo_MCtvgwLWpexHrs_rbmK=hkEoDhO3Ewu_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Also got this nice suggestion at https://stackoverflow.com/q/48050127/165071
-

SELECT COALESCE(
json_object_agg(
gid, array_to_json(y)
), '{}'::json)
FROM (
SELECT gid,
array_agg(
json_build_object(
'uid', uid,
'created', EXTRACT(EPOCH FROM created)::int,
'msg', msg)
) AS y
FROM chat /* WHERE gid = 0 */
GROUP BY gid
) x;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message James Harper 2018-01-02 11:24:38 MSSQL compatibility layer
Previous Message Durumdara 2018-01-02 08:22:57 Select for update / deadlock possibility?