Răzvan Flavius Panda
Răzvan Flavius Panda

Reputation: 22106

PostgreSQL select into JSON array

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

Answers (1)

Christoph Berg
Christoph Berg

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

Related Questions