SQL casing and the Turkish I
One lowercase letter, two uppercase answers: casing rules are locale-dependent, and the Turkish dotted/dotless I pair is where it bites.
- Categoría
- Strings
- Returns
string- In this category
- 31 of 172
Sintaxis
UPPER('i' COLLATE Turkish_CI_AS) -- engine-specific
Soporte del motor
| Motor | Support | Notas |
|---|---|---|
| SQL Server | Sí | Supported under this name. |
| PostgreSQL | Sí | Supported under this name. |
| MySQL | Sí | Supported under this name. |
| SQLite | Sí | Supported under this name. |
| Oracle | Sí | Supported under this name. |
Ejemplos
SQL Server
SELECT UPPER('i' COLLATE Turkish_CI_AS) AS tr,
UPPER('i' COLLATE Latin1_General_CI_AS) AS plain;
-- İ, I
PostgreSQL
SELECT upper('i' COLLATE "tr-TR-x-icu") AS tr; -- İ
Conviene saberlo
- In Turkish, uppercase('i') is 'İ' (dotted) and uppercase('ı') is 'I'. Engines only do this when the locale says so.
- SQL Server: a Turkish collation drives it. UPPER('i' COLLATE Turkish_CI_AS) is 'İ'; a default Latin collation gives 'I'.
- PostgreSQL: casing follows the database locale or a per-expression COLLATE; upper('i' COLLATE "tr-TR-x-icu") is 'İ' on an ICU install.
- MySQL's UPPER/LOWER use Unicode mappings without a locale switch and return 'I'; SQLite maps ASCII only. Neither can be 'wrong' per locale, which is itself the gotcha.
Questions about The Turkish I problem
Why does my data break when the server moves regions?
Casing and sorting followed the old server's locale. Values cased under one locale compare differently under another. Pin collations explicitly on columns and expressions.
How do I avoid the problem entirely?
Compare and match through case-insensitive collations or CI indexes instead of UPPER/LOWER round-trips, and never use UPPER as a normalization step for identifiers in multilingual data.
Does this affect ORDER BY too?
Yes. Sorting is locale-driven too: a Turkish collation treats dotless ı and dotted i as separate letters, with ı sorting first, so the same names can come back in a different order. The same COLLATE/NLS_SORT controls apply.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
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.