有一个名为Example
的表,其中有一个名为Value
的列,其中包含一些示例数据value1
,value2
,value3
。
如何将表中的值选择为JSON数组?
[ "value1", "value2", "value3" ]
create table example ( value text );
insert into example values ('value1'), ('value2'), ('value3');
select json_agg(value) from example;
json_agg
────────────────────────────────
["value1", "value2", "value3"]