Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is there a json type in the mysql database

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you whether there is a json type in the mysql database, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Mysql has a json type. Starting from version 5.7, MySQL introduces the JSON data type, which allows you to directly manipulate json data, but below the MySQL5.7 version, you need to rely on data types such as varchar or text to save data of JSON format in the table.

JSON types in MySQL

Json is a very easy to use data type. Before mysql5.7, people used string to store json, but there is a problem that they can not manipulate json,5.7, so they can directly manipulate json data.

There is nothing to say about the creation of json, which does not need to be updated with a default length of 0, and you can insert queries with string. Individuals do not like to give the data to the background, so give it to the database for processing as an example: a table in the database has a content_json field with such data! {"bill": [{"bill": [{"id": "C81AEAD03F90000142E81B405F6FADC0", "uuid": "cfd872541b3b4507a50c2b2eda6bef28", "billid": "kjdzyljgmzsfzypj", "pageno": [], "billver": "V1", "billname": "New Test", "fjNumber": "" "trueName": "," allPageno ": [{" top ": 13," left ": 7}]," billValue ": {}," isOtherZL ":"," billNumber ":"," fjTMNumber ":"} {"id": "C81AED69D6400001A07818551D9EBEC0", "uuid": "05d87c8052cd44209c684407d200b7ec", "billid": "opztsfpsgd", "pageno": [], "billver": "V1", "billname": "invoice purchase", "fjNumber": "," trueName ":" "allPageno": [{"top": 13, "left": 7}], "isOtherZL": "," billNumber ":", "fjTMNumber": ""}], "index": " "dependBjBill": {"formula": "," keyView ":"}, "codeCondition": {"formula": "," keyView ":"}," billRuleCondition ": {" formula ":", "keyView": ""}} " {"bill": [{"id": "C81AED84903000019B29EAB0196014CE", "uuid": "0d93fe614d09489cbad8fa5a3d160289", "billid": "kjdzcwgwht", "pageno": [], "billver": "V1", "billname": "Financial consideration", "fjNumber": "," trueName ":" "allPageno": [{"top": 39, "left": 7}], "isOtherZL": "," billNumber ":", "fjTMNumber": ""}], "index": " "dependBjBill": {"formula": "," keyView ":"}, "codeCondition": {"formula": "," keyView ":"}," billRuleCondition ": {" formula ":", "keyView": ""}}], "questions": [] "relyonCondition": {}}

The structure is like this, we need to query the lowest uuid! According to the condition to check whether bill is an array of bill or an array, then how to check the bottom uuid?

Personally, I prefer to use a method like lambda, which is, after all, a compelling and good-looking operation:

SELECT content_json- >'$.bill [*] .bill [*] .uuid 'from b WHERE JSON_CONTAINS (content_json- >' $.bill [*] .bill [*] .uuid','["cfd872541b3b4507a50c2b2eda6bef28"]')

Query result

Code analysis:

Content_json- >'$.bill [] .bill [] .uuid'

Represents a content_json field

"$" is a must symbol point to represent an object

* stands for all

Then the code means to query the uuid of all the bill (the first) and all the bill (the second) in the content_json field to form an array to return.

The condition followed by where means that there is a value that can be one or more.

JSON_CONTAINS (field, parameter)

The field must be the specified value to be checked, such as content_json- >'$.bill [] .bill [] .uuid'

The parameter must be of type json. String is not allowed.

The above is all the contents of the json type in the mysql database, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report