Postgres更新JSONB字符串到数组
我有一个表列2是JSONB,我想更改列2是数组的字符串的值。 的结果具有“一个”为[一个“一个”]和“第三” be [third']
table1
column2 | 我希望Column2 |
---|---|
first | [一个“一个”,“两个”,“ |
三 | ” |
] | “第三” |
第四 | 4 |
我应该如何更新值? 这是我尝试的:
UPDATE table
SET columnn2 = ARRAY[value]::JSONB
WHERE jsonb_typeof(column2)!='array';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
JSONB_BUILD_ARRAY()
函数:在
阅读有关函数在文档中。
Use the
jsonb_build_array()
function:Test it in db<>fiddle.
Read about the function in the documentation.
一种选项是使用串联操作员(
||
)用方括号和铸件以及text> text
,然后重新铸造到< code>JSONB such asDemo
One option is to use concatenation operators(
||
) to wrap up the expresion with square brackets along with casting toTEXT
, then recasting toJSONB
such asDemo