Replies: 1 comment
|
Yes, the relation is lazy. Each execution can evaluate For several downstream queries that must share the same IDs, materialize once into a temporary table: import duckdb
con = duckdb.connect()
con.execute("""
CREATE TEMP TABLE stable_rows AS
SELECT gen_random_uuid() AS id, 'hello' AS some_col
""")
rel = con.table("stable_rows")
first = rel.fetchall()
second = rel.fetchall()
assert first == secondUse I verified this on DuckDB 1.5.5: repeated execution of the original relation produced different UUIDs, while the temporary table preserved them. Lazy relations are useful for composing queries; materialization is appropriate when multiple executions must share a stable result. See the relational API documentation. |
Uh oh!
There was an error while loading. Please reload this page.
I'm not sure if there's an issue here somewhere or me just misunderstanding how to do this properly, I'm generating a python relation where one of the columns is created via
gen_random_uuid(), e.g.:Just printing this relation out gives me a consistent UUID each time:
However, if I interact with the relation in any other way (select from it, or call
df()on it), the UUID gets regenerated each time:I assume this has to do with the python relational API's lazy evaluation? If I create a table (like with
to_table("some_name")) and then select from that table the problem goes away, so it seems like the two possible ways to get around this are:But I'm curious if I'm missing something obvious/is there a better or conventional way of dealing with this? This problem is coming up because I have multiple queries later on working with
my_relation, and combining all those results into a final relation that actually gets written as a table, but each later query is incorrectly working with a different set of UUIDs. Is it considered bad practice to create temporary relations like this instead of always making them actual tables and doing any processing on the tables themselves?All reactions