0

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" ]
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169

1 Answers1

4
create table example ( value text );
insert into example values ('value1'), ('value2'), ('value3');
select json_agg(value) from example;
            json_agg            
────────────────────────────────
 ["value1", "value2", "value3"]
Christoph Berg
  • 302
  • 1
  • 3