[mysql] JSON数据操作

/ 20,133评论 / 82248阅读 / 0点赞

前言

在MySql中使用

声明json类型的字段

create table test(
    uids json not null default ('[]')
);
default ('[{"name":"coolight"}, {"name","洛天依"}]')
或
default ("[{'name':'coolight'}, {'name','洛天依'}]")

Mysql中常用的操作json函数

JSON_LENGTH(json1)=JSON_LENGTH(json2) and JSON_CONTAINS(json1, json2)
// 例如:
update test set enable=true where JSON_LENGTH(json1)=JSON_LENGTH(json2) and JSON_CONTAINS(json1, json2);
// 示例:在数组末尾追加元素
SELECT JSON_ARRAY_APPEND('[1, 2, 3]', '$', 4); 
// 得到 [1,2,3,4]

// 示例:对数组添加一个元素,如果已经存在则不添加
// ["1000000", "1000001", "1000002"]
update test set uids=json_array_append(uids, '$','1000001') where id=777 and JSON_CONTAINS(uids,JSON_ARRAY('1000001'))=0;
// 没有添加,注意where ... and 后面 使用JSON_CONTAINS判断了是否包含准备添加的元素
// ["1000000", "1000001", "1000002"]
update test set uids=json_remove(uids, JSON_UNQUOTE(JSON_SEARCH(uids, 'one','1000001'))) where id=777;
// ["1000000", "1000002"]
create TRIGGER auto_reset after insert on test for each row
BEGIN
    update test set uids=json_array_append(uids, '$', CAST(NEW.uid as char)) where id=NEW.id;
END;
  1. The very next time I read a blog, I hope that it doesnt disappoint me just as much as this one. After all, I know it was my choice to read, however I truly believed you would have something interesting to talk about. All I hear is a bunch of crying about something you can fix if you werent too busy seeking attention.

  2. Good online game https://moonprincess-play.com/ where you can make money, buy yourself a new phone or car, close the mortgage on your house and only one month, hurry up to register and win.

  3. 你的狗应该有多重?

  4. Coikemn说道:

    cialis 5mg All analyses were based on the intention to treat principle and used the treatment assignment determined at randomization, regardless of the treatment status at the time of analysis

  5. 缅因猫是好宠物吗?

  6. 为什么我的狗舔它的爪子?

  7. sitenizi takip ediyorum makaleler Faydalı bilgiler için teşekkürler

  8. 为什么狗这么喜欢揉肚子?

  9. 猫可以多久不拉屎?

  10. VORVOSESK说道:

    tamoxifen dose Based on the results of these test trials, Philips will negotiate a lump sum payment to resolve all remaining claims

  11. van escort说道:

    bu konuda bu kadar net bilgiler internette malesef yok bu yüzden çok iyi ve başarılı olmuş teşekkürler.

  12. 为什么当你回家时猫会抓东西?

  13. 猫可以吃火腿吗?

  14. 什么年龄的猫可以生小猫?

  15. 狗害怕的迹象是什么?

  16. 为什么猫躺在他们的垃圾箱里?

  17. 如何阻止狗和小狗的破坏性咀嚼

  18. 对猫来说太冷有多冷?

  19. 猫在野外吃什么?

  20. 如何牵引训练拉动的狗

  21. 猫可以吃松鼠吗?

  22. van escort bayan说道:

    Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.

  23. 为什么猫把耳朵放回去?

  24. 猫舔你的鼻子是什么意思?

  25. 绝育母猫叫什么?

  26. 如何判断你的猫是否在做噩梦

  27. 为什么猫如此灵活?

  28. 缅因猫能活多久?

  29. 猫可以吃黄金糖浆吗?

  30. 8 种不同类型的狗项圈

  31. VORVOSESK说道:

    For more, visit acc buy stromectol australia Thus, it might be expected that the presence of CTCs should be associated with a worse outcome for all patients in the SUCCESS A study, regardless of the method for CTC detection

  32. 猫多久放一次屁?

  33. 关于猫,圣经怎么说?

  34. 俄罗斯蓝猫有黄色的眼睛吗?

  35. 如何在爆发时保护您的狗免受钩端螺旋体病的侵害

  36. 拥抱宠物角落趋势的 4 种方法

  37. 我的猫被黄蜂蜇了。

  38. çok bilgilendirici bir yazı olmuş ellerinize sağlık teşekkür ederim

  39. 波斯猫有多少种?

  40. tuşba escort说道:

    hocam gayet açıklayıcı bir yazı olmuş elinize emeğinize sağlık.

  41. 为什么猫这么懒?

  42. 猫可以吃辣椒豆吗?

  43. 狗的交流和绥靖手势

回复 为什么当你回家时猫会抓东西? 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注