MariaDB
[MariaDB] Json Array Object Type Search
쵸송
2023. 1. 11. 16:09
실행 환경: MariaDB
array 안에 object 형식으로 들어가 있는 경우 검색하는 방법이다.
json_extract를 사용하여 height value 를 추출한후 json_search를 통해서 검색 해내는 방법이다.
SET @json_document = '{ "name": "ab", "specs": [{ "weight": 10, "height": "as" }, { "weight": 101, "height": "as1" }] }';
SELECT JSON_SEARCH(JSON_EXTRACT(@json_document, '$.specs[*].height'), 'all', "as") is not null;
결과
결과 값이 있을 경우 1, 없을 경우 0으로 검색 된다.