clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3364508 fiddles created (36290 in the last week).

with tt (id, name) as ( values (1,'hello'), (4,'good'), (7,'world'), (9,'happy'), (10,'funny'), (12,'stack'), (15,'queue'), (18,'map'), (19,'list'), (23,'code') ) SELECT *, row_to_json(tt.*) as json_obj, row_number() OVER (ORDER BY id) - 1 as idx FROM tt
id name json_obj idx
1 hello {"id":1,"name":"hello"} 0
4 good {"id":4,"name":"good"} 1
7 world {"id":7,"name":"world"} 2
9 happy {"id":9,"name":"happy"} 3
10 funny {"id":10,"name":"funny"} 4
12 stack {"id":12,"name":"stack"} 5
15 queue {"id":15,"name":"queue"} 6
18 map {"id":18,"name":"map"} 7
19 list {"id":19,"name":"list"} 8
23 code {"id":23,"name":"code"} 9
 hidden batch(es)


with tt (id, name) as ( values (1,'hello'), (4,'good'), (7,'world'), (9,'happy'), (10,'funny'), (12,'stack'), (15,'queue'), (18,'map'), (19,'list'), (23,'code') ) SELECT json_agg(json_obj) FROM ( SELECT *, row_to_json(tt.*) as json_obj, row_number() OVER (ORDER BY id) - 1 as idx FROM tt ) s GROUP BY idx / 4
json_agg
[{"id":10,"name":"funny"}, {"id":12,"name":"stack"}, {"id":15,"name":"queue"}, {"id":18,"name":"map"}]
[{"id":19,"name":"list"}, {"id":23,"name":"code"}]
[{"id":1,"name":"hello"}, {"id":4,"name":"good"}, {"id":7,"name":"world"}, {"id":9,"name":"happy"}]
 hidden batch(es)