doumei1908 2017-12-02 21:53
浏览 407

mariadb中的JSON_SET,不要插入数据

In the MariaDB documentation it says that JSON_SET inserts or updates information, while JSON_INSERT just inserts, and JSON_REPLACE only substitutes.

I am using the code below, and I need the information to be inserted, if it does not exist, or updated, if it already exists.

The problem is that it is only updating, when it already exists, and it does not insert, if it does not exist.

MariaDB docs

UPDATE myTable SET config = JSON_SET( config, '$.person.name', 'zeca', '$.person.details.age', '87' ) WHERE id = 127

If "details" already exist in the "config" field of myTable, "age" will be registered. If "details" still do not exist, I want to register details.age, but it is not registering.

  • 写回答

2条回答 默认 最新

  • douning5041 2017-12-02 22:14
    关注

    I can´t test my code, but maybe you can get it to work with something like this

    UPDATE myTable SET config = JSON_MERGE(config, '{"person": {}'), config = JSON_SET( config, '$.person.name', 'zeca', '$.person.details.age', '87' ) WHERE id = 127

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭