0
0
PostgreSQLquery~5 mins

UPPER, LOWER, INITCAP in PostgreSQL

Choose your learning style9 modes available
Introduction

These functions change the case of letters in text. They help make text look consistent or easier to read.

When you want to make all letters in a name uppercase for a report.
When you need to compare text without worrying about uppercase or lowercase differences.
When you want to format names so the first letter of each word is capitalized.
When cleaning up user input to store it in a consistent way.
When displaying text in a user interface with a specific style.
Syntax
PostgreSQL
UPPER(text)
LOWER(text)
INITCAP(text)

UPPER changes all letters to uppercase.

LOWER changes all letters to lowercase.

INITCAP capitalizes the first letter of each word and makes the rest lowercase.

Examples
This makes all letters uppercase: 'HELLO WORLD'
PostgreSQL
SELECT UPPER('hello world');
This makes all letters lowercase: 'hello world'
PostgreSQL
SELECT LOWER('Hello WORLD');
This capitalizes the first letter of each word: 'Hello World'
PostgreSQL
SELECT INITCAP('hello world');
This fixes mixed case to 'My Name Is John'
PostgreSQL
SELECT INITCAP('mY nAmE iS JoHN');
Sample Program

This query shows how each function changes the text.

PostgreSQL
SELECT
  UPPER('postgresql') AS upper_case,
  LOWER('PostgreSQL') AS lower_case,
  INITCAP('pOstGreSQL database') AS initcap_case;
OutputSuccess
Important Notes

These functions only affect letters; numbers and symbols stay the same.

INITCAP treats any non-letter as a word separator.

Use these functions to make text comparisons easier by normalizing case.

Summary

UPPER makes all letters uppercase.

LOWER makes all letters lowercase.

INITCAP capitalizes the first letter of each word.