Home > Back-end >  Postgres SQL to convert first letter after Mc to upper case
Postgres SQL to convert first letter after Mc to upper case

Time:09-22

I have data in Postgres SQL, something like this

Name
Peter C Mcdonald
Mccarthy

I am trying to convert first letter after Mc to uppercase , something as below

Name
Peter C McDonald
McCarthy

I am using initcap function as below, but its not working as expected

Select initcap(name) from table

Appreciate any help!

CodePudding user response:

Select case when name like '%Mc%' then concat(split_part(name,'Mc',1),'Mc',initcap(split_part(name,'Mc',2))) else name end from table

Use above query it will give desired results.

  • Related