I Have a data like this -
So i need to find out all rows with id=203498. How can i write a query for this ? Any Help ?
I Have a data like this -
So i need to find out all rows with id=203498. How can i write a query for this ? Any Help ?
Use the JSON containment operator @>
:
WHERE jsoncol @> '[ { "id": 203498 }]';
[{ "id": 203498 }]
–
Obstacle <@ ANY
. But you cannot index that. –
Pin @Query(value = "select * from conversations where meta\\:\\:jsonb @> :query", nativeQuery = true)
I am using JPA query something like this and it fails, can you help? query: any(array['{"reference": {"chartId": "1"}}', '{"reference": {"chartId": "2"}}']::jsonb[])
–
Lincoln It depends your data so please add to example data but I will give you example data.
If your data like this
id | cars_info
----+------------------------------------------------------------------------------------
1 | {"id": 1, "sold": true, "brand": "Toyota", "color": ["red", "black"], "price": 285000}
2 | {"id": 2, "sold": false, "brand": "Honda", "color": ["blue", "pink"], "price": 25000}
3 | {"id": 3, "sold": true, "brand": "Mitsubishi", "color": ["black", "gray"], "price": 604520}
Your query is like this. Maybe it can occurs some errors but your query will be seem like that.
SELECT * FROM cars WHERE cars_info -> 'id' = '1';
There is one more way of going in, when you are dealing with BIG JSON: you can drill down to a specific field of json (if the structure is predefined):
{
"method": "POST",
"request": {
"id": 111,
"type": "mytupe",
"date": "2000-01-01",
"amount": 2150,
},
"response": {
"message": {
"status": "success",
"confirmation_CODE": "CONFIRMATION0006229"
},
"success": true
}
}
SELECT * FROM TABLE_NAME WHERE
jsoncol -> 'request' @> ' { "id": 111 } '
OR details ->'response'->'message' @> ' { "confirmation_CODE": "CONFIRMATION0006229" } '
© 2022 - 2025 — McMap. All rights reserved.