In Postgres 13, for the below query, the jsonb
values are getting filtered correctly based on "priority":
SELECT jsonb_path_query(
'{
"100": {
"name": "test",
"priority": 5
},
"101": {
"name": "test2",
"priority": 10
},
"102": {
"name": "test3",
"priority": 15
}
}'
, '$.* ? (@.priority > 10)')
Output:
{
"name": "test3",
"priority": 15
}
But I want to get the root key also. In this case I want to get the root for "test3" which is "102". To achieve this, I tried the below query:
SELECT jsonb_path_query(
'{
"100": {
"name": "test",
"priority": 5
},
"101": {
"name": "test2",
"priority": 10
},
"102": {
"name": "test3",
"priority": 15
}
}'
, '$ ? (@.*.priority > 10)')
But the output data is not getting filtered based on "priority".
Here is the output:
{
"100": {
"name": "test",
"priority": 5
},
"101": {
"name": "test2",
"priority": 10
},
"102": {
"name": "test3",
"priority": 15
}
}
The desired output would be:
{
"102": {
"name": "test3",
"priority": 15
}
}
How can I filter the data using an SQL/JSON path expression and the get the root key as well?