[mysql] JSON数据操作

/ 37,036评论 / 148710阅读 / 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. Dayson_hgmt说道:

    фен дайсон отзывы https://www.dyson-feny.com .

  2. CharlesGib说道:

    neurontin 400 mg cost: neurontin 600 mg capsule – neurontin discount

  3. Billyeroge说道:

    http://zithromaxa.store/# zithromax without prescription

  4. MarvinMek说道:

    buy cheap amoxicillin online amoxicillin buy no prescription can i buy amoxicillin online

  5. Richardfrota说道:

    buy doxycycline for dogs: doxycycline hyclate 100 mg cap – doxy 200

  6. HenryIsona说道:

    amoxicillin 500mg price in canada: where can i buy amoxicillin without prec – amoxicillin for sale online

  7. MarvinMek说道:

    prednisone uk price [url=https://prednisoned.online/#]prednisone brand name india[/url] canada buy prednisone online

  8. CharlesGib说道:

    cost of amoxicillin 875 mg: purchase amoxicillin 500 mg – purchase amoxicillin online without prescription

  9. Lwaunz说道:

    simvastatin calm – zocor route atorvastatin total

  10. Williamfug说道:

    top 10 pharmacies in india: india pharmacy mail order – india pharmacy

  11. DonaldtAg说道:

    indian pharmacy online: indian pharmacy online – Online medicine order

  12. DavidTaK说道:

    medication from mexico pharmacy mexican pharmacy mexican border pharmacies shipping to usa

  13. Felipelam说道:

    https://pharmworld.store/# foreign pharmacy no prescription

  14. Illuminate your living space with premium window solutions tailored for you.

  15. Felipelam说道:

    http://pharmworld.store/# online pharmacy non prescription drugs

  16. Williamfug说道:

    mexican pharmacy: buying prescription drugs in mexico – medicine in mexico pharmacies

  17. DavidTaK说道:

    mail order prescriptions from canada [url=http://pharmnoprescription.icu/#]pills no prescription[/url] best website to buy prescription drugs

  18. Jeromeviaph说道:

    http://pharmnoprescription.icu/# how to order prescription drugs from canada

  19. the men wear suits or tuxedos. Mobile phones, which are strictly prohibited (along with any photography), are left at the entrance as guests head to the basement,

  20. Williamfug说道:

    purple pharmacy mexico price list: medicine in mexico pharmacies – best online pharmacies in mexico

  21. DonaldtAg说道:

    best canadian pharmacy to order from: canadian pharmacy meds – the canadian pharmacy

  22. When you’ve got been blocked by blunder, be sure to Speak to us! Make sure to incorporate your IP address to ensure we can easily whitelist it.

  23. Jeromeviaph说道:

    http://pharmnoprescription.icu/# non prescription online pharmacy

  24. DavidTaK说道:

    legal online pharmacy coupon code online pharmacy canada pharmacy not requiring prescription

  25. Felipelam说道:

    https://pharmworld.store/# canadian pharmacy world coupon

  26. Felipelam说道:

    https://pharmnoprescription.icu/# cheap prescription drugs online

  27. I thought this grab-and-go mentality was inspired, but my partner informed me that while he enjoyed the sleeve, he’d “never pay $8.50 for a handjob.”

  28. Williamfug说道:

    discount prescription drugs canada: no prescription online pharmacies – buy medications online without prescription

  29. DavidTaK说道:

    online meds without prescription [url=https://pharmnoprescription.icu/#]online pharmacy not requiring prescription[/url] buying prescription drugs online without a prescription

  30. Williamfug说道:

    online meds no prescription: online pharmacies without prescription – mail order prescriptions from canada

  31. ラブドール说道:

    He now knows what I look like when I fall asleep with a sheet mask on, and I now know what it’s like to fall into the toilet in the dead of the night because he left the seat up.

  32. Do you know? authentic love doll intercourse dolls are often known as love dolls, actual dolls and Grownup dolls.

  33. DavidTaK说道:

    top online pharmacy india online pharmacy india buy medicines online in india

  34. Maximize your home’s potential with expertly installed windows.

  35. Felipelam说道:

    https://pharmnoprescription.icu/# online pharmacy without prescription

  36. Felipelam说道:

    http://pharmindia.online/# india pharmacy mail order

  37. Williamfug说道:

    medication from mexico pharmacy: medication from mexico pharmacy – mexico pharmacy

  38. DavidTaK说道:

    canada online pharmacy no prescription [url=https://pharmworld.store/#]legal online pharmacy coupon code[/url] pharmacy coupons

  39. Donaldkenty说道:

    the canadian drugstore: pet meds without vet prescription canada – canadapharmacyonline legit

  40. DonaldtAg说道:

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

  41. Donaldkenty说道:

    drugstore com online pharmacy prescription drugs: pharm world store – canadian pharmacy world coupon

  42. Williamfug说道:

    canada pharmacy not requiring prescription: pharm world store – international pharmacy no prescription

  43. All kinds of other AI companions Never even provide the mouth being an out 人形 エロthere orifice mainly because of the mechanisms involved with their speech and expressions not to mention as an orifice that could be mechanized.

  44. DavidTaK说道:

    indian pharmacy online top 10 online pharmacy in india world pharmacy india

  45. Felipelam说道:

    http://pharmnoprescription.icu/# online pharmacies without prescriptions

  46. Felipelam说道:

    http://pharmnoprescription.icu/# no prescription needed

  47. Tzxhct说道:

    rosuvastatin pills thunder – caduet buy grave caduet musical

  48. DonaldtAg说道:

    cheapest online pharmacy india: world pharmacy india – india pharmacy mail order

  49. Williamfug说道:

    best online pharmacies in mexico: mexican pharmacy – buying from online mexican pharmacy

  50. DavidTaK说道:

    mexican pharmaceuticals online [url=http://pharmmexico.online/#]buying prescription drugs in mexico[/url] mexico pharmacy

发表回复

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