将postgres中的所有记录转换为Titlecase,首字母大写 [英] Convert all records in postgres to Titlecase, first letter uppercase

查看:116
本文介绍了将postgres中的所有记录转换为Titlecase,首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PostgreSQL中有一个名为关键字的简单表,其中有一个名为name的简单文本字段。我想将首字母大写转换为关键字的所有名称。有办法从psql控制台执行此操作吗?

I have a simple table in PostgreSQL called keywords with a simple text field called name. I want to convert all names of keywords in first letter uppercase. Is there a way to do it from psql console?

推荐答案

如果您正在使用 initcap()函数,意味着将每个关键字的首字母大写,并将以下字符小写:

There is an initcap() function, if you're meaning to uppercase the first letter of each keyword and to lowercase the following characters:

update foo
set bar = initcap(bar)

其他组合 substring() upper()

update foo
set bar = upper(substring(bar from 1 for 1)) ||
          substring(bar from 2 for length(bar))

http://www.postgresql.org/docs/current/static/functions-string.html

这篇关于将postgres中的所有记录转换为Titlecase,首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆