Where data
is JSONB column, I want to check if the key exists, normally I use:
SELECT id FROM users WHERE length(data->>'fingerprint_id') IS NULL;
Is there any better/shorter way to do this? since other alternative give incorrect result:
> SELECT id FROM users WHERE data->>'fingerprint_id' IS NULL;
ERROR: operator does not exist: jsonb ->> boolean
LINE 1: SELECT id FROM users WHERE data->>'fingerprint_id' IS NULL;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
> SELECT id FROM users WHERE data->>'fingerprint_id' = '';
id
----
(0 rows)