By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
create table test1 (id integer, value text);
insert into test1 values
(1, 'xyz'), (2, 'xxy');
create table test2 (id integer, value text);
insert into test2 values
(3, 'yyy'), (4, 'yxy');
CREATE TABLE
INSERT 0 2
CREATE TABLE
INSERT 0 2
SELECT json_agg(jbo.val)
FROM (
SELECT json_build_object('ID', t1.id, 'someText', t1.value)
FROM test1 t1
UNION ALL
SELECT json_build_object('ID', t2.id, 'someText', t2.value)
FROM test2 t2
) AS jbo(val)
json_agg |
---|
[{"ID" : 1, "someText" : "xyz"}, {"ID" : 2, "someText" : "xxy"}, {"ID" : 3, "someText" : "yyy"}, {"ID" : 4, "someText" : "yxy"}] |
SELECT 1