SQL identifier quoting
Identifiers need different delimiters than string literals, and each engine's case-folding rules turn quoting into a portability question of its own.
- カテゴリ
- Strings
- Returns
identifier- In this category
- 79 of 172
構文
"name"
`name`
[name]
Each block is a separate form. The support table and the examples show which engine takes which.
エンジンサポート
| エンジン | 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. |
例
PostgreSQL
SELECT "select" FROM "Users"; -- quoted identifiers keep case
MySQL
SELECT `order` FROM `order details`; -- backticks for reserved words
SQL Server
SELECT [order] FROM [Order Details];
知っておくと便利なこと
- The standard delimiter is double quotes; SQL Server accepts [brackets] (and quotes under QUOTED_IDENTIFIER); MySQL uses backticks by default and quotes only with ANSI_QUOTES.
- Case folding bites: PostgreSQL lowercases unquoted identifiers and preserves quoted ones, so users and "Users" are different tables. Oracle uppercases unquoted names.
- MySQL's "double quotes" are string literals unless ANSI_QUOTES is set, the reverse of the standard, a classic cross-engine bug.
- Reserved words and spaces always need quoting: order, group, select are legal column names everywhere once delimited.
Questions about Quoting identifiers
Are double quotes a string or an identifier?
An identifier in the SQL standard, PostgreSQL, Oracle, SQL Server (QUOTED_IDENTIFIER ON, the driver default) and MySQL with ANSI_QUOTES. Default MySQL treats them as strings. SQLite treats them as identifiers but falls back to a string when no such column exists.
Why does my quoted table name stop resolving?
Quoting preserves case: "Users" is not users on PostgreSQL. Drop the quotes to get case-folding, or match the exact stored case.
How do I quote identifiers safely in dynamic SQL?
SQL Server's QUOTENAME doubles embedded closers; PostgreSQL's quote_ident() does the same job, and MySQL's sys.quote_identifier() wraps in backticks. Validating names against the catalog or an allowlist is still the safer first step.
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.