I have a query:
SELECT json_agg(t) FROM t
, which fails, when t table is empty. How to return no rows in this case?
t
2
To get no row if the table is empty, you can try this :
SELECT json_agg(t) FROM t WHERE EXISTS (SELECT 1 FROM t) GROUP BY t.id HAVING COUNT(id) > 0;
You might be looking for
SELECT COALESCE(json_agg(t), '[]') FROM t
Click here to cancel reply.
2
Answers
To get no row if the table is empty, you can try this :
You might be looking for