Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The DoubleColon cast always skips the AT TIME ZONE part, leading to strange behavior. #1266

Closed
dmitrybugakov opened this issue May 9, 2024 · 0 comments · Fixed by #1267
Closed

Comments

@dmitrybugakov
Copy link
Contributor

dmitrybugakov commented May 9, 2024

We have discovered that during DoubleColon cast, the parser consistently skips the AT TIME ZONE part. It functions correctly only when nested.

Consider the following select statement:
"SELECT c FROM t WHERE c >= '2019-03-27T22:00:00.000Z'::timestamp AT TIME ZONE 'Europe/Brussels'"

This results in the following AST, where we attempt to cast the condition under the WHERE clause instead of only the right part:

[Statement(Query(Query { with: None, body: Select(Select { distinct: None, top: None, projection: [UnnamedExpr(Identifier(Ident { value: "c", quote_style: None }))], into: None, from: [TableWithJoins { relation: Table { name: ObjectName([Ident { value: "t", quote_style: None }]), alias: None, args: None, with_hints: [], version: None, partitions: [] }, joins: [] }], lateral_views: [], selection: Some(AtTimeZone { timestamp: BinaryOp { left: Identifier(Ident { value: "c", quote_style: None }), op: GtEq, right: Cast { expr: Value(SingleQuotedString("2019-03-27T22:00:00.000Z")), data_type: Timestamp(None, None), format: None } }, time_zone: "Europe/Brussels" }), group_by: Expressions([]), cluster_by: [], distribute_by: [], sort_by: [], having: None, named_window: [], qualify: None, value_table_mode: None }), order_by: [], limit: None, limit_by: [], offset: None, fetch: None, locks: [], for_clause: None }))]

dmitrybugakov added a commit to dmitrybugakov/sqlparser-rs that referenced this issue May 9, 2024
dmitrybugakov added a commit to dmitrybugakov/sqlparser-rs that referenced this issue May 10, 2024
@dmitrybugakov dmitrybugakov changed the title The DoubleColonCast always skips the AT TIME ZONE part, leading to strange behavior. The DoubleColon cast always skips the AT TIME ZONE part, leading to strange behavior. May 10, 2024
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 a pull request may close this issue.

1 participant