From 6ed9f4187b3c61268ac3f94cacd10b76abe0d721 Mon Sep 17 00:00:00 2001 From: "yigal.rozenberg" Date: Thu, 9 Jul 2026 09:14:40 -0700 Subject: [PATCH] docs(reference): document string-literal alias normalization (PR #22 follow-up) Add a 'String-Literal Aliases' subsection to the QuoteStyle reference: AS 'x' is accepted for every dialect (lenient input) and normalized to the target dialect's canonical quoted identifier (double-quote / backtick / bracket) with case preserved. Examples are the exact outputs asserted by the test_single_quoted_alias_transpile_to_* tests. Follow-up to PR #22 (v0.10.11). --- docs/reference.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/reference.md b/docs/reference.md index 2a1492a..908b32a 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1218,6 +1218,31 @@ assert!(QuoteStyle::Backtick.is_quoted()); assert!(!QuoteStyle::None.is_quoted()); ``` +### String-Literal Aliases + +Some dialects accept a **string literal** as an alias after an explicit `AS` +(`SELECT col AS 'Record Id'`) — notably SQLite, MySQL, Snowflake, and T-SQL +(legacy syntax). The parser accepts this form for every dialect (it is lenient +on input) and normalizes the alias to a **quoted identifier**, so the generator +re-emits it in the target dialect's canonical quote style with embedded quotes +escaped. The alias is treated as quoted, so its case is always preserved +(never folded). + +```rust +use sqlglot_rust::{transpile, Dialect}; + +// SQLite string-literal alias → the target dialect's canonical quoted identifier +assert_eq!(transpile("SELECT 7 AS 'Mixed'", Dialect::Sqlite, Dialect::Postgres).unwrap(), + r#"SELECT 7 AS "Mixed""#); // double quote +assert_eq!(transpile("SELECT 7 AS 'Mixed'", Dialect::Sqlite, Dialect::Mysql).unwrap(), + "SELECT 7 AS `Mixed`"); // backtick +assert_eq!(transpile("SELECT 7 AS 'Mixed'", Dialect::Sqlite, Dialect::Tsql).unwrap(), + "SELECT 7 AS [Mixed]"); // bracket +``` + +> A trailing string with **no** `AS` is never treated as an alias (in MySQL, +> adjacent string literals are concatenation). + --- ## Dialect Enum