I have a table in PostgreSQL that contains two columns, one being a bigint primary key and the other contains JSONB with a mix of arrays and simple key value pairs.
If I wanted to return the rows in the table where the JSON data in the second column contains a certain exact key value pair, what would the query need to look like? The second column is a JSONB column.
I have been reviewing the PostgreSQL documentation, but I cannot find the operators I would need to make this happen.
I have a table in PostgreSQL that contains two columns, one being a bigint primary key and the other contains JSONB with a mix of arrays and simple key value pairs.
If I wanted to return the rows in the table where the JSON data in the second column contains a certain exact key value pair, what would the query need to look like? The second column is a JSONB column.
I have been reviewing the PostgreSQL documentation, but I cannot find the operators I would need to make this happen.
Share Improve this question edited Feb 3 at 5:40 Ken White 126k15 gold badges236 silver badges466 bronze badges asked Feb 3 at 3:52 ma89581ma89581 11 Answer
Reset to default 1Your question is not totally clear on that, but if the key-value pair you are looking for is not at the top level of the JSON structure, your best option would be to use a JSONPATH search.
This example searches for a { "key": "value" }
pair anywhere nested in a JSON structure:
SELECT JSONB '{
"x": [
{ "key": "value" },
{ "key": "othervalue" }
]
}'
@@ 'strict $.**.key == "value"';
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745250205a4618633.html
评论列表(0条)