作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这样的 jsonb 列:
{name: "Toby", occupation: "Software Engineer", interests: ""}
现在,我需要更新行并将像 ['Volleyball', 'Football', 'Swim']
这样的文本数组放入 interests
字段中。到目前为止我尝试了什么:
UPDATE users SET data = jsonb_set(data, '{interests}', ARRAY['Volleyball', 'Football', 'Swim'], true) WHERE id=84;
data
是jsonb列
但它返回一个错误:
ERROR: function jsonb_set(jsonb, unknown, integer[], boolean) does notexist
Hint: No function matches the given name and argument types. Youmight need to add explicit type casts.
附言:
我正在使用 PostgreSQL 10
最佳答案
第三个参数也需要是JSONB类型。
UPDATE users SET data = jsonb_set(data, '{interests}', '["Volleyball", "Football", "Swim"]'::jsonb, true) WHERE id=84;
这也可以工作,它更接近您使用 ARRAY
的示例:
UPDATE users SET data = jsonb_set(data, '{interests}', to_jsonb(array['Volleyball', 'Football', 'Swim']), true) WHERE id=84
关于arrays - 如何更新 jsonb 列并放置文本数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47619483/
我是一名优秀的程序员,十分优秀!