I have table users
with json column details
.
I want to fetch all user records where details["email"] is null or email key doesn't exist.
This doesn't work:
SELECT users.* FROM users where details->'email' IS NOT NULL;
ERROR: operator does not exist: json -> boolean
use brackets ()
. Looks like compiler tries to see it like details->('email' IS NOT NULL)
. So you can fix it like this:
select * from users where (details->'email') is not null
sql fiddle demo
actually, to get records where details["email"] is null or email key doesn't exist, you can use this query:
select * from users where (details->>'email') is null
as described in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With