Skip to content

fix(tsql): quote reserved-keyword aliases and translate niladic temporal expressions (CR-009)#15

Merged
yigalrozenberg merged 1 commit into
masterfrom
fix/cr-009-tsql-reserved-keyword-alias
May 28, 2026
Merged

fix(tsql): quote reserved-keyword aliases and translate niladic temporal expressions (CR-009)#15
yigalrozenberg merged 1 commit into
masterfrom
fix/cr-009-tsql-reserved-keyword-alias

Conversation

@yigalrozenberg

Copy link
Copy Markdown
Collaborator

Summary

Implements CR-009. Two related TSQL transpilation issues:

Fix 1 — Reserved-keyword alias quoting

Column / table aliases that collide with T-SQL reserved keywords (e.g. current_time, time, key, user) were emitted bare, causing MSSQL syntax error 156. Adds Generator::write_alias which auto-promotes QuoteStyle::None to QuoteStyle::Bracket for TSQL/Fabric targets when the alias matches the reserved-keyword set in dialects::is_tsql_reserved. Applied at all alias emission sites (SelectItem, Subquery, TableFunction, TableRef, Unpivot, Pivot, PivotValue).

Fix 2 — Bare niladic temporal expressions

ANSI CURRENT_TIME / CURRENT_DATE / CURRENT_TIMESTAMP / LOCALTIMESTAMP without parentheses previously parsed as bare column references and passed through verbatim. Adds a new TypedFunction::CurrentTime variant and a parse_primary rewrite that materializes unquoted, unparenthesized occurrences as the matching TypedFunction. Generator emits TSQL-compatible CAST(GETDATE() AS TIME) / CAST(GETDATE() AS DATE) / GETDATE() and the right form for MySQL/Hive/Postgres.

Tests

  • 12 new cases in tests/test_tsql_reserved.rs
  • Full suite: 1050 passed, 0 failed

Jira

PSQ-2419

…ral expressions (CR-009)

Two related TSQL transpilation issues:

1. Column/table aliases that collide with T-SQL reserved keywords (e.g.
   current_time, time, key, user) were emitted bare, causing MSSQL syntax
   error 156. Add Generator::write_alias which auto-promotes
   QuoteStyle::None to QuoteStyle::Bracket for TSQL/Fabric targets when
   the alias matches the reserved-keyword set in
   dialects::is_tsql_reserved. Apply at all alias emission sites
   (SelectItem, Subquery, TableFunction, TableRef, Unpivot, Pivot,
   PivotValue).

2. ANSI niladic temporal expressions (CURRENT_TIME, CURRENT_DATE,
   CURRENT_TIMESTAMP, LOCALTIMESTAMP) without parentheses parsed as bare
   column references, then passed through verbatim. Add a new
   TypedFunction::CurrentTime variant and a parser rewrite in
   parse_primary that materializes unquoted, unparenthesized occurrences
   as the matching TypedFunction. Generator emits TSQL-compatible
   CAST(GETDATE() AS TIME)/DATE) and GETDATE() forms, with appropriate
   variants for MySQL/Hive/Postgres.

Adds tests/test_tsql_reserved.rs covering both fixes (12 cases).
@yigalrozenberg yigalrozenberg merged commit 3e6bd03 into master May 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant