You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DuckDBPyRelation.query(): reusing a virtual table name silently changes the result of an existing relation #604
rel.query(virtual_table_name, sql) returns a lazy relation that re-resolves virtual_table_name through the connection's catalog on every execution. Registering the same name again from a different relation therefore changes what an already-constructed relation returns, with no error, even after that relation has been executed once.
Why it matters
Wrong data rather than an error. For a library this rules out any fixed name, so we generate a unique random name per call, which then accumulates.
What I would expect
One of:
the derived relation binds the virtual table once, at construction, so it is unaffected by later registrations; or
re-registering a name that a live relation depends on raises; or
if this is intended, a note on the relational API docs saying that the name is resolved late and must not be reused.
To Reproduce
import duckdb
con = duckdb.connect()
a = con.sql("select 1 as a")
b = con.sql("select 999 as a")
first = a.query("v", "select a from v")
print(first.fetchall()) # [(1,)]
second = b.query("v", "select a from v") # same name, unrelated relation
print(second.fetchall()) # [(999,)]
Activity
Use CTE for query relation (#656)
evertlammerts commentedon Oct 14, 2026
Thanks! Fixed in #656