This is my query
and it works. I store the list of dictionaries inside my jsonb
column.
SELECT
items.title
FROM
items
WHERE
jsonb_path_exists(items.types::jsonb, '$[*] ? (@.target == "discount")')
Is there any way to write this without jsonb_path_exists()
function?
Also, do JSON Processing Functions use indexing?
I want to simplify the readability/look of my query because it is so long. And curious if I can get any performance improvements by not using JSON Processing Functions.
I tried to replace it with @?
but failed. This is what I used (quote from PostgreSQL):
jsonb @? jsonpath → boolean
Does JSON path return any item for the specified JSON value?
'{"a":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)' → t
Any help is very much appreciated.
@?
but failed" - please also show us the query you tried. How did it fail?jsonb
to begin with? If it's defined asjsonb
the cast is useless (and you can shorten your query by removing it). If it'sjson
(or even worsetext
) then you should convert it tojsonb
so that you don't need the cast everywhere and indexes are easier to define (and use)