assuming you have a table (note json
type):
create table MY_TABLE (
ID int not null,
JSON_VALUE json not null
);
with data:
insert into MY_TABLE (ID, JSON_VALUE) values (1, '{"myKey":"should be found", "otherKey":"123"}');
insert into MY_TABLE (ID, JSON_VALUE) values (2, '{"somethingElse":"should not"}');
you can use postgre json function to get all the IDs of
select ID from
(select ID, json_extract_path(JSON_VALUE, 'myKey') AS keys from MY_TABLE) t
where keys is null -- equivalent to {'myKey': { '$exists': False }}
-- or
where keys is not null -- equivalent to {'myKey': { '$exists': True }}
to clarify the result of sub-query: select ID, json_extract_path(JSON_VALUE, 'myKey') AS keys from MY_TABLE
would be:
id keys
1 should be found
2 (null)