Skip to content

fix: parse ANSI typed string literals (DATE/TIMESTAMP/TIME 'x') - #12

Merged
yigalrozenberg merged 1 commit into
masterfrom
fix/cr-003-ansi-date-timestamp-literals
May 26, 2026
Merged

fix: parse ANSI typed string literals (DATE/TIMESTAMP/TIME 'x')#12
yigalrozenberg merged 1 commit into
masterfrom
fix/cr-003-ansi-date-timestamp-literals

Conversation

@yigalrozenberg

Copy link
Copy Markdown
Collaborator

Summary

Fixes CR-003 / PSQ-2244.

The parser did not recognize ANSI SQL typed string literals (DATE '2024-01-01', TIMESTAMP '...', TIME '...'). They were mis-parsed as a bare column reference (Expr::Column { name: "DATE" }) followed by an orphaned string literal, producing malformed output (e.g., SELECT DATE, '2024-01-01' FROM DUAL).

Changes

Parser (src/parser/sql_parser.rs):

  • Added early detection in parse_primary() — when a DATE/TIMESTAMP/TIMESTAMP WITH TIME ZONE/TIME token is followed by a string literal, produce Expr::Cast.

Generator (src/generator/sql_generator.rs):

  • Added ANSI typed-string emission in the Expr::Cast arm — emits DATE 'x' for all dialects except MySQL family (which uses CAST('x' AS DATE)).

Tests:

  • 11 new tests covering roundtrips, cross-dialect transpilation, WHERE/BETWEEN/INSERT contexts, and edge cases (DATE as column name, DATE as function call).

Roundtrip Behavior

Input Oracle/Postgres/Snowflake MySQL
DATE '2024-01-01' DATE '2024-01-01' CAST('2024-01-01' AS DATE)
TIMESTAMP '2024-06-15 10:30:00' TIMESTAMP '2024-06-15 10:30:00' CAST('...' AS TIMESTAMP)
TIME '10:30:00' TIME '10:30:00' CAST('10:30:00' AS TIME)

Parse DATE 'x', TIMESTAMP 'x', and TIME 'x' as Expr::Cast instead of
mis-parsing them as a bare column reference followed by an orphaned
string literal.

Generator emits the ANSI typed-string form for all dialects except
MySQL family (which uses CAST(...) form).

Fixes CR-003 / PSQ-2244.
@yigalrozenberg
yigalrozenberg merged commit 513542e into master May 26, 2026
5 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