gpt4 book ai didi

arrays - 如何更新 jsonb 列并放置文本数组

转载 作者:行者123 更新时间:2023-11-29 12:54:04 28 4
gpt4 key购买 nike

我有这样的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com