UPPER and LOWER example
We want to show five employees with their original name and two calculated versions:
SELECT id,
name,
UPPER(name) AS uppercase,
LOWER(name) AS lowercase
FROM employees
ORDER BY id
LIMIT 5;What to look for: If an employee is called «Pat Ruiz», the calculated columns show «PAT RUIZ» and «pat ruiz». The original name stays the same: these functions only change how the text is presented in the query.
Check the result with small data
We compare two names written differently.
WITH customers(name) AS (
VALUES ('Amy'),('LIAM')
)
SELECT name, UPPER(name) AS uppercase,
LOWER(name) AS lowercase
FROM customers ORDER BY name;| name | uppercase | lowercase |
|---|---|---|
| Amy | AMY | amy |
| LIAM | LIAM | liam |
UPPER and LOWER transform the text in the output. How some international characters are converted depends on the engine and its settings.
Check your understanding: Which version would you use to make a label look consistent?
Show answer
Either one, as long as you apply the same one to every row: with LOWER(name), "Amy" and "LIAM" are shown as "ana" and "luis". The stored data does not change.
How UPPER and LOWER are used
The argument can be a column, a string or any expression that returns text. If the value is NULL, the result is also NULL.
Common mix-ups with UPPER and LOWER
Thinking the table has been changed
SELECT UPPER(name) FROM employees;The function only changes the value in the result. To change stored data you would need an UPDATE, a different operation that calls for care.
Key differences between engines
PostgreSQL applies the rules of the database's locale. MySQL uses the relevant character set and collation. SQLite, without extra extensions, only converts ASCII letters itself; characters outside that set may be left as they are. If you work with international names, check representative examples.