4

I have a table A with a column b as jsonb

        b
------------------
 {"c": 1}
 {"c": 1, "d": 2}

how to build a query for rows where d is missing?

SELECT * FROM A WHERE b@>'{"c":1}';

returns all rows while

SELECT * FROM A WHERE b@>'{"c":1,"d":null}';

returns none ( due d is not null in first row );

1 Answer 1

5

You can use the ? operator to test for the presence of a key. To find those where the key does not exist, you can negate the expression:

select *
from a 
where not b ? 'd';
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.