You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But this is ugly and tedious to do so for any inner json I need.
Apparently, the culprit is get_json_value that returns BasicCondition, which doesn't support JSON functions.
But get_json_value returns a json that can be used for all other JSON operators, so it should return a different type that allows that.
I managed to make such type by naively creating a new class that derives from both BasicCriterion and JSON:
classJsonCriterion(BasicCriterion, JSON):
pass
Then I used it instead of get_json_value, and it managed to create the correct sql query I needed:
This way, instead of calling table.data.get_json_value('key').get_json_value(1).get_json_value('inner_key')
one can simply call table.data.get_json_value('key', 1, 'inner_key')
I tried to construct a query that accesses inner object inside a json.
So if I have a JSONB column called
data
with the value:I want to filter it using SQL query like this:
Sadly, trying the following fails:
I managed to work around it by using the implementation of
contains
:But this is ugly and tedious to do so for any inner json I need.
Apparently, the culprit is
get_json_value
that returns BasicCondition, which doesn't support JSON functions.But
get_json_value
returns a json that can be used for all other JSON operators, so it should return a different type that allows that.I managed to make such type by naively creating a new class that derives from both
BasicCriterion
andJSON
:Then I used it instead of
get_json_value
, and it managed to create the correct sql query I needed:If this was the implementation of
get_json_value
it would work and support any level of inner json objects, not just arrays.The text was updated successfully, but these errors were encountered: