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

Using interval as a column name with :: results in ParseError #2098

Closed
Bilbottom opened this issue Aug 20, 2023 · 0 comments
Closed

Using interval as a column name with :: results in ParseError #2098

Bilbottom opened this issue Aug 20, 2023 · 0 comments
Assignees

Comments

@Bilbottom
Copy link

Details (bug)

First off -- I love this library! It's super helpful 😄

What I've found looks like a bug, but it looks like it's because of an unquoted reserved keyword being used in the SQL that's being parsed.

The following SQL results in a ParseError after passing it to the sqlglot.parse function:

SELECT interval::INTEGER AS minute_interval
FROM staging.tracker

Here's a snippet of the error -- the sqlglot version used is 17.14.2 (latest):

image

Despite a reserved keyword being used, this is still valid SQL and the SQL will run correctly against the database (in this case, duckdb) so this is a false-positive error.

Additional Details

This is NOT an issue when, either:

  • The interval column is quoted
  • The CAST function is used instead of the :: syntax

Note that this also seems to only be the case for this special keyword -- I tried some others, like date, and they have all worked fine.

Here's an MWE to reproduce this error (and show that the other cases work fine):

import sqlglot  # 17.14.2

SQL_OK_1 = """\
SELECT CAST(interval AS INTEGER) AS time_interval
FROM staging.tracker
"""

SQL_OK_2 = """\
SELECT "interval"::INTEGER AS time_interval
FROM staging.tracker
"""

SQL_OK_3 = """\
SELECT date::DATE AS tracker_date
FROM staging.tracker
"""

SQL_ERROR = """\
SELECT interval::INTEGER AS time_interval
FROM staging.tracker
"""

# All fine
print(sqlglot.parse(SQL_OK_1, read="duckdb"))
print(sqlglot.parse(SQL_OK_2, read="duckdb"))
print(sqlglot.parse(SQL_OK_3, read="duckdb"))

# No likey
print(sqlglot.parse(SQL_ERROR, read="duckdb"))
@tobymao tobymao self-assigned this Aug 20, 2023
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

No branches or pull requests

2 participants