sql - How to conditional update field in JSON in MySQL? -


we have student table contains json in 'jsondata' column(longtext). need change value of "ishandicapped" field in json.

structure:

{   "data": {      "schooldata": {        "studentliste": [         {           "student": {             "studentid": 111749,             "ishandicapped": false             }         }       ],     },   } } 

old data: "ishandicapped": false

new value: "ishandicapped": "no"

this should conditional update true need change value as

old data: "ishandicapped": true

new value: "ishandicapped": "ja"

primary field of table id.

i got following sql query same unable understand how add conditional update if value true put ja else no:

update student  set data = json_set(data, "'$."data"."schooldata"."studentliste"[*]."ishandicapped", "?")  id = 2; 

the following update statement trick:

update student  set $.ishandicapped= case                                when json_extract(data, "'$."data"."schooldata"."studentliste"[*]."ishandicapped")='false'                       'no'                       else 'ja'  end id=2; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -