-
-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Last week DuckDB 1.4.0 was released, with the notable addition of: duckdb/duckdb#18738
Which adds this to the C API: https://duckdb.org/docs/stable/clients/c/appender.html#duckdb_appender_create_query
Currently when appending to a table we have to 1) ensure that we're inserting all columns and not just a subset of them, 2) ensure the columns are inserted in the exact same order as that of the table schema, and that 3) "The default value of the column must be a constant value. Non-deterministic expressions like nextval('seq') or random() are not supported."
To work around these limitations I've been creating temporary tables, appending to that, and then doing the insert from the temporary table. Despite that additional layer of indirection, the appender still proved faster overall than a typical INSERT INTO table (col3, col2) VALUES ((1, 2), (3, 4)) style SQL query.
The aforementioned PR states that this new interface works like a CTE, which is conceptually similar to using a temporary table. It mentions prior limitations regarding default values and seems to address them.
This potentially makes for a much nicer interface and avoids the need to use temporary tables or other workarounds for cases when you're only inserting a subset of columns or need non-deterministic default values, plus the PR even mentions facilitating "more complex operations like upserts, merge into, delete or update" beyond mere appending.