clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 818558 fiddles created (9200 in the last week).

DROP TABLE IF EXISTS `myTable`;
 hidden batch(es)


CREATE TABLE IF NOT EXISTS `myTable` ( `id` SERIAL, `config` TEXT );
 hidden batch(es)


INSERT INTO `myTable` (`id`, `config`) VALUES (126, '{"person": {"name": "", "details": {"age": 20}}}'), (127, '{"person": {"name": "zeca 2"}}');
 hidden batch(es)


UPDATE `myTable` SET `config` = JSON_SET(`config`, '$.person.name', 'zeca 1'), `config` = IF(JSON_EXISTS(`config`, '$.person.details') IS NOT NULL, JSON_SET( `config`, '$.person.details', JSON_OBJECT('age', 40) ), JSON_INSERT( `config`, '$.person', JSON_OBJECT('details', JSON_OBJECT('age', 40) ) ) ) WHERE `id` = 126;
 hidden batch(es)


UPDATE `myTable` SET `config` = JSON_SET(`config`, '$.person.name', 'zeca'), `config` = IF(JSON_EXISTS(`config`, '$.person.details') IS NOT NULL, JSON_SET( `config`, '$.person.details', JSON_OBJECT('age', 87) ), JSON_INSERT( `config`, '$.person', JSON_OBJECT('details', JSON_OBJECT('age', 87) ) ) ) WHERE `id` = 127;
 hidden batch(es)


SELECT `id`, `config` FROM `myTable`;
id config
126 {"person": {"name": "zeca 1", "details": {"age": 40}}}
127 {"person": {"name": "zeca", "details": {"age": 87}}}
 hidden batch(es)