This works fine:
jsonb_path_query(p.blah::jsonb, '$[*] ? (@.fruit == "banana") ')
but if I want to compare the JSON "fruit" property to a value from a column, I cannot get Postgres to parse it, like so:
jsonb_path_query(p.blah::jsonb, '$[*] ? (@.fruit == c.fruit) ')
I get hard-to-understand errors like "syntax error, unexpected IDENT_P at end of jsonpath input"
2
Answers
Use
format()
to build the second parameter, e.g.:All JSONpath functions also accept an additional JSON parameter that contains key/value pairs that can be referenced inside the JSON path expression: