I am using Postgres JSONB, in order to store bunch of properties in one field for one complex system.
Where I have one field, that is called properties and properties do have trees of objects.
Here is the small piece of data from properties.
{
"urls": [],
"games": false,
"images": [],
"rating": null,
"founded": 0,
"bannedIn": ["00000000-0000-0000-8888-000000000001",
"00000000-0000-0000-8888-000000000002"],
"comments": "",
"chat": false
}
In table I have some objects those has bannedIn set to some guids, some object has empty array and some objects don't has bannedIn property at all.
Now I am trying to get every row where bannedIn contains "00000000-0000-0000-8888-000000000001"
(WORKS)
When I try to get every row where bannedIn doesn't contains "00000000-0000-0000-8888-000000000001"
(WORKS)
But When I query to count all where properties doesn't has bannedIn at all it fallback with 0 count, even though I have 1K object with out bannedIn.
WORKS
$builder = $entityManager->createQueryBuilder()
->select('e')
->from(Entity::class, 'e')
->where('e.otherObject = :guid')->setParameter('guid', $guid)
->andWhere('GET_JSON_FIELD(e.properties, \'bannedIn\') LIKE ?1')
->setParameter(1, '%00000000-0000-0000-8888-000000000001%');
Is there a way to query jsonb where key does not exist?
I have also tried following, didn't work.
The ? operator is implemented by calling its function jsonb_exists(column_name, value)