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

Failure Casting String Literal to DATE in WHERE clause #457

Open
b-schmeling opened this issue Nov 20, 2024 · 1 comment
Open

Failure Casting String Literal to DATE in WHERE clause #457

b-schmeling opened this issue Nov 20, 2024 · 1 comment

Comments

@b-schmeling
Copy link

b-schmeling commented Nov 20, 2024

If I run the following with the file
samsung_sales.xlsx

import duckdb

sql = """
    INSTALL spatial; LOAD spatial;
    SELECT *
    FROM st_read('./samsung_sales.xlsx', open_options=['HEADERS=FORCE'], layer='Orders')
    WHERE "Date" >= '2022-01-01'
conn = duckdb.connect(database=":memory:")
conn.execute(sql)

I receive the error:

Traceback (most recent call last):
File "/Users/bethany/repos/x/date_duckdb.py", line 15, in
conn.execute(sql)
duckdb.duckdb.IOException: IO Error: GDAL Error (1): SQL Expression Parsing Error: syntax error, unexpected $undefined, expecting end of string. Occurred around :
Date>='2022-01-01'::DATE AND Date IS NOT NULL

The same error occurs even if I explicitly cast the string literal, e.g.:

import duckdb

sql = """
    INSTALL spatial; LOAD spatial;
    SELECT *
    FROM st_read('./samsung_sales.xlsx', open_options=['HEADERS=FORCE'], layer='Orders')
    WHERE "Date" >= CAST('2022-01-01' AS DATE)
"""
conn = duckdb.connect(database=":memory:")
conn.execute(sql)

However, if I run this same SQL with a csv file, e.g.
BikeShare.csv
it succeeds:

import duckdb

sql = """
    SELECT *
    FROM read_csv('./BikeShare.csv')
    WHERE "date" >= '2022-01-01'
"""
conn = duckdb.connect(database=":memory:")
conn.execute(sql)
@Maxxen
Copy link
Member

Maxxen commented Nov 20, 2024

Hello! this is related to filter pushdown into GDAL (st_read), which is why you don't get the same error with the csv. When we pass filters down we "stringily" the expressions, but It seems like GDAL's SQL-dialect doesn't understand the :: as a cast operator since it is syntax that DuckDB has inherited from PostgreSQL.

As a workaround for now you can disable the filter pushdown optimizer by running:

pragma disabled_optimizers='filter_pushdown';

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