WITH "user" AS (VALUES(1, 'taro'), (2, 'jiro'))
SELECT JSON_AGG("user")
FROM "user";
json_agg
-----------------------------------
[{"column1":1,"column2":"taro"}, +
{"column1":2,"column2":"jiro"}]
(1 row)
CREATE TYPE "user" AS (id integer, name text);
WITH "user" AS (VALUES(1, 'taro'), (2, 'jiro'))
SELECT JSON_AGG("user"::"user") -- タプルの型が同じなので "user" 型にキャストできる
FROM "user";
json_agg
---------------------------
[{"id":1,"name":"taro"}, +
{"id":2,"name":"jiro"}]
(1 row)
CREATE TABLE "user" (id integer, name text);
CREATE TYPE
したときと同じように "user" 型が定義される
WITH "user" AS (VALUES(1, 'taro'), (2, 'jiro'))
SELECT JSON_AGG("user"::"user") -- タプルの型が同じなので "user" 型にキャストできる
FROM "user";
json_agg
---------------------------
[{"id":1,"name":"taro"}, +
{"id":2,"name":"jiro"}]
(1 row)