我需要更新一个包含数据{"X":true}的jsonb列。我需要附加一个{"obj":{"a":1,"b":2}}类型的复杂对象,以便该列{"x":true,"obj":{"a":1,"b":2}}的row的最终值。将使用什么查询来更新此行。
postgres版本12
Update -当存在一个值时,下面的查询update tableName set columnName = (select '{"obj":{"a":1,"b":2}}'::jsonb || columnName::jsonb) where ...成功返回,但是当列为null时,在运行update查询后它仍然是null。我需要能够添加{"obj":{"a":1,"b":2}},即使该列为空。
发布于 2021-02-26 22:16:10
'{"X":true}'::jsonb || '{"obj":{"a":1,"b":2}}'::jsonb如果要更新现有列,请使用coalesce()处理空值:
update the_table
set the_column = coalesce(the_column, '{}')||'{"obj":{"a":1,"b":2}}'https://stackoverflow.com/questions/66387331
复制相似问题