Here is a table:
create table test(
fjson jsonb
);
then insert some value:
insert into test values
('{"name":"A"}'::jsonb),
('{"name":"B"}'::jsonb),
('{"name":"C"}'::jsonb);
I want to get a json array like below:
[
{"name":"A"},
{"name":"B"},
{"name":"C"}
]
How to write the SQL?
Thanks.
Problem solved. thanks
do $$ declare
jdata jsonb;
begin
create temp table test(
fjson jsonb
) on commit drop;
insert into test values
('{"name":"A"}'::jsonb),
('{"name":"B"}'::jsonb),
('{"name":"C"}'::jsonb);
select (select jsonb_agg(fjson) from test) into jdata;
raise notice '%',jdata;
end;
$$ language plpgsql;