[mysql] JSON数据操作

/ 37,113评论 / 149054阅读 / 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. Antoniadat说道:

    pharmacie en ligne: pharmacie en ligne livraison europe – pharmacie en ligne sans ordonnance

  2. click说道:

    Your passion for the subject matter is evident in every post you write. This was another outstanding article. Thank you for sharing!coinsslot

  3. Williamjes说道:

    gГјnstige online apotheke: online apotheke preisvergleich – apotheke online

  4. porn videos说道:

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

  5. bokep说道:

    I urge you stay away from this site. My personal experience with it has been nothing but disappointment and suspicion of scamming practices. Exercise extreme caution, or alternatively, seek out a trustworthy site to fulfill your requirements.

  6. Gichardkaf说道:

    Здравствуйте!
    Получите документы об образовании всех Вузов России с гарантированной доставкой по РФ без предоплаты.
    http://www.dlplomanrussia.com

  7. Williamjes说道:

    farmacias online seguras en espaГ±a: farmacia online envГ­o gratis – farmacias online seguras

  8. lose money说道:

    I strongly recommend stay away from this site. My personal experience with it was nothing but frustration along with concerns regarding scamming practices. Be extremely cautious, or better yet, look for a more reputable platform for your needs.

  9. lose money说道:

    I highly advise to avoid this platform. My own encounter with it has been purely dismay along with suspicion of fraudulent activities. Exercise extreme caution, or alternatively, find an honest site to meet your needs.

  10. scam说道:

    I urge you stay away from this platform. My own encounter with it has been purely frustration along with suspicion of deceptive behavior. Proceed with extreme caution, or alternatively, look for an honest platform to meet your needs.

  11. Antoniadat说道:

    apotheke online: online apotheke – online apotheke preisvergleich

  12. VernonJaf说道:

    https://eumedicamentenligne.shop/# pharmacie en ligne sans ordonnance

  13. RobertindUp说道:

    Pharmacie en ligne livraison Europe pharmacie en ligne fiable pharmacie en ligne france fiable

  14. RobertindUp说道:

    internet apotheke [url=https://euapothekeohnerezept.shop/#]internet apotheke[/url] ohne rezept apotheke

  15. Antoniadat说道:

    farmacie online autorizzate elenco: acquisto farmaci con ricetta – farmacie online sicure

  16. Dvhrvc说道:

    inhalers for asthma flat – asthma treatment fortune asthma medication basket

  17. Williamjes说道:

    farmacia en casa online descuento: farmacia barata – farmacias direct

  18. lose money说道:

    I strongly recommend steer clear of this site. The experience I had with it was only disappointment along with concerns regarding deceptive behavior. Exercise extreme caution, or better yet, find a more reputable service to meet your needs.

  19. Child porn说道:

    I highly advise steer clear of this site. My personal experience with it has been only frustration along with suspicion of fraudulent activities. Be extremely cautious, or even better, look for a trustworthy platform to meet your needs.

  20. ラブドール说道:

    the close of May 2021 is ideal for self-pleasure tips.Early in the pandemic,エロ ラブドール

  21. drugs dealer说道:

    I urge you stay away from this site. The experience I had with it was only frustration along with doubts about deceptive behavior. Proceed with extreme caution, or alternatively, seek out a trustworthy service for your needs.

  22. Williamjes说道:

    online apotheke deutschland: ohne rezept apotheke – online apotheke gГјnstig

  23. ChesterInore说道:

    Keto candies have emerged as a widely-liked snack alternative for individuals following a low-carb or reduced-carb diet. These gummy treats are designed to be low in net carbohydrates, rendering them a healthy indulgence for those trying to sustain a https://t.me/s/ketogummies condition of ketonemia.
    By utilizing natural sugar substitutes like stevia or erythritol, ketogenic sweets provide a satisfying sugary palate without raising blood sugar readings, a frequent issue with regular candy.

  24. Antoniadat说道:

    farmacia online barata: farmacia barata – farmacia online madrid

  25. VernonJaf说道:

    http://euapothekeohnerezept.com/# online apotheke versandkostenfrei

  26. Zhurnal_dpEi说道:

    журнал о красоте и моде https://zhurnal-o-krasote11.ru/ .

  27. RobertindUp说道:

    pharmacie en ligne pharmacie en ligne france pas cher Pharmacie en ligne livraison Europe

  28. FlaxroTyday说道:

    Моя стиральная машина сломалась, а деньги на ремонт нужны были срочно. На телеграм-канале новые и малоизвестные МФО 2024 нашел множество МФО, где предлагают займы на карту без отказа и круглосуточно. Понравилось, что займ могут получить все от 18 лет. Оформил заявку и уже через несколько минут деньги были на карте. Это помогло мне быстро починить технику. Очень удобный канал, рекомендую всем, кому нужны срочные деньги!

  29. RobertindUp说道:

    farmacia online barcelona [url=https://eufarmaciaonline.shop/#]farmacia barata[/url] farmacia online barcelona

  30. Antoniadat说道:

    trouver un médicament en pharmacie: Pharmacie Internationale en ligne – pharmacies en ligne certifiées

  31. RalphRef说道:

    eu apotheke ohne rezept: online apotheke deutschland – online apotheke deutschland

  32. Donaldfub说道:

    pharmacies en ligne certifiГ©es: pharmacie en ligne france livraison internationale – pharmacie en ligne pas cher

  33. OLaneuncog说道:

    Здравствуйте!
    Получите документ об образовании по выгодной цене с доставкой по РФ и оплатой после получения.
    http://www.dlplomanrussia.com

  34. Donaldfub说道:

    farmacia online madrid: farmacia online barata – farmacia online barcelona

  35. here说道:

    This post was incredibly informative and well-organized. I learned so much from reading it. Thank you for your hard work and dedication!rendingnicheblog

  36. Williamjes说道:

    eu apotheke ohne rezept: online apotheke rezept – medikament ohne rezept notfall

  37. Williamjes说道:

    farmacia online barcelona: farmacia online 24 horas – farmacia en casa online descuento

  38. Antoniadat说道:

    acheter médicament en ligne sans ordonnance: trouver un médicament en pharmacie – Pharmacie sans ordonnance

  39. taksi_pgOl说道:

    заказ такси по телефону заказ такси по телефону .

  40. RalphRef说道:

    medikament ohne rezept notfall: online apotheke versandkostenfrei – eu apotheke ohne rezept

  41. Nikebiady说道:

    dark web market https://mydarknetmarketlinks.com/ – darknet marketplace darknet market list

  42. RobertindUp说道:

    farmacia online barata farmacias online seguras п»їfarmacia online espaГ±a

  43. ラブドール说道:

    You should see the new variations to our refund coverage which states that canceling any in-stock doll buy will lead to a ten cancellation/restocking pricEmail us at mailto:[e mail guarded] for inquiries if you are unsure of anything in advance of acquiring.ラブドール えろAfter getting been whitelisted in our technique,

  44. RobertindUp说道:

    online apotheke versandkostenfrei [url=http://euapothekeohnerezept.com/#]eu apotheke ohne rezept[/url] online apotheke rezept

  45. Antoniadat说道:

    Farmacia online migliore: acquisto farmaci con ricetta – farmacie online autorizzate elenco

  46. taksi_vgOl说道:

    такси для инвалидов http://www.taksi-vyzvat.ru .

  47. VernonJaf说道:

    https://eumedicamentenligne.com/# pharmacie en ligne france livraison belgique

发表回复

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