

# SQL reference

DuckDB queries use the SQL dialect used by DuckDB. The topics in this section describe the statements, data types, expressions, functions and operators, and table and file formats that you can use. Each example shows the result that DuckDB returns, or the error message when the statement fails. Where DuckDB works differently from Athena engine version 3, each topic describes the difference.

Along with standard SQL, you can use the SQL additions of open-source DuckDB, such as FROM-first queries, `GROUP BY ALL`, `QUALIFY`, `ASOF` joins, and `PIVOT`. For these features, see [SELECT statement in DuckDB](duckdb-statement-select.md). For lambda functions, `TRY`, `TRY_CAST`, the `::` operator, and list and struct values, see [Expressions and operators in DuckDB](duckdb-expressions.md). For map values, see [`MAP` type](duckdb-data-types.md#athena-duckdb-data-types-map). For the `FILTER` clause of an aggregate function, see [Aggregate function clauses](duckdb-functions-aggregate-general.md#athena-duckdb-functions-aggregate-aggregate-clauses). For `SUMMARIZE`, see [DESCRIBE, SHOW, SUMMARIZE, and EXPLAIN statements in DuckDB](duckdb-statement-describe-show.md).

For information about how DuckDB runs each query, see [How queries run](#athena-duckdb-sql-how-queries-run). For information about how to name catalogs, databases, and tables, see [Work with the AWS Glue Data Catalog](duckdb-glue-catalog.md). For a walkthrough that creates, loads, and queries tables, see [Tutorial: create, load, and query tables](#athena-duckdb-sql-tutorial-create-load-and-query-tables). For information about how to move queries from Athena engine version 3, see [SQL differences from Athena v3](duckdb-functions-and-schemas.md).

**Topics**
+ [How queries run](#athena-duckdb-sql-how-queries-run)
+ [Statement families](#athena-duckdb-sql-statement-families)
+ [Data types that each table format can store](#athena-duckdb-sql-data-types)
+ [Tutorial: create, load, and query tables](#athena-duckdb-sql-tutorial-create-load-and-query-tables)
+ [Considerations and limitations](#athena-duckdb-sql-considerations-and-limitations)
+ [Data types](duckdb-data-types.md)
+ [Expressions](duckdb-expressions.md)
+ [SELECT](duckdb-statement-select.md)
+ [INSERT, UPDATE, DELETE](duckdb-statement-dml.md)
+ [Functions and operators](duckdb-functions.md)
+ [CREATE TABLE](duckdb-statement-create-table.md)
+ [ALTER TABLE, DROP TABLE](duckdb-statement-alter-drop-table.md)
+ [DESCRIBE, SHOW, SUMMARIZE, EXPLAIN](duckdb-statement-describe-show.md)
+ [Data formats](duckdb-data-formats.md)
+ [SQL differences from Athena v3](duckdb-functions-and-schemas.md)

## How queries run
<a name="athena-duckdb-sql-how-queries-run"></a>

 Each query is a single SQL statement. A request with more than one statement fails. Each query runs on isolated serverless capacity used for that query only, so nothing carries over from one query to the next. Because of this, session statements such as `SET`, `USE`, `ATTACH`, `INSTALL`, `LOAD`, `PREPARE`, `BEGIN`, and `CREATE MACRO` are not supported or have no lasting effect. Athena checks each statement before DuckDB runs it, when the query runs rather than when you submit it. 

 `StartQueryExecution` accepts a query that has a syntax error and returns a query execution ID; the error appears when the query runs. The one exception is a multi-statement request, which fails at submission. 

 You cannot change DuckDB settings such as the memory limit, the number of threads, or the session time zone, which is UTC. Without an ORDER BY clause, the order of rows in a result is not guaranteed. 

## Statement families
<a name="athena-duckdb-sql-statement-families"></a>

The following topics describe the statements that DuckDB supports, with examples:
+ [SELECT statement in DuckDB](duckdb-statement-select.md) describes queries.
+ [INSERT, UPDATE, and DELETE statements in DuckDB](duckdb-statement-dml.md) describes how to add, change, and remove rows.
+ [CREATE TABLE and CREATE TABLE AS statements in DuckDB](duckdb-statement-create-table.md) describes how to create tables.
+ [ALTER TABLE and DROP TABLE statements in DuckDB](duckdb-statement-alter-drop-table.md) describes how to change and drop tables.
+ [DESCRIBE, SHOW, SUMMARIZE, and EXPLAIN statements in DuckDB](duckdb-statement-describe-show.md) describes how to look at tables and queries, including with `SUMMARIZE` and `EXPLAIN`.

For information about how to create and drop databases, which statements each table type supports, and how to write query results to Amazon S3 with `COPY (SELECT ...) TO`, see [Work with the AWS Glue Data Catalog](duckdb-glue-catalog.md). For information about views, see [Work with views](duckdb-views.md).

For information about which DuckDB statement to use in place of an Athena engine version 3 statement, see [Statement mapping](duckdb-functions-and-schemas.md#athena-duckdb-upgrading-statement-mapping). That section also lists the engine version 3 statements that have no replacement.

For the open-source DuckDB statements that you cannot use, such as `SET`, `USE`, `ATTACH`, transactions, and `CREATE MACRO`, see [Open-source DuckDB functions and features not available in Athena](duckdb-functions.md#athena-duckdb-functions-not-available). You also cannot use `LOAD DATA`.

## Data types that each table format can store
<a name="athena-duckdb-sql-data-types"></a>

 For the data types that you can use in queries, see [Data types in DuckDB](duckdb-data-types.md). The types that a table can store depend on its table format: 
+  **Hive tables** cannot store `HUGEINT`, `UBIGINT`, `INTERVAL`, `ENUM`, `BIT`, or `UNION` values. Because `sum` of an integer column returns a `HUGEINT`, cast the result, for example `CAST(sum(x) AS BIGINT)`. 
+  **Iceberg tables** cannot store `UBIGINT`, `UHUGEINT`, `BIGNUM`, `BIT`, `INTERVAL`, `JSON`, `TUPLE`, `UNION`, or fixed-size `ARRAY` values. DuckDB widens `TINYINT`, `SMALLINT`, `UTINYINT`, `USMALLINT`, and `UINTEGER` to `INTEGER` or `BIGINT`, and `HUGEINT` to `DECIMAL(38, 0)`. A `GEOMETRY` or `VARIANT` column needs format version 3. 

 To write a column of a type that the table cannot store, cast it in the query, for example `CAST(n AS BIGINT) AS n`. For more information, see [`CREATE TABLE AS`](duckdb-statement-create-table.md#athena-duckdb-statement-create-table-create-table-as) and [Column types](duckdb-statement-create-table.md#athena-duckdb-statement-create-table-column-types). 

## Tutorial: create, load, and query tables
<a name="athena-duckdb-sql-tutorial-create-load-and-query-tables"></a>

 This tutorial creates a database, creates Hive and Apache Iceberg tables in the AWS Glue Data Catalog, loads and changes data, and cleans up. Run each statement as its own query, with the catalog set to `AwsDataCatalog`. Replace `amzn-s3-demo-bucket` with your own bucket. This tutorial creates resources that can incur charges, so complete Step 6 to avoid incurring additional charges. 

 **Step 1: Create a database.** In DuckDB, a database is a schema. 

```sql
CREATE SCHEMA duckdb_tutorial
```

 **Step 2: Create a Hive table and add rows.** Every `CREATE TABLE` takes its storage settings in a `WITH` clause. `type` is required, and `location` is required outside S3 Tables. 

```sql
CREATE TABLE duckdb_tutorial.sales_parquet (
    order_id INTEGER,
    customer VARCHAR,
    region VARCHAR,
    amount DECIMAL(10,2),
    order_date DATE
)
WITH (
    type = 'HIVE',
    format = 'parquet',
    location = 's3://amzn-s3-demo-bucket/duckdb-tutorial/sales_parquet/'
)
INSERT INTO duckdb_tutorial.sales_parquet VALUES
    (1, 'alice', 'east', 120.50, DATE '2026-10-01'),
    (2, 'bob', 'west', 75.00, DATE '2026-10-01'),
    (3, 'carol', 'east', 42.25, DATE '2026-10-02')
```

 `INSERT INTO` is the only statement that adds rows to an existing Hive table. To change rows, use an Iceberg table, see Step 4. 

 **Step 3: Create a Hive table from a query (CTAS).** A CTAS takes the same `WITH` options as `CREATE TABLE`. 

```sql
CREATE TABLE duckdb_tutorial.sales_by_region
WITH (
    type = 'HIVE',
    format = 'parquet',
    location = 's3://amzn-s3-demo-bucket/duckdb-tutorial/sales_by_region/'
)
AS SELECT region, count(*) AS order_count, sum(amount) AS revenue
FROM duckdb_tutorial.sales_parquet
GROUP BY region
```

 **Step 4: Create an Iceberg table and change rows.** Iceberg tables support row-level changes. 

```sql
CREATE TABLE duckdb_tutorial.orders (
    order_id INTEGER,
    customer VARCHAR,
    region VARCHAR,
    amount DECIMAL(10,2),
    order_date DATE
)
WITH (
    type = 'ICEBERG',
    location = 's3://amzn-s3-demo-bucket/duckdb-tutorial/orders/',
    'format-version' = '2'
)
INSERT INTO duckdb_tutorial.orders
SELECT order_id, customer, region, amount, order_date
FROM duckdb_tutorial.sales_parquet
UPDATE duckdb_tutorial.orders SET amount = 80.00 WHERE order_id = 2
DELETE FROM duckdb_tutorial.orders WHERE order_id = 3
```

 `UPDATE` and `DELETE` work on Iceberg tables in the AWS Glue Data Catalog, not on Hive tables. `MERGE INTO` is not supported in this Preview. 

 **Step 5: Export query results with** `COPY TO` **.** Use `COPY (SELECT ...) TO` in place of engine version 3 `UNLOAD`. 

```sql
COPY (
    SELECT region, order_count, revenue
    FROM duckdb_tutorial.sales_by_region
    ORDER BY region
) TO 's3://amzn-s3-demo-bucket/duckdb-tutorial/export/by_region.parquet' (FORMAT parquet)
```

 **Step 6: Clean up.** To avoid incurring additional charges, delete the resources that you created in this tutorial. `DROP TABLE` on a Hive or Iceberg table in the AWS Glue Data Catalog removes only the catalog entry; the data files stay in Amazon S3. 

```sql
DROP TABLE duckdb_tutorial.sales_by_region
DROP SCHEMA duckdb_tutorial CASCADE
```

 Then delete the data in Amazon S3 yourself. 

```bash
aws s3 rm s3://amzn-s3-demo-bucket/duckdb-tutorial/ --recursive
```

## Considerations and limitations
<a name="athena-duckdb-sql-considerations-and-limitations"></a>
+  Each query must contain exactly one SQL statement, and nothing carries over between queries. 
+  You cannot change engine settings, including the session time zone, which is UTC. 
+  A syntax error appears when the query runs, not when you submit it. 
+  Without `ORDER BY`, the order of result rows is not guaranteed. 
+  You cannot create bucketed, Delta Lake, Hudi, or ORC tables. 
+  `DROP TABLE` keeps the data in Amazon S3 for Hive and Iceberg tables in the AWS Glue Data Catalog, and deletes it for S3 Tables. 
+  A write that fails with a transient-error message may already have been applied. Check before you retry it. 
+  All catalogs that you query must be in your own account. Cross-account access is not supported in this Preview. 