StringsSQL standard

LOWER

Converts text to lowercase.

Syntax

LOWER(<text>)

Makes every letter lowercase; other characters don't change. Its mirror function is UPPER, which makes letters uppercase. Most often you need LOWER to compare text regardless of case: Emma, emma and EMMA become the same.

Data for the examples

employees

namedepartmentsalarybonusphone
Emmabackend1200300+44 7700 900123
Liambackend1000NULLNULL
Oliviafrontend1350150+44 7700 900456
Noahfrontend950NULL+44 7700 900789
Sophiadesign1200200NULL

These tables already exist in the sandbox — the examples below use them. Want to try this in your own database? Copy the SQL.

In lowercase
SELECT LOWER('Hello, SQL') AS lower_case;
lower_case
hello, sql
Case-insensitive search
SELECT name, department
FROM employees
WHERE LOWER(name) = LOWER('EMMA');
namedepartment
Emmabackend

Whether someone typed EMMA or emma, we bring both sides to lowercase, and Emma is found.

Emails in one consistent form
SELECT LOWER('Emma.Wilson@Example.COM') AS email;
email
emma.wilson@example.com

People often type addresses any old way, but it's easier to store and compare them in lowercase.

Watch out

Bring both sides to the same case: LOWER(name) = 'Emma' finds nobody, because the left side is all lowercase and the right one has a capital E.

A regular index on name won't help a query with LOWER(name). For such searches you create an index on the expression: CREATE INDEX ON employees (LOWER(name));.

For case-insensitive pattern matching there's ILIKE: name ILIKE 'em%'.

Related functions