[mysql] JSON数据操作

/ 37,076评论 / 148929阅读 / 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. Kamera_suki说道:

    дробеструйная камера купить у производителя http://www.drobestruynaya-kamera.ru/ .

  2. ラブドール说道:

    Conservative areas may have more men who seek information on penis enlargement.As a result,ラブドール sex

  3. ThomasTam说道:

    can i order lisinopril over the counter: can i buy lisinopril in mexico – how much is 30 lisinopril

  4. 급전说道:

    Your article is a true masterpiece.대출

  5. Robertguelm说道:

    buy generic propecia pill: get generic propecia price – generic propecia no prescription

  6. Robertguelm说道:

    cost generic clomid without a prescription: can i order generic clomid price – can i buy generic clomid without insurance

  7. Marvinmef说道:

    cost of propecia without insurance [url=https://propeciaf.online/#]get propecia tablets[/url] order cheap propecia prices

  8. JamesPouff说道:

    https://propeciaf.online/# cost of generic propecia

  9. 空気を注入して膨らませるタイプのエアドールと比較するとメリットがあり過ぎる今商品の「ぬいドール」ダッチワイフではあるものの、準備するときの手間とナイロン素材であるが故の取り扱いにも注意するべき点はあります。

  10. ThomasTam说道:

    lisinopril 5mg buy: buy lisinopril 20 mg – lisinopril 40mg

  11. ThomasTam说道:

    neurontin 100mg tablet: neurontin pills – neurontin tablets no script

  12. RobertPet说道:

    http://lisinopril.club/# lisinopril 2mg tablet

  13. Height Options: If the customization options have height options,エロ 人形 that is usually an indicator of knockoff dolls.

  14. Robertswela说道:

    mexico pharmacy: mexico drug stores pharmacies – mexican drugstore online

  15. Stol_xjkr说道:

    металлический сварной стол https://www.jetstanki.ru .

  16. scam说道:

    I strongly recommend to avoid this site. My own encounter with it has been purely disappointment along with suspicion of scamming practices. Be extremely cautious, or better yet, find an honest service to meet your needs.

  17. Manuelloupe说道:

    mexican mail order pharmacies [url=http://mexicanpharmacy1st.com/#]mexico pharmacy[/url] best online pharmacies in mexico

  18. KennethFobby说道:

    https://mexicanpharmacy1st.online/# buying prescription drugs in mexico

  19. Robertswela说道:

    mexican border pharmacies shipping to usa: best mexican online pharmacies – purple pharmacy mexico price list

  20. Albertnab说道:

    purple pharmacy mexico price list: pharmacies in mexico that ship to usa – mexican border pharmacies shipping to usa

  21. Williamlyday说道:

    http://mexicanpharmacy1st.com/# buying from online mexican pharmacy

  22. Manuelloupe说道:

    buying from online mexican pharmacy mexican mail order pharmacies mexico pharmacy

  23. Williamlyday说道:

    https://mexicanpharmacy1st.shop/# best online pharmacies in mexico

  24. scam说道:

    I highly advise stay away from this platform. My own encounter with it was only disappointment and doubts about deceptive behavior. Exercise extreme caution, or better yet, look for an honest platform for your needs.

  25. Robertswela说道:

    mexican online pharmacies prescription drugs: mexican mail order pharmacies – buying prescription drugs in mexico online

  26. 대출说道:

    Excellent work, I learned a lot from this post.급전

  27. Manuelloupe说道:

    reputable mexican pharmacies online [url=http://mexicanpharmacy1st.com/#]mexican drugstore online[/url] best online pharmacies in mexico

  28. lose money说道:

    I urge you to avoid this site. The experience I had with it has been purely disappointment as well as doubts about fraudulent activities. Exercise extreme caution, or better yet, find a more reputable platform to meet your needs.

  29. criminal说道:

    I highly advise steer clear of this platform. My own encounter with it was nothing but frustration and doubts about fraudulent activities. Proceed with extreme caution, or better yet, find an honest platform to fulfill your requirements.

  30. scam说道:

    I highly advise to avoid this site. My personal experience with it was only disappointment along with doubts about deceptive behavior. Proceed with extreme caution, or better yet, seek out an honest platform for your needs.

  31. criminal说道:

    I highly advise steer clear of this platform. The experience I had with it was purely frustration along with suspicion of deceptive behavior. Be extremely cautious, or even better, find an honest site to meet your needs.

  32. scam说道:

    I urge you steer clear of this platform. The experience I had with it was purely disappointment and suspicion of fraudulent activities. Exercise extreme caution, or alternatively, find a trustworthy site to fulfill your requirements.

  33. Williamlyday说道:

    http://mexicanpharmacy1st.com/# pharmacies in mexico that ship to usa

  34. Williamlyday说道:

    https://mexicanpharmacy1st.com/# buying from online mexican pharmacy

  35. Manuelloupe说道:

    buying prescription drugs in mexico online mexico pharmacies prescription drugs mexico pharmacies prescription drugs

  36. Robertswela说道:

    mexican online pharmacies prescription drugs: mexican pharmaceuticals online – best mexican online pharmacies

  37. 급전说道:

    This is exactly what I needed to read today.대출

  38. Manuelloupe说道:

    purple pharmacy mexico price list [url=https://mexicanpharmacy1st.com/#]medicine in mexico pharmacies[/url] reputable mexican pharmacies online

  39. Robertswela说道:

    medicine in mexico pharmacies: mexico drug stores pharmacies – mexican mail order pharmacies

  40. エロ 人形说道:

    Thu thirty Nov 2023 Sooner or later we would love to see ラブドール 女性 用 of those appear within our Gadget Corner, but we remain some way off squeezing all the required technology into one particular multi-purpose Instrument: the sonic screwdriver

  41. It’s a form of companionship that’s hard to describe,really,リアル セックス

  42. Albertnab说道:

    best online pharmacies in mexico: pharmacies in mexico that ship to usa – mexican border pharmacies shipping to usa

  43. Fhibtm说道:

    brand cialis invent – zhewitra paint penisole merry

  44. Williamlyday说道:

    https://mexicanpharmacy1st.com/# mexican mail order pharmacies

  45. KennethFobby说道:

    https://mexicanpharmacy1st.com/# mexico drug stores pharmacies

  46. Williamlyday说道:

    https://mexicanpharmacy1st.shop/# mexican online pharmacies prescription drugs

  47. Robertswela说道:

    pharmacies in mexico that ship to usa: mexican online pharmacies prescription drugs – medicine in mexico pharmacies

  48. Manuelloupe说道:

    buying prescription drugs in mexico п»їbest mexican online pharmacies buying from online mexican pharmacy

  49. Manuelloupe说道:

    mexican mail order pharmacies [url=https://mexicanpharmacy1st.shop/#]medication from mexico pharmacy[/url] medicine in mexico pharmacies

发表回复

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