[mysql] JSON数据操作

/ 37,051评论 / 148789阅读 / 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. Richardfrota说道:

    buy doxycycline cheap: how to buy doxycycline online – doxycycline 50 mg

  2. criminal说道:

    I highly advise stay away from this site. The experience I had with it has been purely disappointment as well as doubts about deceptive behavior. Be extremely cautious, or even better, look for a trustworthy service to fulfill your requirements.

  3. lose money说道:

    I strongly recommend steer clear of this site. My own encounter with it was only frustration and concerns regarding fraudulent activities. Exercise extreme caution, or even better, seek out a more reputable service to fulfill your requirements.

  4. CharlesGib说道:

    neurontin 400 mg cost: generic neurontin – buy generic neurontin

  5. Dyson_poPn说道:

    dyson стайлер официальный магазин dyson официальный интернет магазин .

  6. lose money说道:

    I strongly recommend steer clear of this site. My personal experience with it has been only disappointment and concerns regarding deceptive behavior. Exercise extreme caution, or even better, look for an honest platform to meet your needs.

  7. MarvinMek说道:

    200 mg doxycycline doxycycline hyclate doxycycline vibramycin

  8. HenryIsona说道:

    can i order prednisone: 20mg prednisone – prednisone buy online nz

  9. scam说道:

    I urge you stay away from this platform. The experience I had with it has been nothing but disappointment and doubts about scamming practices. Proceed with extreme caution, or even better, seek out a more reputable service to meet your needs.

  10. lose money说道:

    I urge you to avoid this site. My own encounter with it was purely disappointment and concerns regarding fraudulent activities. Proceed with extreme caution, or alternatively, find an honest platform to fulfill your requirements.

  11. MarvinMek说道:

    amoxicillin 500 mg where to buy [url=http://amoxila.pro/#]amoxicillin 500mg capsule[/url] medicine amoxicillin 500

  12. Youmrp说道:

    dapoxetine official – fildena husband cialis with dapoxetine stony

  13. HenryIsona说道:

    1 mg prednisone cost: prednisone 2.5 mg – prednisone 10mg price in india

  14. lose money说道:

    I urge you stay away from this site. The experience I had with it has been only dismay as well as suspicion of fraudulent activities. Exercise extreme caution, or alternatively, seek out a more reputable service for your needs.

  15. MarvinMek说道:

    amoxicillin brand name generic amoxicillin 500mg amoxicillin 500mg no prescription

  16. HenryIsona说道:

    doxycycline order online: purchase doxycycline online – doxycycline without a prescription

  17. lose money说道:

    I strongly recommend stay away from this platform. The experience I had with it was purely dismay along with doubts about scamming practices. Exercise extreme caution, or even better, look for a more reputable service to meet your needs.

  18. MarvinMek说道:

    online prednisone [url=http://prednisoned.online/#]prednisone 4mg[/url] average price of prednisone

  19. lose money说道:

    I strongly recommend stay away from this platform. My own encounter with it has been purely dismay and concerns regarding deceptive behavior. Be extremely cautious, or even better, look for an honest site to fulfill your requirements.

  20. Billyeroge说道:

    https://gabapentinneurontin.pro/# how much is neurontin pills

  21. lose money说道:

    I urge you stay away from this site. My personal experience with it has been nothing but frustration along with doubts about deceptive behavior. Exercise extreme caution, or alternatively, find an honest service for your needs.

  22. Zenitbet1.com说道:

    Промокоды для Зенитбет zenitbet1.com

    Если Вы хотели найти промокод бк зенит при регистрации в интернете, то переходите на наш сайт прямо сейчас. Зеркало, чаще всего, регулярно блокируют и необходимо его искать заново. Благодаря сайту zenitbet1.com больше не будет сложности в поиске. Мы каждый день проверяем и добавляем ссылку на вход зеркало ЗенитБет. Можно подписаться на рассылку и Вам на Email будет приходить свежая ссылка о входе на сайт.

  23. HenryIsona说道:

    cost of prednisone tablets: prednisone 5084 – 5mg prednisone

  24. Richardfrota说道:

    cost of neurontin 100mg: neurontin medicine – neurontin 600 mg price

  25. lose money说道:

    I highly advise to avoid this site. The experience I had with it has been only disappointment and concerns regarding deceptive behavior. Exercise extreme caution, or even better, find an honest site for your needs.

  26. criminal说道:

    I strongly recommend steer clear of this site. My personal experience with it was nothing but frustration along with doubts about fraudulent activities. Exercise extreme caution, or alternatively, seek out a trustworthy service for your needs.

  27. criminal说道:

    I strongly recommend stay away from this site. The experience I had with it was only frustration and doubts about fraudulent activities. Proceed with extreme caution, or better yet, look for a more reputable platform for your needs.

  28. HenryIsona说道:

    prednisone 60 mg tablet: prednisone 10 mg online – prednisone purchase online

  29. lose money说道:

    I urge you steer clear of this site. My personal experience with it was only dismay along with concerns regarding scamming practices. Exercise extreme caution, or better yet, look for a trustworthy platform to meet your needs.

  30. lose money说道:

    I urge you steer clear of this site. My own encounter with it was only dismay and concerns regarding scamming practices. Proceed with extreme caution, or alternatively, find a trustworthy platform to fulfill your requirements.

  31. lose money说道:

    I strongly recommend steer clear of this platform. The experience I had with it was purely frustration and doubts about deceptive behavior. Proceed with extreme caution, or alternatively, find an honest site for your needs.

  32. CharlesGib说道:

    doxycycline 100mg dogs: price of doxycycline – doxycycline medication

  33. MarvinMek说道:

    prednisone oral [url=http://prednisoned.online/#]prednisone 10mg cost[/url] prednisone 10mg

  34. Billyeroge说道:

    https://zithromaxa.store/# buy cheap generic zithromax

  35. Richardfrota说道:

    buy cheap amoxicillin: amoxicillin 500mg cost – amoxicillin 500mg buy online uk

  36. HenryIsona说道:

    zithromax 250 mg australia: zithromax capsules price – zithromax online no prescription

  37. CharlesGib说道:

    buy generic zithromax online: zithromax over the counter uk – zithromax 500 tablet

  38. MarvinMek说道:

    amoxicillin online purchase how to get amoxicillin amoxicillin buy no prescription

  39. HenryIsona说道:

    buy prednisone without a prescription best price: prednisone uk over the counter – buy prednisone online without a script

  40. MarvinMek说道:

    doxycycline order online [url=https://doxycyclinea.online/#]doxycycline tablets[/url] doxylin

  41. ラブドール说道:

    頭にはめ込む部分があるので、そこにガチンとはめこむだけです。ねじったりする必要はありません!えろ 人形

  42. Billyeroge说道:

    https://doxycyclinea.online/# generic doxycycline

  43. HenryIsona说道:

    neurontin 100 mg cost: neurontin 100mg capsule price – neurontin 200 mg capsules

  44. Billyeroge说道:

    http://gabapentinneurontin.pro/# neurontin 100mg price

  45. ラブドール说道:

    Sex dolls can help to educate people about consent and healthyセックス ボット relationships by providing a safe and controlled environment for individuals to

发表回复

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