SQL unaccent function
Transliterates accented characters using a configurable rule file. An extension function, not core SQL, with an immutability catch for indexes.
- Категория
- Strings
- Returns
string- In this category
- 64 of 172
Синтаксис
unaccent(string)
Поддержка движка
| Движок | Support | Заметки |
|---|---|---|
| SQL Server | Not built in | No built-in equivalent. |
| PostgreSQL | Different name or syntax | requires CREATE EXTENSION unaccent |
| MySQL | Not built in | No built-in equivalent. |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | Not built in | No built-in equivalent. |
Примеры
PostgreSQL
CREATE EXTENSION IF NOT EXISTS unaccent;
SELECT unaccent('Héllo Wörld') AS plain; -- Hello World
Полезно знать
- It is an extension: CREATE EXTENSION unaccent; first. Rule sets live in unaccent.rule and can be customized per dictionary.
- unaccent() is STABLE, not IMMUTABLE, so expression indexes over it need an IMMUTABLE wrapper function (the single most-asked follow-up).
- Typical uses: accents-insensitive unique indexes, search normalization, and cleaning feeds before comparison.
- SQL Server reaches for TRANSLATE maps or accent-insensitive collations; MySQL for _ai collations; Oracle for TRANSLATE or LINGUISTIC sorts.
Questions about unaccent
Why can I not index unaccent(col) directly?
The function is STABLE because rules may change, and index expressions demand IMMUTABLE. Create an IMMUTABLE wrapper that calls unaccent and index that.
Does unaccent exist outside PostgreSQL?
Not as a function. SQL Server and MySQL fold accents through collations (_AI/_ai), Oracle through TRANSLATE or linguistic indexes.
Is unaccent safe for keys?
It makes 'café' and 'cafe' collide, which is the point for dedupe, and a hazard if the original spelling is meaningful. Normalize on a derived column, keep the original.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
- Compare strings ignoring case and accents in SQL Snippet
- Strip diacritics and accents in SQL Snippet
Cheat sheets for the engines that have it: PostgreSQL.
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.