简体   繁体   English

如何附加到 JSON 列 postgres 中的嵌套数组

[英]How to append to a nested array in a JSON column postgres

I have column with the next structure:我有具有下一个结构的列:

 {
  "_id": "57101c4efbea42d219e068b3",
  "name": "System admin group",
  "is_service": 0,
  "security_lists": {
    "actions": [
      "ota upload",
      "widgets manage",
      "scheduled jobs manage all",
      "users view"
    ]
  }
}

How can I append value to actions array?如何将值附加到操作数组? I suppose that it's can be done using jsonb_set() but I can't figure out how to do it(我想可以使用 jsonb_set() 来完成,但我不知道该怎么做(

    UPDATE 
        group_permissions 
    SET 
        "document"=jsonb_set("document"::jsonb, 
        '{security_lists, actions}', 
        ("document" ->'security_lists'->'actions')::jsonb || 
        '["newString"]'::jsonb) 
    WHERE 
        "document"::json->>'name'='System admin group';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM