[英]Update json field value to lower case in Postgres
I have a table which includes a json field. 我有一个包含json字段的表。 One of the key have mixed case values and I want to convert them to lower case.
关键之一具有大小写混合的值,我想将它们转换为小写。 I have tried a few methods to do that, but nothing works and raising explicit cast issues.
我已经尝试了几种方法来做到这一点,但是没有任何效果,并且提出了明确的强制转换问题。
UPDATE table SET data = LOWER( CAST (data AS json)) WHERE id=123;
Above query raised the following error. 上面的查询引发以下错误。
No function matches the given name and argument types.
没有函数与给定的名称和参数类型匹配。 You might need to add explicit type casts.
您可能需要添加显式类型转换。
lower()
is for type text
. lower()
用于text
类型。 So first cast your json data into text. 因此,首先将json数据转换为文本。 After
lower()
execution you can cast it back into type json
: 执行
lower()
之后,可以将其json
转换回json
类型:
UPDATE a SET data = LOWER(data::text)::json;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.