Searching inside JSON array in MySQL

核能气质少年 提交于 2019-12-25 09:10:36

问题


I have a table of Products that also contains JSON datatype with JSON array - json_array() field.

For the example "Products" table includes the following:

ProductID
ProductName
ProductDesc
CreateDate
Price
HistoricalPrices (json) 

I am appending the data using the follow query syntax:

    UPDATE Products 
SET    HistoricalPrices =
           json_array_append(HistoricalPrices, 
               '$', json_object('CreateDate', '2016-05-01', 'Price', 23.65)
           )
WHERE  ProductID = 1;

Example of structure of the JSON array:

> [
>     {
>         "CreateDate": "2016-05-01",
>         "Price": 12.34
>     },
>     {
>         "CreateDate": "2016-05-22",
>         "Price": 12.50
>     } ]

Would it be possible to search inside the JSON array for a specific productID. Like looking for specific prices in a date range ?

来源:https://stackoverflow.com/questions/38423045/searching-inside-json-array-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!