Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux