SQL LOWER function
Returns the string with every character lowercased. Its main job is normalizing emails, codes and identifiers before comparing or storing them.
- Категория
- Strings
- Returns
string- In this category
- 5 of 172
Синтаксис
LOWER(string)
Поддержка движка
| Движок | Support | Заметки |
|---|---|---|
| SQL Server | Да | Supported under this name. |
| PostgreSQL | Да | Supported under this name. |
| MySQL | Да | Supported under this name. |
| SQLite | Да | Supported under this name. |
| Oracle | Да | Supported under this name. |
Примеры
Any engine
SELECT LOWER('MiXeD') AS quiet; -- mixed
PostgreSQL
CREATE INDEX users_email_lower_idx ON users (LOWER(email));
Полезно знать
- Normalization usually happens once, on write: UPDATE users SET email = LOWER(email) beats LOWER() on every read afterwards.
- PostgreSQL's citext extension gives a case-insensitive text type, so plain = comparisons ignore case without LOWER() calls or expression indexes.
- Like UPPER, LOWER(column) = constant in a WHERE clause disables a plain index; index the expression instead.
Questions about LOWER
Is LOWER the same in every database?
For ASCII, yes. Beyond that it depends on the collation: SQLite's built-in LOWER only handles ASCII, and special cases like the Turkish dotted İ come out differently between engines and between collations on one engine.
Should I LOWER data on the way in or the way out?
On the way in, if the lowercase form is the data (emails, codes). Lowering on every read costs CPU and index usage forever.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
- Indexes on expressions like LOWER(col) in every SQL dialect Dialect comparison
- Case-insensitive string comparison Dialect comparison
- DISTINCT on an expression Dialect comparison
- Generate a UUID in SQL in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Compare strings ignoring case and accents in SQL Snippet
- Fuzzy match strings with Levenshtein distance in SQL Snippet
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
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.