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

In some instances compiled SQL is incompatible with duckdb client #361

Closed
roveo opened this issue Aug 8, 2022 · 1 comment
Closed

In some instances compiled SQL is incompatible with duckdb client #361

roveo opened this issue Aug 8, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@roveo
Copy link

roveo commented Aug 8, 2022

Twin issue of duckdb/duckdb#4314, it was suggested to continue here.

To reproduce

import duckdb
from sqlalchemy import func, select, create_engine, MetaData, Table

# setup
conn = duckdb.connect("test.duckdb")
conn.execute("create table test (dt date); insert into test values ('2022-01-01');");

# query
engine = create_engine("duckdb:///test.duckdb")
metadata = MetaData(engine)
metadata.reflect()
test = metadata.tables["test"]
part = "year"
date_part = func.date_part(part, test.c.dt)

stmt = select(date_part).select_from(test).group_by(date_part)
engine.execute(stmt).fetchall()

Compiled statement:

SELECT date_part(?, test.dt) AS date_part_1 
FROM test GROUP BY date_part(?, test.dt)

So, from our discussion, I see several possibilities:

  • I just shouldn't generate queries this way with sqla.
  • There is a bug in duckdb library itself, I guess the consensus is that this is not the case.
  • The compiled statement is incorrect and it's fixable from within duckdb_engine.
  • The compiled statement is incorrect and it's only fixable from within the core sqlalchemy library.
@Mause Mause linked a pull request Sep 13, 2022 that will close this issue
@Mause Mause added the bug Something isn't working label Feb 28, 2023
@Mause
Copy link
Owner

Mause commented Dec 5, 2023

As of #836 this is now fixed for SQLAlchemy 2+

@Mause Mause closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants