PostgreSQL选择JSON数组

问题描述 投票:0回答:1

有一个名为Example的表,其中有一个名为Value的列,其中包含一些示例数据value1value2value3

如何将表中的值选择为JSON数组?

[ "value1", "value2", "value3" ]
json postgresql
1个回答
3
投票
create table example ( value text );
insert into example values ('value1'), ('value2'), ('value3');
select json_agg(value) from example;
            json_agg            
────────────────────────────────
 ["value1", "value2", "value3"]
© www.soinside.com 2019 - 2024. All rights reserved.