I want to find whether a specific path exists in a jsonb value using a psql query.
For example, for this path: {"333":"opc":["1333"]}
This value should return true:
'{"333":{"opc":[{"1333":"3787"}]}}'
But these values should return false:
'{"333":{"opc":[{"104":"3787"}]}}'
'{"54":{"opc":[{"1333":"3787"},{"1334":"37"}]}}'
'{"333":{"opc":[]}}'
I've tried some variations using the @>
operator but couldn't quite get the right syntax.
ex:
select
'{"333":{"opc":[{"1333":"3787"},{"1334":"37"}]}}'::jsonb @>
'{"333":{"opc":[{"1333"}]}}'::jsonb
this gives me an invalid syntax error