mysql-json

Using MySQL JSON field to join on a table

做~自己de王妃 提交于 2019-11-27 14:30:45
I have a json field that stores a list of ids (not best practice here I know), I want to know if it's possible to use do operations on this JSON field and use them in the sql. Below is a fictitious example of what I'm trying to achieve, is something like this doable? CREATE TABLE user ( user_id INT, user_name VARCHAR(50), user_groups JSON ); CREATE TABLE user_group ( user_group_id INT, group_name VARCHAR(50) ); INSERT INTO user_group (user_group_id, group_name) VALUES (1, 'Group A'); INSERT INTO user_group (user_group_id, group_name) VALUES (2, 'Group B'); INSERT INTO user_group (user_group_id

How to update JSON data type column in MySQL 5.7.10?

只愿长相守 提交于 2019-11-27 10:47:45
问题 I have started using MySQL 5.7.10 recently and I am liking the native JSON Data type a lot. But I ran into a problem when it comes to updating a JSON type value. Questions: Below is the table format, here I want to add 1 more key in JSON data column for t1 table. Right now I have to fetch the value modify it and Update the table. So it involves an extra SELECT statement. I can insert like this INSERT INTO t1 values ('{"key2":"value2"}', 1); mysql> select * from t1; +--------------------+-----

JSON vs. Serialized Array in database [closed]

拥有回忆 提交于 2019-11-27 10:19:28
What are the advantages and disadvantages of storing JSON data in MySQL database vs. serialized array? JSON encode () & decode () PHP Version >= 5.0.0 Nesting Limit of 20. PHP Version >= 5.2.3 Nesting Limit of 128. PHP Version >= 5.3.0 Nesting Limit of 512. Small footprint vs PHP's serialize'd string. serialize () & unserialize () PHP Version >= 4.0.0 Methods are not lost on PHP Datatype Object. __wakeup() magic method called on any object being unserialize. (VERY POWERFUL) It has been noted that it is some times best the base64 encode strings put into the database, and base64 decode strings

How to search JSON data in MySQL?

随声附和 提交于 2019-11-26 14:34:17
I am inserting my data in a database with json_encoded . Now I want to search in "feature", but I can't. MySQL query: SELECT `id` , `attribs_json` FROM `products` WHERE `attribs_json` REGEXP '"1":{"value":[^"3"$]' This query shows me all rows with key "1" and value is any thing not value is "3" My data is: {"feature":{"1":{"value":"["2","3"]"}, "2":{"value":["1"]}, "5":{"value":""}, "3":{"value":["1"]}, "9":{"value":""}, "4":{"value":"\u0633\u0627\u062a\u0646"}, "6":{"value":""}, "7":{"value":""}, "8":{"value":""} }, "show_counter":"0", "show_counter_discount":"" }} Sachin Vairagi If you have