This page lists what Python code written for DuckDB 1.x must change to run on DuckDB 2.0. Each item gives the 1.x form, the 2.0 form and the page that explains it. For changes outside the Python client, see Migrating to DuckDB v2.0.
-
Python version. DuckDB 2.0 requires Python 3.11 or newer; free-threaded builds of CPython are not supported. On Python 3.10,
pip install duckdbinstalls a 1.x release. See Installation. -
Arrow and Polars output of
execute(). 1.x:con.execute(query).fetch_arrow_table(),fetch_record_batch(),arrow()andpl(). 2.0: these methods are gone fromexecute()results, andto_arrow_table()andto_arrow_reader()there copy the rows and warn. Use a relation:con.sql(query).to_arrow_table(),con.sql(query).to_arrow_reader()orcon.sql(query).pl(). See Arrow and Polars Output. -
Fetching from a relation. 1.x:
rel.fetchone(),rel.fetchmany(n),rel.execute()andrel.fetch_df_chunk(). 2.0: these methods are gone, because a relation keeps no result between calls and runs its query again on every read. To keep afetchone()orfetchmany()loop for a SQL query, create its result withcon.execute(query)instead ofcon.sql(query). To iterate over an existing relation, usefor row in rel.iter_rows(): ...; this keeps the complete result in engine memory. For streamed batches, userel.to_arrow_reader(). Replacerel.execute()withrel.materialize()when you want to compute and retain the rows. -
Plain strings in expressions. 1.x: in
ColumnExpression("s") == "x"and inrel.update(set={"a": "x"}), the string"x"named a column. 2.0: in an expression a plain string is a value, so the comparison testssagainst the textxand warns whenxis also a column name;update()refuses a plain string with aTypeError. Writecol("x")for the column andlit("x")for the text. See the Expression API andupdate. -
Dotted column names. 1.x:
ColumnExpression("t.x")was the columnxoft. 2.0: a name is never split at a dot, so"t.x"is one column name, and a query without a column of that name raises aBinderException. Writecol("t", "x"). See Column Expression. -
Dicts with keys that are not strings. 1.x:
con.values({1: "a"})made aSTRUCTwith a field named1. 2.0: invalues()and in expressions, such a dict becomes aMAP, hereMAP(INTEGER, VARCHAR). Use string keys for aSTRUCT. Seedict. -
Columns named like new relation methods. 1.x:
rel.offsetwas the columnoffsetofrel. 2.0: relations have new methods such asoffset,sample,head,rename,pivot,drop,unnest,unpivot,previewandgroup_by, sorel.offsetis the method. Writerel["offset"]for the column. See the Relational API. -
sql()of statements that do not read. 1.x:con.sql("CREATE TABLE t (i INTEGER)")returnedNone. 2.0: it returns a relation over what the statement returned, which a REPL or notebook prints; the statement still runs at the call. Usecon.execute()for DDL and DML. Printing a relation runs its query, every time. See Basic API Usage. -
Open
execute()results. 1.x: other queries on the connection ran while a result was partly read. 2.0: running another query on the connection raises aResourceInUseExceptionuntil the result is read to its end or ended withcon.complete()orcon.abort(), and the nextexecute()replaces the open result. See Open Results. -
One connection in several threads. 1.x: calls from several threads on one connection waited for each other. 2.0: a call while another thread uses the connection raises a
ResourceInUseException. Give each thread its owncon.cursor(). See Using Connections in Parallel Python Programs. -
Failed statements in a transaction. 1.x: after
con.begin(), a statement run withexecute()that failed with a catalog, binder or parser error left the transaction usable. 2.0: any statement run withexecute()that fails aborts the transaction:con.commit()then rolls it back, and any other statement raises aTransactionExceptionuntilcon.rollback(). See Transactions. -
Writing files with
overwrite=False. 1.x:rel.write_csv(path, overwrite=False)andrel.write_parquet(path, overwrite=False)replaced an existing file. 2.0: they raise anIOException. Leaveoverwriteout to replace the file. Seewrite_csvandwrite_parquet. -
Decimalvalues with a positive exponent. 1.x:Decimal("1E+2")became1.00of typeDECIMAL(3,2). 2.0: it is100of typeDECIMAL(3,0). See Conversion between DuckDB and Python. -
Arrow batch size. 1.x: the Arrow output of a relation came in batches of 1000000 rows by default. 2.0: the default is 131072 rows. Pass
batch_sizetoto_arrow_table()orto_arrow_reader()for another size. Seeto_arrow_reader. -
Database files. 1.x: a database file that DuckDB 1.5 wrote opens in DuckDB 1.5. 2.0: DuckDB 1.5 cannot open a file that DuckDB 2.0 writes in its default format; to keep a file readable by DuckDB 1.5, connect with
config={"storage_compatibility_version": "v1.5.0"}. See Configuration and Storage Format.