-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prepared statement not working with multiple CTEs #2965
Comments
Indeed that looks like a bug and probably we simply never tested this. Thanks for reporting, will have a go at fixing. |
Here is a full example: import duckdb
con = duckdb.connect()
con.execute('create table "user" (name string)')
print(con.execute('''
with temp_first as (
select * from "user"
where "name" = ?
), temp_second as (
select * from "user"
where "name" = ?
)
select * from temp_first
''', ["val1", "val2"]).fetchall()) Interestingly, when I change the select to include the other CTE, it works, e.g. select * from temp_first, temp_second Also, when I use the following query with temp_first as (
select * from "user"
where "name" = ?
), temp_second as (
select * from temp_first
where "name" = ?
)
select * from temp_second all is well, too. This means the bug is likely due of DuckDB ignoring the unused CTE in its planning/binding phase. Is there a reason for these unused CTEs in your query? |
I believe the query in this was being built up iteratively, testing out parts as they went, so the second part was planned to be used but this error confused the consumer |
Bind unused CTEs to make sure all parameters get bound.
Add missing include.
* Back out dubious binding of unused CTE. * Replace with binding only requested parameters. * Record parameter count in `SQLStatement` * Make `SQLStatement::Copy` use copy constructors to ensure parameter count propagation * Use recorded parameter count for paremeter count validation.
What happens?
When trying to run a query w/ prepared statement and a CTE, I get an error regardless of how many parameters I pass.
To Reproduce
When trying to run this query (or one like it):
If I try to execute it like so:
I get this error, which is incorrect since there should be two arguments to insert:
If I instead only pass 1 like so:
I get the an error which looks correct:
Environment (please complete the following information):
Before Submitting
Have you tried this on the latest
master
branch?I tried using
0.3.2.dev1173
Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
The text was updated successfully, but these errors were encountered: