gpt4 book ai didi

postgresql - 尝试更新 Postgres 表中的 JSON 但出现未知错误

转载 作者:行者123 更新时间:2023-11-29 13:40:23 25 4
gpt4 key购买 nike

这是我正在尝试的查询...

UPDATE users 
SET preferences = jsonb_set(preferences, '{some_key}', 'true'::jsonb)
WHERE id IN (1, 2)

但我一直收到这样的错误,即 jsonb_set 的第二个参数未知,并且不清楚为什么会这样。字符串键肯定存在。 some_keypreferences 中的一个键(表中的列名)。

有人知道是什么原因造成的吗?

这些查询有效...

SELECT preferences -> 'some_key' AS some_key FROM users

SELECT preferences -> 'some_key' AS some_key FROM users WHERE preferences -> 'some_key' = 'false'

更新

这是 preferences 列包含内容的示例...

“some_key”=>"false", "some_other_key"=>"true",

最佳答案

应该这样做...

更新用户设置偏好 = 偏好 || '"some_key"=>"true"'::hstore;

需要使用正确的数据类型

关于postgresql - 尝试更新 Postgres 表中的 JSON 但出现未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56298898/

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