[mysql] JSON数据操作

/ 37,031评论 / 148680阅读 / 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. I do not even know how I ended up here but I thought this post was great I do not know who you are but certainly youre going to a famous blogger if you are not already Cheers

  2. Williamfug说道:

    canadian pharmacy discount code: pharm world – canadian pharmacy world coupon code

  3. DavidTaK说道:

    pharmacy canadian canadian pharmacy king canadian pharmacy king

  4. Felipelam说道:

    https://pharmnoprescription.icu/# canadian and international prescription service

  5. DavidTaK说道:

    international pharmacy no prescription [url=http://pharmworld.store/#]cheapest pharmacy[/url] mail order prescription drugs from canada

  6. Felipelam说道:

    http://pharmnoprescription.icu/# online pharmacy not requiring prescription

  7. Williamfug说道:

    online drugstore no prescription: online pharmacy no prescription needed – online medicine without prescription

  8. DonaldtAg说道:

    canadianpharmacy com: canadian pharmacy online ship to usa – canadian discount pharmacy

  9. oborudovan_takt说道:

    оборудование для диспетчерских http://www.oborudovanie-dispetcherskih-centrov.ru/ .

  10. DavidTaK说道:

    rx pharmacy coupons canadian pharmacies not requiring prescription cheapest pharmacy to fill prescriptions with insurance

  11. Williamfug说道:

    medication from mexico pharmacy: mexico drug stores pharmacies – mexico drug stores pharmacies

  12. 人形 えろ说道:

    Big shocker: They’re named after a man, Alexander Skene. The Skene’s fill with fluid during sexual arousal and if stimulated during sexual arousal, sex, or masturbation, can actually release this liquid.

  13. DonaldtAg说道:

    canada pharmacy not requiring prescription: online pharmacy – canadian pharmacies not requiring prescription

  14. DavidTaK说道:

    canadian pharmacy [url=http://pharmcanada.shop/#]pharmacy in canada[/url] canadianpharmacyworld com

  15. Jeromeviaph说道:

    https://pharmcanada.shop/# online canadian pharmacy

  16. Felipelam说道:

    http://pharmworld.store/# canadian pharmacy without prescription

  17. Felipelam说道:

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

  18. Williamfug说道:

    canadian discount pharmacy: canadian pharmacy world reviews – canada drug pharmacy

  19. Charlesvox说道:

    http://viagras.online/# Order Viagra 50 mg online

  20. DavidBiolo说道:

    https://cenforce.pro/# Cenforce 150 mg online

  21. Charlesvox说道:

    https://cialist.pro/# Generic Tadalafil 20mg price

  22. Tylerreunk说道:

    http://cialist.pro/# Generic Cialis price

  23. oborudovan_iukt说道:

    оборудование диспетчерского пункта http://www.oborudovanie-dispetcherskih-centrov.ru .

  24. Tylerreunk说道:

    http://levitrav.store/# Buy generic Levitra online

  25. Georgefrege说道:

    Cialis 20mg price: Cialis 20mg price in USA – Generic Cialis without a doctor prescription

  26. Jamesexite说道:

    Cenforce 100mg tablets for sale: Cenforce 150 mg online – order cenforce

  27. Elmersoalf说道:

    Kamagra tablets buy kamagra online cheap kamagra

  28. Elmersoalf说道:

    Generic Levitra 20mg [url=http://levitrav.store/#]Buy Vardenafil 20mg[/url] Levitra 20 mg for sale

  29. Charlesvox说道:

    https://cenforce.pro/# cenforce.pro

  30. Charlesvox说道:

    http://cialist.pro/# Generic Cialis price

  31. Jamesexite说道:

    sildenafil oral jelly 100mg kamagra: kamagra.win – cheap kamagra

  32. Elmersoalf说道:

    cheapest cialis [url=http://cialist.pro/#]buy cialis online[/url] cialis for sale

  33. Jamesexite说道:

    Cheap generic Viagra online: Cheapest place to buy Viagra – Cheap Sildenafil 100mg

  34. Georgefrege说道:

    cenforce for sale: cheapest cenforce – Cenforce 100mg tablets for sale

  35. DavidBiolo说道:

    https://kamagra.win/# cheap kamagra

  36. Charlesvox说道:

    https://levitrav.store/# Vardenafil buy online

  37. Charlesvox说道:

    https://kamagra.win/# Kamagra Oral Jelly

  38. Elmersoalf说道:

    Cenforce 150 mg online order cenforce buy cenforce

  39. Jamesexite说道:

    Vardenafil online prescription: Cheap Levitra online – Vardenafil online prescription

  40. DavidBiolo说道:

    https://cialist.pro/# Cialis without a doctor prescription

  41. Elmersoalf说道:

    Buy Vardenafil online [url=http://levitrav.store/#]Vardenafil online prescription[/url] Buy Vardenafil online

  42. But its AI manufacturers Restrict the dolls’ robotics and intellect to 人形 エロThe top. That means it lacks the contact sensors and overall body heaters common in other AI companions.

  43. Georgefrege说道:

    Buy Cenforce 100mg Online: cenforce.pro – order cenforce

  44. Jamesexite说道:

    Cheap Levitra online: Levitra 20mg price – Vardenafil price

  45. Spooning: Spooning is among the most ドール エロintimate intercourse situation of all time. If you need to attempt sexing your love doll when lying on your bed,

  46. Charlesvox说道:

    http://viagras.online/# Viagra generic over the counter

  47. Charlesvox说道:

    https://cialist.pro/# Tadalafil Tablet

  48. Jamesexite说道:

    Kamagra 100mg price: kamagra.win – Kamagra tablets

  49. Elmersoalf说道:

    Generic Levitra 20mg [url=https://levitrav.store/#]Buy generic Levitra online[/url] Levitra 20 mg for sale

发表回复

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