// strings reference

SQL UPPER function

Returns the string with every character uppercased. Non-ASCII letters follow the collation's case rules, and uppercasing a column in a WHERE clause stops a plain index on it from being used.

Catégorie
Strings
Returns
string
In this category
4 of 172

Syntaxe

UPPER(string)

Prise en charge des moteurs

MoteurSupportNotes
SQL Server Oui Supported under this name.
PostgreSQL Oui Supported under this name.
MySQL Oui Supported under this name.
SQLite Oui Supported under this name.
Oracle Oui Supported under this name.

Exemples

Any engine

SELECT UPPER('mixed Case') AS shouted;  -- MIXED CASE

PostgreSQL

CREATE INDEX users_email_upper_idx ON users (UPPER(email));

Bon à savoir

  • UPPER maps one character to one character on all five engines by default, so UPPER('straße') stays 'STRAßE'. PostgreSQL 18's pg_unicode_fast collation applies full Unicode case mapping and returns 'STRASSE'.
  • SQLite's built-in UPPER only changes ASCII letters: UPPER('é') stays 'é' unless the ICU extension is loaded.
  • WHERE UPPER(email) = ... cannot use a plain index on email. Use a case-insensitive collation or an expression index. PostgreSQL's ILIKE does not help here: it cannot use a plain b-tree index either.

Questions about UPPER

Why does UPPER make my query slow?

Wrapping a column in a function stops the plain index on that column from being used. Add an expression index on UPPER(column), or compare case-insensitively via collation instead.

Do I need UPPER for case-insensitive matching?

On SQL Server and MySQL, usually not: their default collations are case-insensitive, so 'a' = 'A' is already true. PostgreSQL, Oracle and SQLite compare case-sensitively with =, so LOWER/UPPER on both sides, ILIKE (PostgreSQL) or a case-insensitive collation is needed. SQLite's LIKE is case-insensitive for ASCII only.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.