How to Convert the Case of a String in PostgreSQL

The most basic case conversion functions are lower() and upper(). Usage is pretty straightforward:

select lower('Turn this into lOweRCAse');
 lower           
--------------------------
 turn this into lowercase
select upper('capiTalize THis');
 upper      
-----------------
 CAPITALIZE THIS

Another useful case conversion function is initcap(), which capitalizes the first character of each word and lowers the case of everything else. This is very useful when printing proper nouns and titles and making names stored in uppercase more pleasing to read:

select
  first_name,
  last_name,
  initcap(concat(first_name, ' ', last_name)) as name
from customer
limit 5;
 first_name | last_name |       name       
------------+-----------+------------------
 MARY       | SMITH     | Mary Smith
 PATRICIA   | JOHNSON   | Patricia Johnson
 LINDA      | WILLIAMS  | Linda Williams
 BARBARA    | JONES     | Barbara Jones
 ELIZABETH  | BROWN     | Elizabeth Brown
database icon
Shared queries and folders ✅ Version history ✅ One-click connection to PostgreSQL ✅
Get more done, together, with PopSQL and PostgreSQL