I want to create a connectionless data frame like object that I can register to the connection, as I would do that with an arrow or pandas data frame.
import duckdb
conn = duckdb.connect(":memory:")
df = conn.sql("SELECT * FROM '/tmp/test.csv'")
conn.close()
conn1 = duckdb.connect(":memory:")
conn1.register("test", df)
conn1.execute("SELECT * FROM test")
This code doesn't work with the exception: Connection Error: Connection has already been closed
If I comment conn.close(), then it throws: The relation you are attempting to register was not made from this connection
If I do df = conn.sql("SELECT * FROM lineitem").arrow() it works because the intermediate state is in the arrow format. It materializes and doesn't depend on the connection.
Can I do something similar in the duckdb without materialization but just to create a lazy data frame that I can register and use in another connection?
I expected that the duckdb object is connection less and that i can register it on the another connection.
Relations are bound to a connection, this is because relations are already partially bound, the names and types of the result have been resolved.
What you're looking for is more akin to the parsed statement, I have a branch working on exposing the ExtractStatements method from the C++ API to the Python bindings.|
That would be more along the lines of what you expect, not being reliant on any given Connection, from there you can create a Relation from the parsed statement.