Six contacts arrived from a web form as hANNAH BROOKS and TYLER O'BRIEN. The PostgreSQL initcap function fixes them in one call: initcap('hANNAH BROOKS') returns Hannah Brooks.
The catch: initcap knows nothing about names or acronyms. McDonald came back as Mcdonald, and III as Iii.
Six examples follow, from one string to separators, state codes and an UPDATE. Tested on PostgreSQL 18.6 with psql in VS Code.
PostgreSQL INITCAP Function Syntax
Here is the syntax:
initcap ( text ) → text
It uppercases the first letter of each word and lowercases the rest, where a word is any run of letters and digits and every other character, even an apostrophe, ends one.
Return value: text. NULL in, NULL out.
Availability: every supported PostgreSQL release.
When to Use the INITCAP Function in PostgreSQL
Use initcap in PostgreSQL when you need to:
- fix names typed in all caps
- clean city names before a mailing export
- fix a whole column once, right after trimming stray spaces in PostgreSQL
Run this once. Every example uses these six US contacts:
CREATE TABLE contacts (
id int PRIMARY KEY,
full_name varchar(20),
city varchar(16),
state char(2)
);
INSERT INTO contacts VALUES
(1, 'hANNAH BROOKS', 'columbus', 'oh'),
(2, 'TYLER O''BRIEN', 'SAN ANTONIO', 'tx'),
(3, 'grace mcdonald', 'st. louis', 'mo'),
(4, 'mary-ann ellis', 'winston-salem', 'nc'),
(5, 'marcus reed iii', 'NEW YORK', 'ny'),
(6, 'Olivia Hayes', NULL, 'WA');
Example 1: Capitalize the First Letter of Each Word
Start small. You want Hannah’s name fixed, plus a NULL test:
\pset null '(null)'
SELECT initcap('hANNAH BROOKS') AS name,
initcap(NULL) AS null_in;
Output:
name | null_in
---------------+---------
Hannah Brooks | (null)
(1 row)
That returns Hannah Brooks; NULL stays NULL. initcap lowercased ANNAH by itself, so you don’t need PostgreSQL lower() first.
Example 2: Proper Case Names in a PostgreSQL Table
Now the table. The goal is clean full_name values for display:
\pset footer off
SELECT initcap(full_name) AS full_name
FROM contacts
ORDER BY id;
Output:
full_name
-----------------
Hannah Brooks
Tyler O'Brien
Grace Mcdonald
Mary-Ann Ellis
Marcus Reed Iii
Olivia Hayes

For Tyler, this returns Tyler O'Brien, and the hyphen gives Mary-Ann two capitals. Two rows don’t survive, though: Grace Mcdonald and Marcus Reed Iii.
Example 3: How INITCAP Splits Words (Apostrophes, Hyphens, Digits)
Say you need to predict odd input:
SELECT s AS input, initcap(s) AS initcap
FROM (VALUES ('pat''s diner'), ('mary-ann'),
('3rd street'), ('ibm usa llc'),
('first_name')) AS t(s);
Output:
input | initcap
-------------+-------------
pat's diner | Pat'S Diner
mary-ann | Mary-Ann
3rd street | 3rd Street
ibm usa llc | Ibm Usa Llc
first_name | First_Name
(5 rows)

pat's diner returns Pat'S Diner. The same rule that fixed O’Brien breaks every possessive.
Digits belong to the word, so 3rd stays lowercase after the 3, while the underscore in first_name starts a new word and hands you First_Name. For targeted fixes, I have a separate guide on PostgreSQL REGEXP_REPLACE.
Example 4: Proper Case the City but Keep State Codes Uppercase
I want City, ST for a label:
SELECT initcap(city) || ', ' || initcap(state) AS wrong,
initcap(city) || ', ' || upper(state) AS mailing
FROM contacts
WHERE id IN (1, 4);
Output:
wrong | mailing
-------------------+-------------------
Columbus, Oh | Columbus, OH
Winston-Salem, Nc | Winston-Salem, NC
(2 rows)
For Columbus, initcap gives Columbus, Oh; upper() gives Columbus, OH. The same pieces work with PostgreSQL CONCAT.
Example 5: Capitalize Only the First Letter of a String in PostgreSQL
Sometimes title case is wrong. The goal is sentence case for an order note:
SELECT initcap(s) AS initcap,
upper(left(s, 1)) || lower(substr(s, 2)) AS first_only
FROM (VALUES ('LATE DELIVERY TO OHIO')) AS t(s);
Output:
initcap | first_only
-----------------------+-----------------------
Late Delivery To Ohio | Late delivery to ohio
(1 row)

first_only returns Late delivery to ohio. Ohio loses its capital, so use it for notes, not places.
left() grabs the first character and substr(s, 2) grabs everything after it, the same positions the PostgreSQL SUBSTRING function uses.
Example 6: Clean a Column with UPDATE and INITCAP
Last, store the fix. You want full_name cleaned, touching only messy rows:
UPDATE contacts
SET full_name = initcap(full_name)
WHERE full_name IS DISTINCT FROM initcap(full_name);
SELECT count(*) AS still_messy FROM contacts
WHERE full_name <> initcap(full_name);
Output:
UPDATE 5
still_messy
-------------
0
(1 row)

psql reports UPDATE 5, and still_messy is 0, because the WHERE skipped Olivia’s clean row. Run the SELECT again and you should still see 0. My PostgreSQL UPDATE walkthrough has more patterns.
INITCAP vs UPPER and LOWER: Which Should You Use?
| Function | Use it for |
|---|---|
| initcap | names, cities, labels |
| upper | state codes, SKUs |
| lower | emails, matching |
My rule of thumb: initcap for display, lower for matching.
Tips & Common Mistakes
- initcap takes text only.
initcap(42)failed withfunction initcap(integer) does not exist; cast with42::text. - It keeps extra spaces, so trim first.
- Mc names and acronyms need a manual pass or REPLACE in PostgreSQL.
- The collation changes results. Under
COLLATE "C",élodiebecameéLodie; the ICU collationen-US-x-icuturnedo'brienintoO'brien.
Wrapping Up
In PostgreSQL, copy Example 4 for addresses and Example 6 to clean stored data.
Next step: browse the complete list of PostgreSQL functions or the PostgreSQL 18 string functions docs.
Two more string functions for the same cleanup job:
Frequently Asked Questions
Is there an INITCAP function in SQL Server or MySQL?
No. Both need UPPER(LEFT(…)) plus LOWER(SUBSTRING(…)) or a user-defined function. Oracle’s INITCAP works like PostgreSQL’s.
Can I use initcap in a generated column?
Yes, it’s IMMUTABLE. GENERATED ALWAYS AS (initcap(n)) STORED returned Tyler Reed in my test.
How do I keep words like and, of and the lowercase?
initcap has no option. Wrap it in a small PL/pgSQL function that lowercases a word list.

Kumar Saurabh is a freelance software engineer who builds web and mobile apps with Next.js, React, Flutter and Python. From 2021 to 2024, Saurabh worked as an IT analyst and developer at TSInfo Technologies, writing technical articles on SQL and PostgreSQL. Saurabh writes the PostgreSQL, MySQL, MariaDB and MongoDB tutorials on DatabaseFAQs.com and holds a Master of Computer Applications (MCA) from Chandigarh University.