0

Recently I have come across two queries as:

select jsonb_build_object('a', jsonb_agg(1))
 where false;

select jsonb_build_object('a', jsonb_agg(1))
 where false
having count(*) > 0;

First retuns {"a": null}, second - nothing, could you please explain me what happens in these 2 queries? I would expect nothing in result for BOTH.

1
  • 1
    Second query returns nothing because it filtered all records. If you have no records then result is nothing not null Commented Aug 27, 2018 at 7:11

1 Answer 1

2

It is not related to JSON functions.

select count(1) where false;

and

select count(1) where false having count(1) > 0;

providing same effect.

First query reporting that there is 0 records satisfied given condition in the where clause and in the second query having clause filtering out rows from the first query where count(1) <= 0

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.