Update value to "the first character is capital and the rest is small"

Started by Emi Luabout 20 years ago5 messagesgeneral
Jump to latest
#1Emi Lu
emilu@encs.concordia.ca

Hello all,

Does anyone have available plpgsql codes to update all capital letters
in a column to "the first character is capital and the rest is small" ?

For example, in tableA(id, description)
001, 'ZHANG ZHE XIN' =>
'Zhang Zhe Xin'
002, 'LIU, WEI-HUAI'
=> 'Liu, Wei-Huai'
003, 'GU & WEI. NAN (CE SHI) & TOMMORROW' => 'Gu & Wei. Nan (Ce
Shi) & Tommorrow'

Thanks a lot!
Ying

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Emi Lu (#1)
Re: [SQL] Update value to "the first character is capital and the rest is small"

Emi Lu wrote:

Hello all,

Does anyone have available plpgsql codes to update all capital letters
in a column to "the first character is capital and the rest is small" ?

I don't know about plpgsql codes, but there is a function initcap() that
you can use for that.

alvherre=# select initcap('GU & WEI. NAN (CE SHI) & TOMMORROW');
initcap
------------------------------------
Gu & Wei. Nan (Ce Shi) & Tommorrow
(1 row)

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#3Emi Lu
emilu@encs.concordia.ca
In reply to: Emi Lu (#1)
Re: Update value to "the first character is capital and

I got the answer from the docs. |initcap|(text)

thanks anyway,
Ying

Show quoted text

Hello all,

Does anyone have available plpgsql codes to update all capital letters
in a column to "the first character is capital and the rest is small" ?

For example, in tableA(id, description)
001, 'ZHANG ZHE XIN'
=> 'Zhang Zhe Xin'
002, 'LIU, WEI-HUAI'
=> 'Liu, Wei-Huai'
003, 'GU & WEI. NAN (CE SHI) & TOMMORROW' => 'Gu & Wei. Nan
(Ce Shi) & Tommorrow'

Thanks a lot!
Ying

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

#4Emi Lu
emilu@encs.concordia.ca
In reply to: Alvaro Herrera (#2)
Re: [GENERAL] Update value to "the first character is capital

I saw it from the docs as well. Thank you Alvaro :)

Alvaro Herrera wrote:

Show quoted text

Emi Lu wrote:

Hello all,

Does anyone have available plpgsql codes to update all capital letters
in a column to "the first character is capital and the rest is small" ?

I don't know about plpgsql codes, but there is a function initcap() that
you can use for that.

alvherre=# select initcap('GU & WEI. NAN (CE SHI) & TOMMORROW');
initcap
------------------------------------
Gu & Wei. Nan (Ce Shi) & Tommorrow
(1 row)

#5John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Emi Lu (#1)
Re: Update value to "the first character is capital and

Have you tried the initcap function?

select initcap('abcd efgh');
initcap
-----------
Abcd Efgh

John

Emi Lu wrote:

Show quoted text

Hello all,

Does anyone have available plpgsql codes to update all capital letters
in a column to "the first character is capital and the rest is small" ?

For example, in tableA(id, description)
001, 'ZHANG ZHE XIN' =>
'Zhang Zhe Xin'
002, 'LIU, WEI-HUAI'
=> 'Liu, Wei-Huai'
003, 'GU & WEI. NAN (CE SHI) & TOMMORROW' => 'Gu & Wei. Nan (Ce
Shi) & Tommorrow'

Thanks a lot!
Ying

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings