Reputation: 22106
Having a table named Example
with a column named Value
and some example data in it value1
, value2
, value3
.
How can I select the values in the table into a JSON array?
[ "value1", "value2", "value3" ]
Upvotes: 0
Views: 196
Reputation: 311
create table example ( value text );
insert into example values ('value1'), ('value2'), ('value3');
select json_agg(value) from example;
json_agg
────────────────────────────────
["value1", "value2", "value3"]
Upvotes: 4