我有一个看起来像这样的JSON对象:
{
"all_books": [
{
"book_id": "dcbdfc3b-6b4f-44b6-9309-2a855f840c66",
"book_name": "book14",
"book_type": "public"
},
{
"book_id": "d367ffba-b2e1-411f-9250-6e0a51bdaa9b",
"book_name": "book19",
"attributes": {
"attribute_json": "{\"number\": \"9\"}"
},
"book_type": "private"
},
{
"book_id": "e39a2006-4286-4f9f-81a5-a513a34b933c",
"book_name": "book16",
"attributes": {
"attribute_json": "{\"number\": \"25\"}"
},
"book_type": "private"
}
]
}
我需要查询像这样的大数据表:
这是我到目前为止的查询
select *
from test_data_json
where
book_json -> 'all_books' @> '[{"book_id":"d367ffba-b2e1-411f-9250-6e0a51bdaa9b", "book_type":"public"}]' OR
(
book_json -> 'all_books' @> '[{"book_id":"d367ffba-b2e1-411f-9250-6e0a51bdaa9b", "book_type":"private"}]' -- AND
-- determine if the attribute matches --> all_books/attributes/attribute_json
)