添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
2
4

More than 3 years have passed since last update.

MySQL でJSON型のnull/空配列のデータをフィルターする

Posted at

環境は MySQL 5.7

値が null のレコードを検索する
SELECT data FROM test WHERE JSON_EXTRACT(data, "$.value") = CAST('null' AS JSON);
+-----------------+
| data            |
+-----------------+
| {"value": null} |
+-----------------+
値が 空配列 のレコードを検索する
SELECT data FROM test WHERE JSON_EXTRACT(data, "$.value") = JSON_ARRAY();
+---------------+
| data          |
+---------------+
| {"value": []} |
+---------------+
  • https://dev.mysql.com/doc/refman/5.7/en/json-creation-functions.html#function_json-object
  • https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-extract
  • https://dev.mysql.com/doc/refman/5.7/en/json.html
  • Register as a new user and use Qiita more conveniently

    1. You get articles that match your needs
    2. You can efficiently read back useful information
    What you can do with signing up
    4