pg更新JSON字段
jsonb_set()
示例:
- user表的info字段为
jsonb
类型 info内city键更新为
Beijing
update "user" set "info" = jsonb_set(info, '{city}', '"Beijing"') where name = 'wang';
若jsonb可能为空(null)
update "user"
set "info" = jsonb_set(coalesce("info", '{}'), '{city}', '"Beijing"')
where name = 'wang';
厉害