相关疑难解决方法(0)

如何修改PostgreSQL JSONB数据类型中的单个属性值?

如何修改PostgreSQL JSONB数据类型中的单个字段?

假设我有一张叫做动物的桌子:

id       info
------------------------------------------------------------
49493   {"habit1":"fly","habit2":"dive","location":"SONOMA NARITE"}
Run Code Online (Sandbox Code Playgroud)

我想简单地更改location属性的值(例如,大写或小写文本).所以结果,在UPDATE之后

    id       info
------------------------------------------------------------
49493   {"habit1":"fly","habit2":"dive","location":"sonoma narite"}
Run Code Online (Sandbox Code Playgroud)

我在下面尝试了这个,它不起作用

update animal set info=jsonb_set(info, '{location}', LOWER(info->>'location'), true) where id='49493';
----------------------------------
ERROR:  function jsonb_set(jsonb, unknown, text, boolean) does not exist
LINE 7: update animal set info=jsonb_set(info, '{con...
                                           ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********

ERROR: function jsonb_set(jsonb, unknown, text, boolean) does not exist
Run Code Online (Sandbox Code Playgroud)

如果我只是知道更新的值是什么,那么我可以使用这个:

update animal set info=jsonb_set(info, '{location}', …
Run Code Online (Sandbox Code Playgroud)

postgresql json jsonb

6
推荐指数
2
解决办法
5717
查看次数

标签 统计

json ×1

jsonb ×1

postgresql ×1