json_agg
vrátí hodnotu null z prázdné množiny:
select json_agg(t.*) is null
from (select 'test' as mycol where 1 = 2) t ;
?column?
----------
t
Pokud chcete prázdné pole json coalesce
to:
select coalesce(json_agg(t.*), '[]'::json)
from (select 'test' as mycol where 1 = 2) t ;
coalesce
----------
[]