json_agg
mengembalikan null dari set kosong:
select json_agg(t.*) is null
from (select 'test' as mycol where 1 = 2) t ;
?column?
----------
t
Jika Anda ingin array json kosong coalesce
itu:
select coalesce(json_agg(t.*), '[]'::json)
from (select 'test' as mycol where 1 = 2) t ;
coalesce
----------
[]