

# Work with the AWS Glue Data Catalog

With Athena, powered by DuckDB, you can use the AWS Glue Data Catalog as your metastore. DuckDB stores the databases and tables that you create in the AWS Glue Data Catalog. It can also query the databases and tables that are already in your catalog. These include tables that Athena engine version 3, AWS Glue crawlers, or other engines created. Your data stays in Amazon Simple Storage Service (Amazon S3) or in Amazon S3 table buckets.

This topic gives an overview of how to work with catalog objects. For more information about the syntax of each statement, see the statement topics in [SQL reference](duckdb-sql-reference.md).

The examples in this topic use a database named `sales_db` and files under `s3://amzn-s3-demo-bucket/`. To run the examples, replace these names with your own database and Amazon S3 location.

## Catalogs, databases, and table names
<a name="athena-duckdb-glue-catalog-catalogs-databases-and-table-names"></a>

The following table lists the catalogs that DuckDB can query in your account and Region.


| Catalog | Name in a query | Contains | 
| --- | --- | --- | 
| AWS Glue Data Catalog | AwsDataCatalog (default) | Hive tables and Apache Iceberg tables | 
| Amazon S3 Tables | "s3tablescatalog/<table-bucket>" | Iceberg tables in a table bucket. Each namespace is a database. | 

In DuckDB, a database is called a *schema*. Use `CREATE SCHEMA`, `DROP SCHEMA`, and `SHOW SCHEMAS` in place of `CREATE DATABASE`, `DROP DATABASE`, and `SHOW DATABASES`. A schema is the same AWS Glue database that Athena engine version 3 shows.

A query can refer to a table with a one-part, two-part, or three-part name. Athena fills in the missing parts from the query execution context. If the context does not set a catalog, Athena uses `AwsDataCatalog`. If the context does not set a database, Athena uses `default`. The following table shows how Athena reads each form of name.


| Name you write | Table it refers to | 
| --- | --- | 
| orders | orders in the context database of the context catalog | 
| sales\_db.orders | orders in the sales\_db database of the context catalog | 
| awsdatacatalog.sales\_db.orders | orders in the sales\_db database of the AWS Glue Data Catalog | 

When you write table names, follow these rules:
+ Athena always reads a two-part name as `database.table`.
+ Quote an identifier with double quotes when it contains special characters, such as `"my-db"."my-table"`.
+ Because the name of an S3 Tables catalog contains a slash, enclose it in double quotes, such as `"s3tablescatalog/amzn-s3-demo-table-bucket".tutorial_ns.daily_orders`. You can also set the catalog in the query execution context.
+ A query cannot change its default catalog or database. Each query is one statement, and `USE` is not supported. To set the defaults, use the query execution context, such as `--query-execution-context Catalog=AwsDataCatalog,Database=sales_db`.

## Table types and supported operations
<a name="athena-duckdb-glue-catalog-table-types-and-supported-operations"></a>

The following table summarizes which operations each table type supports in this Preview.


| Operation | Hive tables | Iceberg tables (AWS Glue) | S3 Tables | 
| --- | --- | --- | --- | 
| SELECT | Yes | Yes | Yes | 
| CREATE TABLE, CREATE TABLE AS SELECT (CTAS) | Yes | Yes | Yes, without location | 
| INSERT INTO | Yes | Yes | Yes | 
| UPDATE, DELETE | No | Yes | Yes | 
| MERGE INTO | Not applicable | No | No | 
| TRUNCATE | No | Yes | No | 
| ALTER TABLE columns | ADD, DROP, widening | ADD, DROP, RENAME, widening | ADD, DROP, RENAME, widening | 
| Add, drop, and rename partitions | Yes | No | No | 
| Create a partitioned table | Yes | Yes | Yes | 
| DESCRIBE, SHOW TABLES, EXPLAIN | Yes | Yes | Yes | 
| Time travel | Not applicable | Yes, excluding branches and tags | Yes | 
| CREATE VIEW over the table | Yes | No | No | 
| Table maintenance (OPTIMIZE, VACUUM) | Not applicable | No | No | 

DuckDB does not support Delta Lake, Apache Hudi, or bucketed tables, and it cannot create ORC tables. For more information about the table formats, SerDes, and compression codecs that DuckDB reads and writes, see [Table formats, file formats, and SerDes in DuckDB](duckdb-data-formats.md).

## Create databases and tables
<a name="athena-duckdb-glue-catalog-create-databases-and-tables"></a>

Run each statement as its own query.

### Create a database
<a name="athena-duckdb-glue-catalog-create-a-database"></a>

Specify database metadata in a `WITH (key = value [, ...])` clause, in place of the Athena engine version 3 `COMMENT` and `LOCATION` clauses. The `comment` key sets the AWS Glue database description, and the `location` key sets its location URI. The following SQL statement creates a database named `sales_db`.

```sql
CREATE SCHEMA sales_db
WITH (comment = 'Sales data', location = 's3://amzn-s3-demo-bucket/sales/')
```

To delete a database and its tables from the catalog, use `DROP SCHEMA sales_db CASCADE`. The data files stay in Amazon S3. `DROP SCHEMA` without `CASCADE` fails if the database has tables.

### Create a table
<a name="athena-duckdb-glue-catalog-create-a-table"></a>

Every `CREATE TABLE` statement takes its storage settings in a `WITH` clause. The `type` property is required, and `location` is required outside S3 Tables. The following SQL statement creates a Hive table in Parquet format.

```sql
CREATE TABLE sales_db.orders_parquet (
    order_id   INTEGER,
    customer   VARCHAR,
    amount     DECIMAL(10,2),
    order_date DATE,
    region     VARCHAR
)
WITH (
    type = 'HIVE',
    format = 'parquet',
    location = 's3://amzn-s3-demo-bucket/sales/orders_parquet/'
)
```

The following SQL statement creates an Iceberg table.

```sql
CREATE TABLE sales_db.orders (
    order_id   INTEGER,
    customer   VARCHAR,
    amount     DECIMAL(10,2),
    order_date DATE
)
WITH (
    type = 'ICEBERG',
    location = 's3://amzn-s3-demo-bucket/sales/orders/',
    'format-version' = '2'
)
```

A CTAS statement takes the same `WITH` properties. For more information about table properties, CSV and JSON options, and CTAS, see [CREATE TABLE and CREATE TABLE AS statements in DuckDB](duckdb-statement-create-table.md).

### Drop a table
<a name="athena-duckdb-glue-catalog-drop-a-table"></a>

`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, so make sure that you delete them, such as with `aws s3 rm s3://amzn-s3-demo-bucket/sales/orders/ --recursive`. `DROP TABLE` on an S3 Tables table deletes its data.

## Work with partitions
<a name="athena-duckdb-glue-catalog-work-with-partitions"></a>

To partition a Hive table, list the partition columns in the column list, and name them again, without types, in `PARTITIONED BY`. Put `PARTITIONED BY` before `WITH`. A CTAS statement can also create a partitioned table. The following SQL statement creates a Hive table that is partitioned by `order_date`.

```sql
CREATE TABLE sales_db.orders_by_day (
    order_id   INTEGER,
    customer   VARCHAR,
    amount     DECIMAL(10,2),
    order_date DATE
)
PARTITIONED BY (order_date)
WITH (
    type = 'HIVE',
    format = 'parquet',
    location = 's3://amzn-s3-demo-bucket/sales/orders_by_day/'
)
```

`INSERT INTO` writes each row to its partition and registers new partitions in the AWS Glue Data Catalog. To register partitions for data that another process wrote to Amazon S3, use `ALTER TABLE ... ADD PARTITION` or the `glue_repair_table` function. The following SQL statement registers one partition.

```sql
ALTER TABLE sales_db.orders_by_day
ADD PARTITION (order_date = DATE '2026-10-01')
```

`MSCK REPAIR TABLE` is not supported. In its place, call `glue_repair_table`. It registers each `key=value` directory under the table location that is not yet a registered partition, and it returns one row for each partition that it registers. The following SQL statement registers the partition directories under the table location.

```sql
CALL glue_repair_table('sales_db.orders_by_day')
```

To also find registered partitions whose location under the table location holds no files, add `missing := true`. The result then has a `status` column, which is `added` for a partition that the call registers and `missing` for a partition without files. The function does not remove the missing partitions.

To list partitions in place of `SHOW PARTITIONS`, query the `glue_partitions` table function.

```sql
SELECT *
FROM glue_partitions('awsdatacatalog.sales_db.orders_by_day')
```

DuckDB cannot read tables that use partition projection. To query such a table, set `projection.enabled` to `false` and register its partitions in the AWS Glue Data Catalog.

To partition an Iceberg table, use `PARTITIONED BY` with columns or with the transforms `year`, `month`, `day`, `hour`, `bucket`, and `truncate`, such as `PARTITIONED BY (day(order_ts))`. You cannot add, drop, or rename the partitions of an Iceberg table.

For more information, see the following topics:
+ [Partition a Hive table](duckdb-statement-create-table.md#athena-duckdb-statement-create-table-partitioned-hive-tables)
+ [Partition an Iceberg table](duckdb-statement-create-table.md#athena-duckdb-statement-create-table-iceberg-partitioning)
+ [`ADD PARTITION`](duckdb-statement-alter-drop-table.md#athena-duckdb-statement-alter-drop-table-add-partition)
+ [`glue_partitions` function](duckdb-functions-glue.md#athena-duckdb-functions-glue-glue-partitions)
+ [`glue_repair_table` function](duckdb-functions-glue.md#athena-duckdb-functions-glue-glue-repair-table)

## Work with Apache Iceberg tables
<a name="athena-duckdb-glue-catalog-work-with-apache-iceberg-tables"></a>

DuckDB reads and writes the Apache Iceberg tables in your AWS Glue Data Catalog. Keep the following in mind when you work with Iceberg tables:
+ DuckDB reads format version 1, and it reads and writes format versions 2 and 3. Athena engine version 3 cannot read format version 3 tables, and you cannot downgrade a table. Keep tables that Athena engine version 3 reads at format version 2.
+ Data files must be Parquet. DuckDB writes Parquet even if `write.format.default` is set to `orc` or `avro`.
+ You can change rows with `UPDATE` and `DELETE`. `UPDATE` fails on a table whose `write.update.mode` property is `copy-on-write`. To update the table, first run `ALTER TABLE sales_db.orders SET ('write.update.mode' = 'merge-on-read')`.
+ `MERGE INTO` is not supported in this Preview.
+ To read an earlier snapshot, add an `AT (VERSION => snapshot_id)` or `AT (TIMESTAMP => timestamp)` clause. Branches and tags are not supported. To list snapshot IDs, use the `iceberg_snapshots` function.

For more information, see the following topics:
+ [`UPDATE` statement](duckdb-statement-dml.md#athena-duckdb-statement-dml-update)
+ [`DELETE` statement](duckdb-statement-dml.md#athena-duckdb-statement-dml-delete)
+ [Time travel queries on Iceberg tables](duckdb-statement-select-time-travel.md)
+ [Iceberg functions in DuckDB](duckdb-functions-iceberg.md)

## Work with Amazon S3 Tables
<a name="athena-duckdb-glue-catalog-work-with-amazon-s3-tables"></a>

Each table bucket appears as a catalog named `s3tablescatalog/<table-bucket>`, and each namespace is a database. The following SQL query reads a table in a table bucket.

```sql
SELECT *
FROM "s3tablescatalog/amzn-s3-demo-table-bucket".tutorial_ns.daily_orders
LIMIT 10
```

Keep the following in mind when you work with S3 Tables:
+ Reads, `CREATE TABLE`, CTAS, `INSERT`, `UPDATE`, and `DELETE` are supported in this Preview. `MERGE INTO` and `TRUNCATE` are not.
+ When you create a table in a table bucket, omit `location`.
+ `DROP TABLE` deletes the table's data.
+ Integrate your table buckets with AWS analytics services by using IAM access control. IAM access control is the default. If the integration uses AWS Lake Formation access control, statements on the tables fail. For more information, see [Security and permissions](duckdb-permissions.md).

## Inspect databases and tables
<a name="athena-duckdb-glue-catalog-inspect-databases-and-tables"></a>

The following table lists the statements and functions that show catalog metadata.


| To see | Use | 
| --- | --- | 
| Databases | SHOW SCHEMAS, or the duckdb\_schemas() function | 
| Tables in a database | SHOW TABLES FROM sales\_db, or the duckdb\_tables() function | 
| Columns and data types | DESCRIBE sales\_db.orders | 
| Databases, tables, and columns as views | The information\_schema views schemata, tables, and columns | 
| Table location, SerDe, parameters, and partition keys | The glue\_get\_table\_response function | 
| Hive partitions | The glue\_partitions function | 
| Location, SerDe, and parameters of one Hive partition | The glue\_get\_partition\_response function | 
| Iceberg table properties | The iceberg\_table\_properties function | 
| Iceberg snapshots | The iceberg\_snapshots function | 
| Iceberg partition specs | The iceberg\_partition\_specs function | 

The following SQL query reads the AWS Glue metadata of a Hive table.

```sql
SELECT * EXCLUDE (response)
FROM glue_get_table_response('awsdatacatalog.sales_db.orders_parquet')
```

`SHOW CREATE TABLE`, `SHOW COLUMNS`, `SHOW PARTITIONS`, `SHOW TBLPROPERTIES`, `DESCRIBE EXTENDED`, and `DESCRIBE FORMATTED` are not supported. In place of `DESCRIBE FORMATTED ... PARTITION (...)`, use `glue_get_partition_response`, such as `glue_get_partition_response('sales_db.orders_by_day', {order_date: DATE '2026-10-01'})`. For more information, see [DESCRIBE, SHOW, SUMMARIZE, and EXPLAIN statements in DuckDB](duckdb-statement-describe-show.md) and [AWS Glue Data Catalog functions in DuckDB](duckdb-functions-glue.md).

## Read and write files by Amazon S3 path
<a name="athena-duckdb-glue-catalog-read-and-write-files-by-amazon-s3-path"></a>

DuckDB can read files in Amazon S3 without a table in the catalog, and it can write query results to Amazon S3 with `COPY (SELECT ...) TO`. Use `COPY (SELECT ...) TO` in place of the Athena engine version 3 `UNLOAD` statement. The following SQL query reads Parquet files directly.

```sql
SELECT *
FROM read_parquet('s3://amzn-s3-demo-bucket/raw/events/*.parquet')
```

The following SQL statement writes a query result to a Parquet file.

```sql
COPY (
    SELECT region, sum(amount) AS revenue
    FROM sales_db.orders_parquet
    GROUP BY region
) TO 's3://amzn-s3-demo-bucket/exports/revenue.parquet' (FORMAT parquet)
```

**Important**  
Reads and writes by Amazon S3 path do not go through the AWS Glue Data Catalog. Table permissions in AWS Glue or AWS Lake Formation do not limit them. Only the IAM permissions of the principal that runs the query for Amazon S3 limit them. This is true even if your policies allow Amazon S3 access only for requests that Athena makes. This includes policies that use the `aws:CalledVia` condition key. For more information, see [Security and permissions](duckdb-permissions.md).

For more information about the file reading functions and their options, see [Read files directly from Amazon S3](duckdb-data-formats.md#athena-duckdb-data-formats-direct-reads).

## Share tables with Athena engine version 3 and other engines
<a name="athena-duckdb-glue-catalog-share-tables-with-athena-engine-version-3-and-other-engines"></a>

Both engines use the AWS Glue Data Catalog, so a table that one engine creates is visible to the other. For tables that more than one engine reads, follow these rules:
+ Use Parquet for Hive tables.
+ Keep Iceberg tables at format version 2.
+ Do not use `TIMESTAMP WITH TIME ZONE`, `TIME`, `UUID`, or `VARIANT` columns in Hive tables.
+ Do not set `write.format.default` to `orc` or `avro` on an Iceberg table.
+ Query a view from the engine that created it.

For more information, see [Sharing tables with engine version 3 and other engines](duckdb-functions-and-schemas.md#athena-duckdb-upgrading-sharing-tables-with-engine-version-3-and-other-engines).

## Differences from Athena engine version 3
<a name="athena-duckdb-glue-catalog-differences-from-athena-engine-version-3"></a>

The following table lists the catalog differences between Athena engine version 3 and DuckDB.


| Area | Athena engine version 3 | DuckDB | 
| --- | --- | --- | 
| Create, drop, and list databases | CREATE DATABASE, DROP DATABASE, SHOW DATABASES | CREATE SCHEMA, DROP SCHEMA, SHOW SCHEMAS | 
| Database metadata | COMMENT, LOCATION, WITH DBPROPERTIES | WITH (key = value, ...) | 
| Create a Hive table | CREATE EXTERNAL TABLE ... ROW FORMAT ... STORED AS ... LOCATION ... TBLPROPERTIES | CREATE TABLE ... WITH (type = 'HIVE', format = ..., location = ...) | 
| Partition columns | Declared with types in PARTITIONED BY only | Listed in the column list, and named without types in PARTITIONED BY | 
| Register partitions | MSCK REPAIR TABLE, ALTER TABLE ADD PARTITION | CALL glue\_repair\_table(...), ALTER TABLE ADD PARTITION | 
| List partitions | SHOW PARTITIONS | glue\_partitions(...) | 
| Table details | SHOW CREATE TABLE, DESCRIBE FORMATTED, SHOW TBLPROPERTIES | DESCRIBE, glue\_get\_table\_response(...), glue\_get\_partition\_response(...), iceberg\_table\_properties(...) | 
| Set the default database | Query execution context | Query execution context (USE is not supported) | 
| Export results | UNLOAD | COPY (SELECT ...) TO | 
| Read files without a table | Not supported | read\_parquet, read\_csv, read\_json | 
| DROP TABLE on an Iceberg table | Deletes data and metadata files | Leaves data and metadata files in Amazon S3 | 
| Table formats | Hive, Iceberg, Delta Lake, Hudi | Hive, Iceberg, S3 Tables | 
| MERGE INTO on Iceberg | Supported | No | 
| OPTIMIZE, VACUUM | Supported | No | 
| Views over Iceberg tables | Supported | No | 
| Cross-account catalogs and Lake Formation | Supported | No | 
| Federated catalogs | Supported | No | 

## Considerations and limitations
<a name="athena-duckdb-glue-catalog-considerations-and-limitations"></a>

Keep the following in mind when you work with the AWS Glue Data Catalog:
+ All catalogs that you query must be in your own account. This Preview does not support cross-account catalogs or AWS Lake Formation resource links.
+ DuckDB queries the AWS Glue Data Catalog in the workgroup's Region. It cannot read Amazon S3 buckets in other Regions.
+ This Preview does not support tables in Amazon S3 locations that are registered with AWS Lake Formation. This includes tables that grant permissions to `IAMAllowedPrincipals`. Statements on these tables fail with an error that contains "is registered with Lake Formation."
+ This Preview does not support federated catalogs (data source connectors).
+ You cannot create bucketed, Delta Lake, Hudi, or ORC tables.
+ Data that DuckDB writes to Amazon S3 uses the default encryption of the bucket. DuckDB does not apply workgroup encryption settings or the `encryption_option` and `kms_key` table properties.
+ DuckDB cannot read tables that use client-side encryption with AWS KMS (CSE-KMS).
+ A write that fails with a transient-error message may already have been applied. Check before you retry it. For more information, see [Troubleshooting](duckdb-troubleshooting.md).