MySQL5.7.22:当json的键包含点字符时,如何选择json值?

9udxz4iz  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(332)

json结构如下:

{
  "pixel.uuid": "1ca86b7d7505c48363b2a5d9dde0c7e4",
  "innerWidth": "1440"
}

问题:如何选择“pixel.uuid”?我试过这些组合:

select json->"$.pixel.uuid" from TrackingData_experimental

 

select json->"$.pixel\.uuid" from TrackingData_experimental

 

select json->{"$.pixel.uuid"} from TrackingData_experimental

  

select JSON_EXTRACT(json, '$.pixel.uuid') from TrackingData_experimental

但是运气不好。谢谢您!

0pizxfdo

0pizxfdo1#

用双引号分隔键:

mysql> select json->'$."pixel.uuid"' from TrackingData_experimental;
+------------------------------------+
| json->'$."pixel.uuid"'             |
+------------------------------------+
| "1ca86b7d7505c48363b2a5d9dde0c7e4" |
+------------------------------------+

如果希望返回的值不带引号,请执行以下操作:

mysql> select json->>'$."pixel.uuid"' from TrackingData_experimental;
+----------------------------------+
| json->>'$."pixel.uuid"'          |
+----------------------------------+
| 1ca86b7d7505c48363b2a5d9dde0c7e4 |
+----------------------------------+

相关问题