[mysql] JSON数据操作

/ 37,063评论 / 148861阅读 / 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. criminal说道:

    I urge you to avoid this site. My personal experience with it has been nothing but disappointment along with concerns regarding deceptive behavior. Exercise extreme caution, or better yet, look for a more reputable service to meet your needs.

  2. Unmatched Sturdiness : STPE can endure Serious stretching for nearly aオナホ 高級 month without tpe doll having tearing, letting For additional adaptability and a wider array of movements.

  3. Thomasliest说道:

    buying prescription drugs in mexico: medication from mexico pharmacy – mexican border pharmacies shipping to usa

  4. Robertswela说道:

    mexico drug stores pharmacies: buying prescription drugs in mexico – buying prescription drugs in mexico

  5. Manuelloupe说道:

    mexican online pharmacies prescription drugs [url=https://mexicanpharmacy1st.com/#]mexican drugstore online[/url] reputable mexican pharmacies online

  6. Thomasliest说道:

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

  7. Williamlyday说道:

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

  8. Albertnab说道:

    mexican online pharmacies prescription drugs: mexican rx online – mexican mail order pharmacies

  9. Williamlyday说道:

    http://mexicanpharmacy1st.com/# medication from mexico pharmacy

  10. Robertswela说道:

    mexican pharmaceuticals online: mexico pharmacy – mexican rx online

  11. Manuelloupe说道:

    mexican online pharmacies prescription drugs mexican border pharmacies shipping to usa buying prescription drugs in mexico online

  12. KennethFobby说道:

    http://mexicanpharmacy1st.com/# mexican pharmaceuticals online

  13. Robertswela说道:

    mexican border pharmacies shipping to usa: mexican pharmaceuticals online – buying prescription drugs in mexico online

  14. very good jon mate. it helped me a lot mersii

  15. Albertnab说道:

    buying from online mexican pharmacy: mexican drugstore online – mexico drug stores pharmacies

  16. 대출说道:

    Your writing always leaves me feeling inspired.급전

  17. Manuelloupe说道:

    mexican rx online [url=https://mexicanpharmacy1st.shop/#]medicine in mexico pharmacies[/url] mexican mail order pharmacies

  18. KennethFobby说道:

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

  19. Williamlyday说道:

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

  20. Williamlyday说道:

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

  21. Robertswela说道:

    mexican online pharmacies prescription drugs: mexico pharmacies prescription drugs – reputable mexican pharmacies online

  22. HenryIsona说道:

    neurontin for sale online: neurontin 100 mg – neurontin cream

  23. MarvinMek说道:

    prednisone pak prednisone 50 mg prices prednisone tablet 100 mg

  24. Billyeroge说道:

    http://amoxila.pro/# where to get amoxicillin over the counter

  25. Billyeroge说道:

    http://zithromaxa.store/# zithromax 250 mg australia

  26. MarvinMek说道:

    prednisone uk over the counter [url=https://prednisoned.online/#]buy prednisone online no prescription[/url] prednisone brand name

  27. 人形 えろ说道:

    ” —A man “LOVE when my partner moans! I love a guy that makes noise in bed.Silence is strange.人形 えろ

  28. Qvyvwj说道:

    brand cialis steer – penisole death penisole smaller

  29. HenryIsona说道:

    how much is amoxicillin prescription: buy amoxicillin 500mg – can you purchase amoxicillin online

  30. criminal说道:

    I highly advise stay away from this platform. The experience I had with it was nothing but disappointment as well as concerns regarding scamming practices. Be extremely cautious, or better yet, seek out a more reputable site to meet your needs.

  31. criminal说道:

    I urge you to avoid this site. The experience I had with it was only disappointment and suspicion of fraudulent activities. Exercise extreme caution, or better yet, seek out an honest site for your needs.

  32. criminal说道:

    I urge you stay away from this site. The experience I had with it has been only dismay as well as doubts about deceptive behavior. Be extremely cautious, or better yet, find a more reputable service to fulfill your requirements.

  33. HenryIsona说道:

    neurontin 204: order neurontin over the counter – drug neurontin

  34. MarvinMek说道:

    purchase prednisone 10mg 20mg prednisone prednisone price south africa

  35. 대출说道:

    Absolutely pent subject matter, appreciate it for selective information .대출

  36. Richardfrota说道:

    generic zithromax medicine: average cost of generic zithromax – zithromax drug

  37. Billyeroge说道:

    https://prednisoned.online/# online order prednisone

  38. Billyeroge说道:

    https://prednisoned.online/# prednisone 20mg capsule

  39. MarvinMek说道:

    buy zithromax 500mg online [url=https://zithromaxa.store/#]zithromax 250 mg tablet price[/url] can you buy zithromax over the counter in australia

  40. HenryIsona说道:

    doxycycline generic: buy generic doxycycline – where can i get doxycycline

  41. CharlesGib说道:

    amoxil pharmacy: amoxicillin 500 mg where to buy – amoxicillin 50 mg tablets

  42. Richardfrota说道:

    buy doxycycline without prescription: order doxycycline 100mg without prescription – buy doxycycline online

  43. CharlesGib说道:

    zithromax 600 mg tablets: zithromax buy online – can i buy zithromax over the counter

  44. MarvinMek说道:

    prednisone 10mg online prednisone 4 mg daily 20mg prednisone

  45. HenryIsona说道:

    drug neurontin: gabapentin 300 – neurontin 600mg

  46. criminal说道:

    I urge you steer clear of this platform. The experience I had with it was purely disappointment along with doubts about deceptive behavior. Exercise extreme caution, or better yet, seek out a trustworthy site for your needs.

  47. scam说道:

    I urge you stay away from this site. The experience I had with it has been nothing but dismay along with doubts about scamming practices. Be extremely cautious, or even better, look for a trustworthy site to meet your needs.

发表回复

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