[mysql] JSON数据操作

/ 37,058评论 / 148821阅读 / 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. MarvinMek说道:

    doxycycline tablets [url=https://doxycyclinea.online/#]order doxycycline 100mg without prescription[/url] online doxycycline

  2. Billyeroge说道:

    https://amoxila.pro/# where to buy amoxicillin pharmacy

  3. Billyeroge说道:

    http://amoxila.pro/# amoxicillin generic

  4. HenryIsona说道:

    buy prednisone online without a prescription: prednisone drug costs – generic prednisone pills

  5. MarvinMek说道:

    amoxicillin buy canada amoxicillin no prescipion purchase amoxicillin online

  6. ダッチワイフThe Skene’s fill with fluid during sexual arousal and if stimulated during sexual arousal,sex,

  7. HenryIsona说道:

    buy doxycycline online 270 tabs: doxy – 100mg doxycycline

  8. MarvinMek说道:

    amoxicillin 500 mg capsule [url=https://amoxila.pro/#]amoxicillin 50 mg tablets[/url] amoxicillin 500mg tablets price in india

  9. Richardfrota说道:

    generic prednisone for sale: generic prednisone pills – prednisone 30 mg tablet

  10. scam说道:

    I urge you stay away from this site. My own encounter with it has been purely disappointment as well as concerns regarding scamming practices. Exercise extreme caution, or alternatively, seek out an honest service for your needs.

  11. Billyeroge说道:

    https://gabapentinneurontin.pro/# neurontin 100 mg cap

  12. Billyeroge说道:

    https://amoxila.pro/# where can i get amoxicillin

  13. HenryIsona说道:

    200 mg doxycycline: buy doxycycline monohydrate – doxycycline order online

  14. CharlesGib说道:

    neurontin 300mg: neurontin 300 mg cost – neurontin canada

  15. lose money说道:

    I highly advise stay away from this platform. The experience I had with it has been only dismay as well as suspicion of scamming practices. Exercise extreme caution, or alternatively, seek out an honest site for your needs.

  16. MarvinMek说道:

    prednisone pills cost 1 mg prednisone daily prednisone tablets

  17. lose money说道:

    I strongly recommend to avoid this platform. My personal experience with it was purely dismay as well as concerns regarding deceptive behavior. Exercise extreme caution, or alternatively, seek out an honest service to meet your needs.

  18. lose money说道:

    I strongly recommend steer clear of this platform. My own encounter with it was nothing but disappointment along with suspicion of scamming practices. Exercise extreme caution, or alternatively, seek out a more reputable site to fulfill your requirements.

  19. lose money说道:

    I highly advise steer clear of this platform. The experience I had with it was purely disappointment along with suspicion of fraudulent activities. Exercise extreme caution, or better yet, look for an honest service to meet your needs.

  20. HenryIsona说道:

    zithromax for sale usa: zithromax cost australia – how to get zithromax online

  21. zmdii ltfvf vqvbo smsqv qyjlo aulrj

  22. Richardfrota说道:

    amoxicillin 500 coupon: where can i get amoxicillin – amoxicillin 500 mg price

  23. lose money说道:

    I strongly recommend steer clear of this platform. My personal experience with it was nothing but frustration and suspicion of deceptive behavior. Be extremely cautious, or alternatively, seek out a trustworthy site to fulfill your requirements.

  24. MarvinMek说道:

    doxycycline 100mg capsules [url=https://doxycyclinea.online/#]doxycycline tetracycline[/url] doxycycline vibramycin

  25. lose money说道:

    I strongly recommend steer clear of this platform. My personal experience with it was nothing but dismay along with concerns regarding deceptive behavior. Exercise extreme caution, or better yet, find an honest site for your needs.

  26. Billyeroge说道:

    https://prednisoned.online/# generic prednisone 10mg

  27. CharlesGib说道:

    neurontin 300 600 mg: gabapentin 600 mg – neurontin 600 mg coupon

  28. lose money说道:

    I strongly recommend steer clear of this site. My personal experience with it has been only disappointment as well as concerns regarding scamming practices. Be extremely cautious, or even better, find a more reputable service to fulfill your requirements.

  29. lose money说道:

    I highly advise steer clear of this site. The experience I had with it was nothing but dismay as well as doubts about fraudulent activities. Be extremely cautious, or alternatively, find an honest service for your needs.

  30. Billyeroge说道:

    https://prednisoned.online/# where can i get prednisone

  31. HenryIsona说道:

    prednisone acetate: order prednisone from canada – best pharmacy prednisone

  32. MarvinMek说道:

    buy cheap amoxicillin amoxicillin 30 capsules price amoxicillin 250 mg price in india

  33. qrknx otzds mkrlk znvys qsmca bydeg

  34. HenryIsona说道:

    where can i buy zithromax uk: zithromax cost canada – zithromax over the counter uk

  35. MarvinMek说道:

    prednisone 50 mg buy [url=https://prednisoned.online/#]non prescription prednisone 20mg[/url] over the counter prednisone medicine

  36. Billyeroge说道:

    https://zithromaxa.store/# zithromax online usa

  37. Billyeroge说道:

    https://prednisoned.online/# generic prednisone cost

  38. HenryIsona说道:

    prednisone 54: prednisone 30 – prednisone pill 10 mg

  39. Richardfrota说道:

    neurontin price india: buy brand neurontin – neurontin cost in singapore

  40. MarvinMek说道:

    buy doxycycline hyclate 100mg without a rx doxycycline prices doxycycline pills

  41. Emkzqy说道:

    cenforce several – brand viagra pills slip

  42. aviator game说道:

    ysvvv xzzev fgjog xhelt xessi ivsmo

  43. HenryIsona说道:

    prednisone over the counter uk: prednisone 5 mg tablet cost – prednisone 5 mg brand name

  44. MarvinMek说道:

    how much is prednisone 10 mg [url=http://prednisoned.online/#]price of prednisone tablets[/url] cheap prednisone 20 mg

  45. Billyeroge说道:

    https://doxycyclinea.online/# buy doxycycline without prescription uk

  46. Billyeroge说道:

    https://prednisoned.online/# cost of prednisone tablets

  47. CharlesGib说道:

    doxycycline 100mg dogs: buy doxycycline online uk – doxycycline 100mg tablets

  48. HenryIsona说道:

    buy zithromax: zithromax 250 mg pill – buy zithromax online fast shipping

  49. Elton Baisten说道:

    rtp ak4d adalah platform perjudian online pasti wd di nusantara.

  50. lose money说道:

    I urge you steer clear of this site. My personal experience with it was purely disappointment along with concerns regarding fraudulent activities. Be extremely cautious, or even better, look for an honest platform for your needs.

发表回复

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