简体   繁体   English

在PostgreSQL中将json字段值更新为小写

[英]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. 您可能需要添加显式类型转换。

  • I have also tried to update particular key but that also raised the same kind of error. 我也尝试过更新特定的密钥,但这也引发了同样的错误。
  • I am not sure if PostgreSQL allowed such kind of operation on json data 我不确定PostgreSQL是否允许对json数据进行此类操作

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;

demo:db<>fiddle 演示:分贝<>小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM