INSERT, UPDATE, and DELETE statements in DuckDB
Use INSERT INTO to add rows to Hive tables and Apache Iceberg tables in the AWS Glue Data Catalog. Use UPDATE and DELETE to change and remove the rows of Iceberg tables. On a Hive table, INSERT INTO is the only one of these statements that works, and it can only add rows. These statements do not support the RETURNING clause. For more information about the statements that each table type supports, see SQL reference.
Each query runs one statement. Transactions are not supported, so each statement takes effect on its own. A write that fails with a transient-error message might already have been applied. Before you run it again, check whether the table already has the change.
The examples change three tables in a database named sales_db. The dml_sales table is an empty Hive table in Parquet format, and the dml_sales_by_region table is an empty Hive table in Parquet format that is partitioned by region. The dml_orders table is an Iceberg table that holds three orders. Some examples also read sales_parquet, a Hive table in Parquet format that holds six orders. Its data files are under s3://amzn-s3-demo-bucket/tables/sales_parquet/.
dml_sales, dml_orders, and sales_parquet have the columns order_id (INTEGER), customer (VARCHAR), region (VARCHAR), amount (DECIMAL(10,2)), and order_date (DATE). dml_sales_by_region has the columns order_id, customer, amount, and region, in that order. The amount column holds the order total in US dollars (USD).
Run the examples in the order in which this topic shows them, because many of them change the rows that other examples read.
Synopsis
INSERT INTO table [ ( column [, ...] ) ]
VALUES ( expression [, ...] ) [, ...]
INSERT INTO table [ BY { NAME | POSITION } ] query
UPDATE table
SET column = expression [, ...]
[ WHERE condition ]
DELETE FROM table [ WHERE condition ]
INSERT INTO with VALUES
INSERT INTO table VALUES adds the rows that you list to a table. Put each row in parentheses, and separate the rows with commas. Without a column list, each row has one value for each column of the table, in the order of the table's columns.
Each value can be a literal, such as DATE '2026-10-01' or NULL, or an expression. When the type of a value differs from the type of its column, DuckDB converts the value to the column's type. If a value cannot be converted, the statement fails.
Syntax
INSERT INTO table [ ( column
[, ...] ) ] VALUES ( expression [, ...] ) [, ...]
In the syntax, replace each placeholder as follows:
table-
The table to add the rows to. Write it as
table,database.table, orcatalog.database.table. column-
A column of the table that the values are for. For more information about column lists, see Column lists.
expression-
The value for one column of the new row.
Examples
The following SQL statement adds two rows to the Hive table dml_sales.
INSERT INTO sales_db.dml_sales VALUES (1, 'alice', 'east', 120.50, DATE '2026-10-01'), (2, 'bob', 'west', 75.00, DATE '2026-10-01')
The statement returns no rows.
The following SQL query returns the rows of dml_sales.
SELECT * FROM sales_db.dml_sales ORDER BY order_id
The query returns the following results.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
Considerations
INSERT INTO only adds rows. It does not replace or remove the rows that the table already has. INSERT OVERWRITE is not supported. On a Hive table, each INSERT INTO writes new data files under the table location and leaves the existing files in place.
Differences from Athena engine version 3
When DuckDB converts an inserted value to the type of its column, it uses DuckDB cast rules, which can differ from Athena engine version 3. For example, DuckDB stores the DOUBLE value 2.5E0 as 2 in an INTEGER column, because it rounds halves to the nearest even number. In Athena engine version 3, a cast of 2.5E0 to INTEGER returns 3. To control the result, round the value yourself, for example with CAST(round(x) AS INTEGER).
When INSERT INTO writes DOUBLE or REAL values to a Hive CSV table, DuckDB writes NaN, positive infinity, and negative infinity as nan, inf, and -inf. In contrast, Athena engine version 3 writes NaN, Infinity, and -Infinity, and reads the lowercase values as NULL. When other engines must read these values, use Parquet or Iceberg.
Column lists
To give values for only some columns, or to give them in another order, list the column names in parentheses after the table name. Each row then has one value for each listed column, in the order of the list. The columns that you leave out are set to NULL.
Syntax
INSERT INTO table ( column
[, ...] ) VALUES ( expression [, ...] ) [, ...]
Examples
The following SQL statement adds a row with values for only two columns, listed in an order that differs from the table's.
INSERT INTO sales_db.dml_sales ( customer, order_id ) VALUES ('carol', 3)
The statement returns no rows.
The following SQL query returns the new row. The columns that the column list left out are NULL.
SELECT order_id, customer, region, amount, order_date FROM sales_db.dml_sales WHERE order_id = 3
The query returns the following result.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
INSERT INTO with a query
INSERT INTO table query adds the rows that a SELECT query returns. DuckDB matches the columns of the query to the columns of the table by position. The query must therefore return one column for each column of the table, in the same order. To match the columns by name instead, use BY NAME.
The query can read other tables. To load files from Amazon S3 into a table, read them in the query with a table function such as read_parquet, read_csv, or read_json.
Syntax
INSERT INTO table query
In the syntax, replace each placeholder as follows:
query-
A
SELECTquery that returns one column for each column of the table, in the order of the table's columns.
Examples
The following SQL statement adds orders 4 and 5 from the sales_parquet table.
INSERT INTO sales_db.dml_sales SELECT * FROM sales_db.sales_parquet WHERE order_id IN (4, 5)
The statement returns no rows.
The following SQL statement reads the Parquet files of the sales_parquet table directly from Amazon S3 with read_parquet and adds order 6.
INSERT INTO sales_db.dml_sales SELECT * FROM read_parquet( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' ) WHERE order_id = 6
The statement returns no rows.
The following SQL query returns every row of dml_sales.
SELECT * FROM sales_db.dml_sales ORDER BY order_id
The query returns the following results.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BY NAME and BY POSITION
By default, INSERT INTO matches the columns of a query to the columns of the table by position. With BY NAME, it matches each column of the query to the table column that has the same name, in any order. The query can leave out columns, and the columns that it leaves out are set to NULL. Each column of the query must have the name of a column of the table.
BY POSITION matches the columns by position, which is the default. You cannot use BY NAME with a column list. BY NAME also needs a query, not a VALUES list.
Syntax
INSERT INTO table BY { NAME | POSITION } query
Examples
The following SQL statement adds a row from a query whose columns are in a different order from the table's, and that leaves out two columns.
INSERT INTO sales_db.dml_sales BY NAME SELECT 'grace' AS customer, 7 AS order_id, 'south' AS region
The statement returns no rows.
The following SQL query returns the new row. Each value is in the column of the same name, and amount and order_date are NULL.
SELECT order_id, customer, region, amount, order_date FROM sales_db.dml_sales WHERE order_id = 7
The query returns the following result.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
Insert rows into a partitioned Hive table
To add rows to a partitioned Hive table, give a value for each partition column, as for any other column. With a column list, you can list a partition column in any position. When you insert rows, DuckDB writes each row under the Amazon S3 prefix of its partition, such as region=east/ under the table location. It also registers each new partition in the AWS Glue Data Catalog, so you do not have to register partitions before you insert rows into them.
To list the partitions of a Hive table and their locations, query glue_partitions('database.table'). For more information about glue_partitions, see glue_partitions function.
Examples
The following SQL statement adds the six orders of sales_parquet to dml_sales_by_region. The query returns the columns in the order of the table's columns, with the partition column region last.
INSERT INTO sales_db.dml_sales_by_region SELECT order_id, customer, amount, region FROM sales_db.sales_parquet
The statement returns no rows.
The following SQL statement adds a row for the region south, which has no partition yet.
INSERT INTO sales_db.dml_sales_by_region VALUES ( 7, 'grace', 64.00, 'south' )
The statement returns no rows.
The following SQL query lists the partitions of the table and their locations. The insert of order 7 registered the partition for south.
SELECT region, location FROM glue_partitions('sales_db.dml_sales_by_region') ORDER BY region
The query returns the following results.
| region | location |
|---|---|
|
|
|
|
|
|
|
|
The following SQL query counts the orders and totals the amounts in each partition. The east total leaves out order 6, whose amount is NULL.
SELECT region, count(*) AS orders, sum(amount) AS revenue FROM sales_db.dml_sales_by_region GROUP BY region ORDER BY region
The query returns the following results.
| region | orders | revenue |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Differences from Athena engine version 3
In Athena engine version 3, you list the partitions of a table with SHOW PARTITIONS. In DuckDB, query glue_partitions instead.
Insert rows into an Iceberg table
INSERT INTO works the same way on Iceberg tables, with VALUES or a query, and with or without a column list.
Each statement that changes an Iceberg table commits one new snapshot. Queries that start after the commit read the new rows. Time travel queries can still read the table as it was in an earlier snapshot. For more information about time travel queries, see Time travel queries on Iceberg tables. To list the snapshots of a table, with the operation and the number of rows that each one added, query iceberg_snapshots('database.table'). After a write fails, query iceberg_snapshots to check whether the write committed before you run it again.
Examples
The following SQL statement adds an order to the Iceberg table dml_orders.
INSERT INTO sales_db.dml_orders VALUES ( 4, 'dave', 'north', 310.00, DATE '2026-10-03' )
The statement returns no rows.
The following SQL query returns the rows of dml_orders: the three orders that it held, and the new one.
SELECT * FROM sales_db.dml_orders ORDER BY order_id
The query returns the following results.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following SQL query lists the snapshots of dml_orders. The first snapshot added the three orders that the table started with. The insert made the second snapshot, which added one row.
SELECT sequence_number, operation, summary['added-records'] AS added_records FROM iceberg_snapshots('sales_db.dml_orders') ORDER BY sequence_number
The query returns the following results.
| sequence_number | operation | added_records |
|---|---|---|
|
|
|
|
|
|
Considerations
You can read Iceberg tables in format version 1, but you cannot write to them.
You cannot write to a branch or a tag of an Iceberg table.
DuckDB writes Iceberg data files in Parquet format, regardless of the value of the table's write.format.default property.
UPDATE statement
UPDATE sets one or more columns in the rows that the WHERE condition selects. Without a WHERE clause, it changes every row of the table.
An expression in the SET clause can refer to the current values of the row. For example, amount = amount + 5.00 adds USD 5.00 to the amount.
Syntax
UPDATE table SET column = expression [, ...]
[ WHERE condition ]
In the syntax, replace each placeholder as follows:
table-
The Iceberg table to change.
column-
A column to set.
expression-
The new value of the column.
condition-
The condition that selects the rows to change, as a Boolean expression.
Examples
The following SQL statement sets the amount of order 2 to USD 80.00.
UPDATE sales_db.dml_orders SET amount = 80.00 WHERE order_id = 2
The statement returns no rows.
The following SQL statement adds USD 5.00 to the amount of each order in the east region and sets the order date of those orders.
UPDATE sales_db.dml_orders SET amount = amount + 5.00, order_date = DATE '2026-10-05' WHERE region = 'east'
The statement returns no rows.
The following SQL query returns the rows after both updates.
SELECT * FROM sales_db.dml_orders ORDER BY order_id
The query returns the following results.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Considerations
UPDATE works only on Iceberg tables. On a Hive table, the statement fails. To change rows of a Hive table, write the changed rows to a new table with CREATE TABLE AS SELECT. For more information about creating a table from a query, see CREATE TABLE AS.
UPDATE and DELETE write row-level changes to Iceberg tables in merge-on-read mode. DuckDB does not support copy-on-write mode. Before you change the rows of a table whose write-mode properties, such as write.update.mode, are set to copy-on-write, set them to merge-on-read.
DELETE statement
DELETE FROM removes the rows that the WHERE condition selects. Without a WHERE clause, it removes every row, and the empty table stays in the AWS Glue Data Catalog.
Syntax
DELETE FROM table [ WHERE condition ]
In the syntax, replace each placeholder as follows:
table-
The Iceberg table to remove rows from.
condition-
The condition that selects the rows to remove, as a Boolean expression.
Examples
The following SQL statement removes order 3.
DELETE FROM sales_db.dml_orders WHERE order_id = 3
The statement returns no rows.
The following SQL query returns the rows that are left.
SELECT * FROM sales_db.dml_orders ORDER BY order_id
The query returns the following results.
| order_id | customer | region | amount | order_date |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Considerations
DELETE works only on Iceberg tables. On a Hive table, the statement fails.