

# 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](duckdb-sql-reference.md).

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
<a name="athena-duckdb-statement-dml-synopsis"></a>

```sql
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`
<a name="athena-duckdb-statement-dml-insert-values"></a>

`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
<a name="athena-duckdb-statement-dml-insert-values-syntax"></a>

```sql
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`, or `catalog`.`database`.`table`.

**{{column}}**  
A column of the table that the values are for. For more information about column lists, see [Column lists](#athena-duckdb-statement-dml-column-list).

**{{expression}}**  
The value for one column of the new row.

### Examples
<a name="athena-duckdb-statement-dml-insert-values-examples"></a>

The following SQL statement adds two rows to the Hive table `dml_sales`.

```sql
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`.

```sql
SELECT * FROM sales_db.dml_sales ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | region | amount | order\_date | 
| --- | --- | --- | --- | --- | 
| `1` | `alice` | `east` | `120.50` | `2026-10-01` | 
| `2` | `bob` | `west` | `75.00` | `2026-10-01` | 

### Considerations
<a name="athena-duckdb-statement-dml-insert-values-considerations"></a>

`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
<a name="athena-duckdb-statement-dml-insert-values-differences-from-engine-version-3"></a>

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
<a name="athena-duckdb-statement-dml-column-list"></a>

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
<a name="athena-duckdb-statement-dml-column-list-syntax"></a>

```sql
INSERT INTO {{table}} ( {{column}}
    [, ...] ) VALUES ( {{expression}} [, ...] ) [, ...]
```

### Examples
<a name="athena-duckdb-statement-dml-column-list-examples"></a>

The following SQL statement adds a row with values for only two columns, listed in an order that differs from the table's.

```sql
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`.

```sql
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 | 
| --- | --- | --- | --- | --- | 
| `3` | `carol` | `NULL` | `NULL` | `NULL` | 

## `INSERT INTO` with a query
<a name="athena-duckdb-statement-dml-insert-query"></a>

`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
<a name="athena-duckdb-statement-dml-insert-query-syntax"></a>

```sql
INSERT INTO {{table}} {{query}}
```

In the syntax, replace each placeholder as follows:

**{{query}}**  
A `SELECT` query that returns one column for each column of the table, in the order of the table's columns.

### Examples
<a name="athena-duckdb-statement-dml-insert-query-examples"></a>

The following SQL statement adds orders 4 and 5 from the `sales_parquet` table.

```sql
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.

```sql
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`.

```sql
SELECT * FROM sales_db.dml_sales ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | region | amount | order\_date | 
| --- | --- | --- | --- | --- | 
| `1` | `alice` | `east` | `120.50` | `2026-10-01` | 
| `2` | `bob` | `west` | `75.00` | `2026-10-01` | 
| `3` | `carol` | `NULL` | `NULL` | `NULL` | 
| `4` | `dave` | `north` | `310.00` | `2026-10-03` | 
| `5` | `erin` | `west` | `18.75` | `2026-10-03` | 
| `6` | `frank` | `east` | `NULL` | `2026-10-04` | 

## `BY NAME` and `BY POSITION`
<a name="athena-duckdb-statement-dml-by-name"></a>

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
<a name="athena-duckdb-statement-dml-by-name-syntax"></a>

```sql
INSERT INTO {{table}} BY { NAME | POSITION } {{query}}
```

### Examples
<a name="athena-duckdb-statement-dml-by-name-examples"></a>

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.

```sql
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`.

```sql
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 | 
| --- | --- | --- | --- | --- | 
| `7` | `grace` | `south` | `NULL` | `NULL` | 

## Insert rows into a partitioned Hive table
<a name="athena-duckdb-statement-dml-partitioned-hive"></a>

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](duckdb-functions-glue.md#athena-duckdb-functions-glue-glue-partitions).

### Examples
<a name="athena-duckdb-statement-dml-partitioned-hive-examples"></a>

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.

```sql
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.

```sql
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`.

```sql
SELECT region, location
FROM glue_partitions('sales_db.dml_sales_by_region')
ORDER BY region
```

The query returns the following results.


| region | location | 
| --- | --- | 
| `east` | `s3://amzn-s3-demo-bucket/tables/dml_sales_by_region/region=east` | 
| `north` | `s3://amzn-s3-demo-bucket/tables/dml_sales_by_region/region=north` | 
| `south` | `s3://amzn-s3-demo-bucket/tables/dml_sales_by_region/region=south` | 
| `west` | `s3://amzn-s3-demo-bucket/tables/dml_sales_by_region/region=west` | 

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`.

```sql
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 | 
| --- | --- | --- | 
| `east` | `3` | `162.75` | 
| `north` | `1` | `310.00` | 
| `south` | `1` | `64.00` | 
| `west` | `2` | `93.75` | 

### Differences from Athena engine version 3
<a name="athena-duckdb-statement-dml-partitioned-hive-differences-from-engine-version-3"></a>

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
<a name="athena-duckdb-statement-dml-iceberg-insert"></a>

`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](duckdb-statement-select-time-travel.md). 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
<a name="athena-duckdb-statement-dml-iceberg-insert-examples"></a>

The following SQL statement adds an order to the Iceberg table `dml_orders`.

```sql
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.

```sql
SELECT * FROM sales_db.dml_orders ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | region | amount | order\_date | 
| --- | --- | --- | --- | --- | 
| `1` | `alice` | `east` | `120.50` | `2026-10-01` | 
| `2` | `bob` | `west` | `75.00` | `2026-10-01` | 
| `3` | `carol` | `east` | `42.25` | `2026-10-02` | 
| `4` | `dave` | `north` | `310.00` | `2026-10-03` | 

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.

```sql
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 | 
| --- | --- | --- | 
| `1` | `append` | `3` | 
| `2` | `append` | `1` | 

### Considerations
<a name="athena-duckdb-statement-dml-iceberg-insert-considerations"></a>

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
<a name="athena-duckdb-statement-dml-update"></a>

`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
<a name="athena-duckdb-statement-dml-update-syntax"></a>

```sql
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
<a name="athena-duckdb-statement-dml-update-examples"></a>

The following SQL statement sets the amount of order 2 to USD 80.00.

```sql
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.

```sql
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.

```sql
SELECT * FROM sales_db.dml_orders ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | region | amount | order\_date | 
| --- | --- | --- | --- | --- | 
| `1` | `alice` | `east` | `125.50` | `2026-10-05` | 
| `2` | `bob` | `west` | `80.00` | `2026-10-01` | 
| `3` | `carol` | `east` | `47.25` | `2026-10-05` | 
| `4` | `dave` | `north` | `310.00` | `2026-10-03` | 

### Considerations
<a name="athena-duckdb-statement-dml-update-considerations"></a>

`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`](duckdb-statement-create-table.md#athena-duckdb-statement-create-table-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
<a name="athena-duckdb-statement-dml-delete"></a>

`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
<a name="athena-duckdb-statement-dml-delete-syntax"></a>

```sql
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
<a name="athena-duckdb-statement-dml-delete-examples"></a>

The following SQL statement removes order 3.

```sql
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.

```sql
SELECT * FROM sales_db.dml_orders ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | region | amount | order\_date | 
| --- | --- | --- | --- | --- | 
| `1` | `alice` | `east` | `125.50` | `2026-10-05` | 
| `2` | `bob` | `west` | `80.00` | `2026-10-01` | 
| `4` | `dave` | `north` | `310.00` | `2026-10-03` | 

### Considerations
<a name="athena-duckdb-statement-dml-delete-considerations"></a>

`DELETE` works only on Iceberg tables. On a Hive table, the statement fails.