

# AWS Glue Data Catalog functions in DuckDB

Use the AWS Glue Data Catalog functions to read the definitions of the tables and partitions that your queries read. You can also use them to register and change the partitions of Hive tables, and to change the location or the columns of a Hive table.

Functions that change the AWS Glue Data Catalog take effect as soon as they run, and a later failure does not roll them back. Run each one as a query of its own with `CALL`, for example `CALL glue_add_partition('sales_db.orders', {dt: '2026-10-03'})`. Replace `sales_db.orders` with your own table name and `'2026-10-03'` with your own partition value. These functions change metadata only. They do not create, move, or delete data files in Amazon S3.

Name a table as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. When you leave out the catalog or the database, DuckDB fills it in from the query execution context, as it does for table names in a query.

This topic shows the functions that read the AWS Glue Data Catalog first, and then the functions that change it, in the order in which their examples ran. The examples change the same tables, so each one starts from the state that the examples before it leave. To get the same results, run the examples in the order of this topic.

The following table lists the AWS Glue Data Catalog functions that this topic describes.


| Function | Description | 
| --- | --- | 
| [glue\_add\_partition](#athena-duckdb-functions-glue-glue-add-partition) | Registers a new partition for a Hive table. | 
| [glue\_alter\_table](#athena-duckdb-functions-glue-glue-alter-table) | Applies a list of partition and location changes to a Hive table in one call. | 
| [glue\_drop\_partition](#athena-duckdb-functions-glue-glue-drop-partition) | Removes a partition from the AWS Glue definition of a Hive table and leaves its data files in Amazon S3. | 
| [glue\_get\_database\_response](#athena-duckdb-functions-glue-glue-get-database-response) | Returns the AWS Glue definition of a database. | 
| [glue\_get\_partition\_response](#athena-duckdb-functions-glue-glue-get-partition-response) | Returns the AWS Glue definition of one partition of a Hive table. | 
| [glue\_get\_table\_response](#athena-duckdb-functions-glue-glue-get-table-response) | Returns the AWS Glue definition of a table, including its location, SerDe, columns, and parameters. | 
| [glue\_partitions](#athena-duckdb-functions-glue-glue-partitions) | Lists the registered partitions of a Hive table. | 
| [glue\_rename\_partition](#athena-duckdb-functions-glue-glue-rename-partition) | Changes the values of a registered partition and keeps its location. | 
| [glue\_repair\_table](#athena-duckdb-functions-glue-glue-repair-table) | Finds the partition directories under a Hive table's location that no registered partition uses, and registers them in the AWS Glue Data Catalog. | 
| [glue\_replace\_columns](#athena-duckdb-functions-glue-glue-replace-columns) | Replaces all the data columns of a Hive table in one call. | 
| [glue\_set\_partition\_location](#athena-duckdb-functions-glue-glue-set-partition-location) | Changes the Amazon S3 location of a registered partition. | 
| [glue\_set\_table\_location](#athena-duckdb-functions-glue-glue-set-table-location) | Changes the Amazon S3 location of a Hive table. | 
| [hive\_scan](#athena-duckdb-functions-glue-hive-scan) | Reads Hive-style data files from an Amazon S3 location, with a schema and partitions that you supply instead of a catalog table. | 

## `glue_get_database_response` function
<a name="athena-duckdb-functions-glue-glue-get-database-response"></a>

Returns one row that describes a database in the AWS Glue Data Catalog: its name, description, location, and parameters, and the complete AWS Glue `Database` object in the `response` column.

If the database does not exist, the query fails.

### Syntax
<a name="athena-duckdb-functions-glue-glue-get-database-response-syntax"></a>

```sql
glue_get_database_response({{database}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-get-database-response-arguments"></a>

The `glue_get_database_response` function takes the following argument:

**{{database}}**  
The name of the database, as `{{database}}` or `{{catalog}}.{{database}}`. It must be a constant `VARCHAR` value.

### Return type
<a name="athena-duckdb-functions-glue-glue-get-database-response-return-type"></a>

A table with one row and the columns `database_name` (`VARCHAR`), `description` (`VARCHAR`), `location_uri` (`VARCHAR`), `parameters` (`MAP(VARCHAR, VARCHAR)`), and `response` (`VARIANT`).

### Examples
<a name="athena-duckdb-functions-glue-glue-get-database-response-examples"></a>

The following SQL query returns the name of a database.

```sql
SELECT database_name
FROM glue_get_database_response('sales_db')
```

The query returns the following result.


| database\_name | 
| --- | 
| `sales_db` | 

The following SQL query names the database with its catalog and checks whether the database has a description.

```sql
SELECT
    database_name,
    description IS NULL AS no_description
FROM glue_get_database_response(
    'awsdatacatalog.sales_db'
)
```

The query returns the following result.


| database\_name | no\_description | 
| --- | --- | 
| `sales_db` | `true` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-get-database-response-considerations"></a>

To read one field of the complete definition, use dot notation on `response` and cast the result, for example `CAST(response.LocationUri AS VARCHAR)`.

## `glue_get_table_response` function
<a name="athena-duckdb-functions-glue-glue-get-table-response"></a>

Returns one row that describes a table in the AWS Glue Data Catalog. The row gives the table's database and name, its table type, its location and SerDe library, its columns and partition keys, and its table and SerDe parameters. The `response` column holds the complete AWS Glue `Table` object.

Use `glue_get_table_response` on Hive tables and on other tables that are registered in the AWS Glue Data Catalog, such as Apache Iceberg tables. The `table_type` column shows how DuckDB reads the table, for example `HIVE` or `ICEBERG`, and `glue_table_type` shows the AWS Glue table type, for example `EXTERNAL_TABLE`.

### Syntax
<a name="athena-duckdb-functions-glue-glue-get-table-response-syntax"></a>

```sql
glue_get_table_response({{table}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-get-table-response-arguments"></a>

The `glue_get_table_response` function takes the following argument:

**{{table}}**  
The name of the table, as `{{table}}`, `{{database}}.{{table}}`, or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

### Return type
<a name="athena-duckdb-functions-glue-glue-get-table-response-return-type"></a>

A table with one row and the columns `database_name`, `table_name`, `table_type`, `glue_table_type`, `location`, and `serde_library` (all `VARCHAR`). The other columns are `columns` and `partition_keys` (both `STRUCT(name VARCHAR, type VARCHAR, comment VARCHAR)[]`), `parameters` and `serde_parameters` (both `MAP(VARCHAR, VARCHAR)`), and `response` (`VARIANT`).

### Examples
<a name="athena-duckdb-functions-glue-glue-get-table-response-examples"></a>

The following SQL query returns the table type and the location of a Hive table.

```sql
SELECT table_type, glue_table_type, location
FROM glue_get_table_response('sales_db.sales_parquet')
```

The query returns the following result.


| table\_type | glue\_table\_type | location | 
| --- | --- | --- | 
| `HIVE` | `EXTERNAL_TABLE` | `s3://amzn-s3-demo-bucket/tables/sales_parquet` | 

The following SQL query uses a table name that includes the catalog, `awsdatacatalog`, and returns the partition key, the classification, and the field delimiter of a partitioned CSV table.

```sql
SELECT partition_keys[1].name AS partition_key,
       parameters['classification'] AS classification,
       serde_parameters[
           'field.delim'
       ] AS field_delimiter
FROM glue_get_table_response(
    'awsdatacatalog.sales_db.sales_csv'
)
```

The query returns the following result.


| partition\_key | classification | field\_delimiter | 
| --- | --- | --- | 
| `region` | `csv` | `,` | 

The following SQL query reads the input format from the complete table definition in the `response` column.

```sql
SELECT
    CAST(
        response.StorageDescriptor.InputFormat AS VARCHAR
    ) AS input_format
FROM glue_get_table_response('sales_db.sales_parquet')
```

The query returns the following result.


| input\_format | 
| --- | 
| `org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat` | 

The following SQL query returns the table type of an Apache Iceberg table and its `table_type` parameter.

```sql
SELECT
    table_type,
    parameters['table_type'] AS table_type_parameter
FROM glue_get_table_response('sales_db.orders_iceberg')
```

The query returns the following result.


| table\_type | table\_type\_parameter | 
| --- | --- | 
| `ICEBERG` | `iceberg` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-get-table-response-considerations"></a>

The `type` field of `columns` and `partition_keys` holds the Hive type name that the AWS Glue Data Catalog stores, such as `int` or `string`, not the DuckDB type.

The order of the entries in `parameters` and `serde_parameters` is not fixed. To read one parameter, select it by key, for example `parameters['classification']`.

To read one field of the complete definition, use dot notation on `response` and cast the result, for example `CAST(response.StorageDescriptor.InputFormat AS VARCHAR)`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-glue-glue-get-table-response-differences-from-engine-version-3"></a>

Athena engine version 3 shows the details of a Hive table with `DESCRIBE EXTENDED` and `DESCRIBE FORMATTED`, which DuckDB does not support. Use `glue_get_table_response` to read the location, SerDe, parameters, and partition keys of a Hive table. The result of `glue_get_table_response` is not formatted like the Athena engine version 3 `DESCRIBE` output.

In place of the Athena engine version 3 `SHOW TBLPROPERTIES` statement, use `glue_get_table_response` for a Hive table, or `iceberg_table_properties` for an Iceberg table. For more information about `iceberg_table_properties`, see [`iceberg_table_properties` function](duckdb-functions-iceberg.md#athena-duckdb-functions-iceberg-iceberg-table-properties).

## `glue_get_partition_response` function
<a name="athena-duckdb-functions-glue-glue-get-partition-response"></a>

Returns one row that describes one partition of a partitioned Hive table. The row gives the partition's database and table, its partition values, its location and SerDe library, its columns, and its parameters and SerDe parameters. The `response` column holds the complete AWS Glue `Partition` object.

Name the partition with a `STRUCT` that has one field for each partition key of the table. If the partition does not exist, the query fails.

### Syntax
<a name="athena-duckdb-functions-glue-glue-get-partition-response-syntax"></a>

```sql
glue_get_partition_response({{table}}, {{partition}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-get-partition-response-arguments"></a>

The `glue_get_partition_response` function takes the following arguments:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

**{{partition}}**  
The partition to describe, as a constant `STRUCT` with one field for each partition key, such as `{region: 'east'}`. A field set to `NULL` names the default partition, `__HIVE_DEFAULT_PARTITION__`.

### Return type
<a name="athena-duckdb-functions-glue-glue-get-partition-response-return-type"></a>

A table with one row and the columns `database_name` and `table_name` (both `VARCHAR`), `partition_values` (`VARCHAR[]`), and `location` and `serde_library` (both `VARCHAR`). The other columns are `columns` (`STRUCT(name VARCHAR, type VARCHAR, comment VARCHAR)[]`), `parameters` and `serde_parameters` (both `MAP(VARCHAR, VARCHAR)`), and `response` (`VARIANT`).

### Examples
<a name="athena-duckdb-functions-glue-glue-get-partition-response-examples"></a>

The following SQL query returns the partition values and the location of one partition.

```sql
SELECT partition_values, location
FROM glue_get_partition_response(
    'sales_db.sales_csv', {region: 'east'}
)
```

The query returns the following result.


| partition\_values | location | 
| --- | --- | 
| `[east]` | `s3://amzn-s3-demo-bucket/tables/sales_csv/region=east` | 

The following SQL query reads the input format of a partition from the complete partition definition in the `response` column.

```sql
SELECT
    CAST(
        response.StorageDescriptor.InputFormat AS VARCHAR
    ) AS input_format
FROM glue_get_partition_response(
    'sales_db.sales_csv', {region: 'west'}
)
```

The query returns the following result.


| input\_format | 
| --- | 
| `org.apache.hadoop.mapred.TextInputFormat` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-get-partition-response-considerations"></a>

The function works only on partitioned Hive tables. The partition must name every partition key of the table and no other field.

## `glue_partitions` function
<a name="athena-duckdb-functions-glue-glue-partitions"></a>

Returns one row for each partition that is registered in the AWS Glue Data Catalog for a partitioned Hive table. The result has one column for each partition key, named after the key and typed as the key. The last two columns are `location` and `partition_values`. The `partition_values` column holds the partition values as the strings that the AWS Glue Data Catalog stores.

### Syntax
<a name="athena-duckdb-functions-glue-glue-partitions-syntax"></a>

```sql
glue_partitions({{table}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-partitions-arguments"></a>

The `glue_partitions` function takes the following argument:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

### Return type
<a name="athena-duckdb-functions-glue-glue-partitions-return-type"></a>

A table with one column for each partition key, typed as the key, then `location` (`VARCHAR`) and `partition_values` (`VARCHAR[]`).

### Examples
<a name="athena-duckdb-functions-glue-glue-partitions-examples"></a>

The following SQL query lists the partitions of a table and their locations.

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

The query returns the following results.


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

The following SQL query filters on the partition key column and returns the stored partition values.

```sql
SELECT region, partition_values
FROM glue_partitions('sales_db.sales_csv')
WHERE region <> 'east'
ORDER BY region
```

The query returns the following results.


| region | partition\_values | 
| --- | --- | 
| `north` | `[north]` | 
| `west` | `[west]` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-partitions-considerations"></a>

A partition key column is `NULL` both for the default partition, which the AWS Glue Data Catalog stores as `__HIVE_DEFAULT_PARTITION__`, and for a stored value that the key's type cannot hold. To tell the two apart, read `partition_values`, which always holds the stored strings.

If a partition key is itself named `location` or `partition_values`, the function's own column of that name gets a numeric suffix, such as `location_1`.

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

In place of the Athena engine version 3 `SHOW PARTITIONS` statement, use `SELECT * FROM glue_partitions('{{catalog}}.{{database}}.{{table}}')`.

## `hive_scan` function
<a name="athena-duckdb-functions-glue-hive-scan"></a>

Reads the data files under one Amazon S3 location the way DuckDB reads a Hive table, without looking anything up in the AWS Glue Data Catalog. You supply the columns in `schema`, and for a partitioned layout, the partitions in `partitions`.

Without `partitions`, `hive_scan` reads every data file under `location` as one unpartitioned table. With `partitions`, it reads only the partitions that you list. A partition without its own location is read from the `{{key}}={{value}}` directory under `location`.

### Syntax
<a name="athena-duckdb-functions-glue-hive-scan-syntax"></a>

```sql
hive_scan({{location}}, schema := {{columns}}
    [, format := {{format}} ]
    [, partitions := {{partition_list}} ]
    [, partition_keys := {{key_list}} ]
    [, header := {{header}} ] [, delim := {{delimiter}} ]
    [, quote := {{quote}} ] [, escape := {{escape}} ]
    [, nullstr := {{null_string}} ]
    [, ignore_errors := {{ignore_errors}} ])
```

### Arguments
<a name="athena-duckdb-functions-glue-hive-scan-arguments"></a>

The `hive_scan` function takes the following arguments:

**{{location}}**  
The root Amazon S3 location of the data, as a `VARCHAR` value, such as `'s3://amzn-s3-demo-bucket/orders/'`. Give one location, not a list.

**{{columns}}**  
The columns of the data, as a `STRUCT` that maps each column name to a type name, such as `{id: 'INTEGER', dt: 'VARCHAR'}`. List the data columns and the partition columns. This argument is required.

**{{format}}**  
The file format, as a `VARCHAR` value: `'parquet'` (the default), `'csv'`, `'json'`, or `'avro'`. This argument is optional.

**{{partition\_list}}**  
The partitions to read, as a list of `STRUCT` values, one for each partition, such as `[{dt: '2026-10-01'}, {dt: '2026-10-02'}]`. Each value has a field for each partition key and an optional `location` field. This argument is optional.

**{{key\_list}}**  
The names of the partition keys in order, as a `VARCHAR[]` list. By default, the partition keys are the fields of `partition_list` other than `location`. Use it only together with `partitions`. This argument is optional.

**{{header}}**  
The header option for CSV files, as a `BOOLEAN` value. A value of `true` means that each file starts with a header line. This argument is optional.

**{{delimiter}}**  
The field delimiter of CSV files, as a `VARCHAR` value, such as `'|'`. This argument is optional.

**{{quote}}**  
The quote character of CSV files, as a `VARCHAR` value. This argument is optional.

**{{escape}}**  
The escape character of CSV files, as a `VARCHAR` value. This argument is optional.

**{{null\_string}}**  
The string that stands for `NULL` in CSV files, as a `VARCHAR` value, such as `'\N'`. This argument is optional.

**{{ignore\_errors}}**  
The option for lines in JSON files that are not valid JSON, as a `BOOLEAN` value. When it is `true`, the function reads such a line as a row of `NULL` values. This argument is optional.

### Return type
<a name="athena-duckdb-functions-glue-hive-scan-return-type"></a>

A table with the columns that `columns` names, typed as given.

### Examples
<a name="athena-duckdb-functions-glue-hive-scan-examples"></a>

The following SQL query reads the Parquet files under one location as an unpartitioned table and counts the rows for each region.

```sql
SELECT region, count(*) AS orders
FROM hive_scan('s3://amzn-s3-demo-bucket/tables/sales_parquet/',
    schema := {
        order_id: 'INTEGER', customer: 'VARCHAR',
        region: 'VARCHAR', amount: 'DECIMAL(10,2)',
        order_date: 'DATE'
    })
GROUP BY region
ORDER BY region
```

The query returns the following results.


| region | orders | 
| --- | --- | 
| `east` | `3` | 
| `north` | `1` | 
| `west` | `2` | 

The following SQL query reads CSV files that are partitioned by `region` in `region={{value}}` directories, and adds up the amounts in each partition.

```sql
SELECT region, sum(amount) AS total
FROM hive_scan('s3://amzn-s3-demo-bucket/tables/sales_csv/',
    schema := {
        order_id: 'INTEGER', customer: 'VARCHAR',
        amount: 'DOUBLE', region: 'VARCHAR'
    },
    format := 'csv',
    partitions := [
        {region: 'east'}, {region: 'north'},
        {region: 'west'}
    ])
GROUP BY region
ORDER BY region
```

The query returns the following results.


| region | total | 
| --- | --- | 
| `east` | `162.75` | 
| `north` | `310.0` | 
| `west` | `75.0` | 

The following SQL query lists only one partition, so it reads only the files of that partition.

```sql
SELECT count(*) AS orders
FROM hive_scan('s3://amzn-s3-demo-bucket/tables/sales_csv/',
    schema := {
        order_id: 'INTEGER', customer: 'VARCHAR',
        amount: 'DOUBLE', region: 'VARCHAR'
    },
    format := 'csv',
    partitions := [{region: 'north'}])
```

The query returns the following result.


| orders | 
| --- | 
| `1` | 

The following SQL query lists a partition whose directory holds no data files, so the count is `0`.

```sql
SELECT count(*) AS orders
FROM hive_scan('s3://amzn-s3-demo-bucket/tables/sales_csv/',
    schema := {
        order_id: 'INTEGER', customer: 'VARCHAR',
        amount: 'DOUBLE', region: 'VARCHAR'
    },
    format := 'csv',
    partitions := [{region: 'south'}])
```

The query returns the following result.


| orders | 
| --- | 
| `0` | 

### Considerations
<a name="athena-duckdb-functions-glue-hive-scan-considerations"></a>

CSV columns are matched by position, and JSON and Parquet columns by name. In CSV files, an empty field is `NULL` unless `nullstr` says otherwise.

## `glue_add_partition` function
<a name="athena-duckdb-functions-glue-glue-add-partition"></a>

Registers a partition of a partitioned Hive table in the AWS Glue Data Catalog and returns the partition's location. Without `location`, the function uses a `{{key}}={{value}}` directory under the table location as the partition's location, such as `s3://amzn-s3-demo-bucket/orders/dt=2026-10-03`.

The function registers metadata only. It does not create files or directories in Amazon S3.

### Syntax
<a name="athena-duckdb-functions-glue-glue-add-partition-syntax"></a>

```sql
CALL glue_add_partition({{table}}, {{partition}}
    [, location := {{location}} ]
    [, if_not_exists := {{if_not_exists}} ])
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-add-partition-arguments"></a>

The `glue_add_partition` function takes the following arguments:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

**{{partition}}**  
The partition to register, as a constant `STRUCT` with one field for each partition key, such as `{dt: '2026-10-03'}`. A field set to `NULL` names the default partition, `__HIVE_DEFAULT_PARTITION__`.

**{{location}}**  
The Amazon S3 location of the partition's data files, as a `VARCHAR` value. The function removes a trailing slash. This argument is optional.

**{{if\_not\_exists}}**  
The option for a partition that already exists, as a `BOOLEAN` value. When `true`, the call succeeds without a change if the partition already exists. The default is `false`, which makes the call fail if the partition exists. This argument is optional.

### Return type
<a name="athena-duckdb-functions-glue-glue-add-partition-return-type"></a>

A table with one row and one column, `location` (`VARCHAR`), the location of the partition.

### Examples
<a name="athena-duckdb-functions-glue-glue-add-partition-examples"></a>

The following SQL statement registers a partition at the default location under the table location.

```sql
CALL glue_add_partition(
    'sales_db.partition_demo', {dt: '2026-10-03'}
)
```

The statement returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-03` | 

The following SQL statement registers a partition at a location that you choose. The function removes the trailing slash.

```sql
CALL glue_add_partition(
    'sales_db.partition_demo', {dt: '2026-10-04'},
    location := 's3://amzn-s3-demo-bucket/tables/partition_demo/imports/2026-10-04/'
)
```

The statement returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/partition_demo/imports/2026-10-04` | 

The following SQL statement tries to add a partition that already exists. With `if_not_exists := true`, the call succeeds and changes nothing.

```sql
CALL glue_add_partition(
    'sales_db.partition_demo', {dt: '2026-10-03'},
    if_not_exists := true
)
```

The statement returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-03` | 

The following SQL query lists the partitions of the table. The table already had the `2026-10-01` and `2026-10-02` partitions, and the previous examples added `2026-10-03` and `2026-10-04`.

```sql
SELECT dt, location
FROM glue_partitions('sales_db.partition_demo')
ORDER BY dt
```

The query returns the following results.


| dt | location | 
| --- | --- | 
| `2026-10-01` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-01` | 
| `2026-10-02` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-02` | 
| `2026-10-03` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-03` | 
| `2026-10-04` | `s3://amzn-s3-demo-bucket/tables/partition_demo/imports/2026-10-04` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-add-partition-considerations"></a>

With `if_not_exists := true` and a partition that already exists, the `location` column shows the location that the call would have registered. It is not necessarily the location of the existing partition. To read the existing location, use the [`glue_partitions` function](#athena-duckdb-functions-glue-glue-partitions).

## `glue_rename_partition` function
<a name="athena-duckdb-functions-glue-glue-rename-partition"></a>

Changes the partition values of a registered partition of a Hive table and returns the partition's location. The partition keeps its location, so its data files stay where they are, and queries read their rows with the new partition values.

If the partition does not exist, or a partition with the new values already exists, the call fails.

### Syntax
<a name="athena-duckdb-functions-glue-glue-rename-partition-syntax"></a>

```sql
CALL glue_rename_partition({{table}}, {{partition}},
    {{new_partition}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-rename-partition-arguments"></a>

The `glue_rename_partition` function takes the following arguments:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

**{{partition}}**  
The partition to change, as a constant `STRUCT` with one field for each partition key, such as `{dt: '2026-10-02'}`.

**{{new\_partition}}**  
The new partition values, as a constant `STRUCT` with one field for each partition key, such as `{dt: '2026-10-20'}`.

### Return type
<a name="athena-duckdb-functions-glue-glue-rename-partition-return-type"></a>

A table with one row and one column, `location` (`VARCHAR`), the location of the partition, which does not change.

### Examples
<a name="athena-duckdb-functions-glue-glue-rename-partition-examples"></a>

The following SQL statement changes the value of a partition. The result shows the location that the partition keeps.

```sql
CALL glue_rename_partition(
    'sales_db.partition_demo', {dt: '2026-10-02'},
    {dt: '2026-10-20'}
)
```

The statement returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-02` | 

The following SQL query shows the renamed partition and its location.

```sql
SELECT dt, location
FROM glue_partitions('sales_db.partition_demo')
WHERE dt = '2026-10-20'
```

The query returns the following result.


| dt | location | 
| --- | --- | 
| `2026-10-20` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-02` | 

The following SQL query reads the table. The row in the renamed partition now has the new partition value.

```sql
SELECT id, dt FROM sales_db.partition_demo ORDER BY id
```

The query returns the following results.


| id | dt | 
| --- | --- | 
| `1` | `2026-10-01` | 
| `2` | `2026-10-20` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-rename-partition-considerations"></a>

The location does not change to match the new values. For example, after you rename `dt=2026-10-02` to `dt=2026-10-20`, the partition still reads from the `dt=2026-10-02` directory. To change the location as well, use the [`glue_set_partition_location` function](#athena-duckdb-functions-glue-glue-set-partition-location).

## `glue_set_partition_location` function
<a name="athena-duckdb-functions-glue-glue-set-partition-location"></a>

Changes the Amazon S3 location of a registered partition of a Hive table and returns the new location. The function changes metadata only. It does not move data files, so after the change the partition reads the files at the new location.

If the partition does not exist, the call fails.

### Syntax
<a name="athena-duckdb-functions-glue-glue-set-partition-location-syntax"></a>

```sql
CALL glue_set_partition_location({{table}}, {{partition}},
    {{location}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-set-partition-location-arguments"></a>

The `glue_set_partition_location` function takes the following arguments:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

**{{partition}}**  
The partition to change, as a constant `STRUCT` with one field for each partition key, such as `{dt: '2026-10-20'}`.

**{{location}}**  
The new location, as a `VARCHAR` value. It must start with `s3://` or `s3a://` and must not be `NULL` or empty. The function removes a trailing slash.

### Return type
<a name="athena-duckdb-functions-glue-glue-set-partition-location-return-type"></a>

A table with one row and one column, `location` (`VARCHAR`), the new location of the partition.

### Examples
<a name="athena-duckdb-functions-glue-glue-set-partition-location-examples"></a>

The following SQL statement changes the location of the `2026-10-20` partition to the `dt=2026-10-20` directory, which matches its partition value.

```sql
CALL glue_set_partition_location(
    'sales_db.partition_demo', {dt: '2026-10-20'},
    's3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-20/'
)
```

The statement returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-20` | 

The following SQL query shows the partition's new location.

```sql
SELECT dt, location
FROM glue_partitions('sales_db.partition_demo')
WHERE dt = '2026-10-20'
```

The query returns the following result.


| dt | location | 
| --- | --- | 
| `2026-10-20` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-20` | 

The following SQL query counts the rows in the partition. The data file stayed at the old location, so the partition now reads as empty.

```sql
SELECT count(*) AS row_count
FROM sales_db.partition_demo
WHERE dt = '2026-10-20'
```

The query returns the following result.


| row\_count | 
| --- | 
| `0` | 

## `glue_repair_table` function
<a name="athena-duckdb-functions-glue-glue-repair-table"></a>

Lists the directories under the location of a partitioned Hive table. Then it registers in the AWS Glue Data Catalog each partition directory that is not yet the location of a registered partition. It returns one row for each partition that it registers. Without `missing := true`, if every partition is already registered, the result has no rows.

A partition directory has one `{{key}}={{value}}` path component for each partition key, in partition key order, such as `dt=2026-10-02`. The function registers the partition at that directory, with the values converted to the types of the partition keys.

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

### Syntax
<a name="athena-duckdb-functions-glue-glue-repair-table-syntax"></a>

```sql
CALL glue_repair_table({{table}} [, missing := {{missing}} ])
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-repair-table-arguments"></a>

The `glue_repair_table` function takes the following arguments:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value. The table must have a location.

**{{missing}}**  
The option to also report the registered partitions whose location holds no files, as a `BOOLEAN` value. When `true`, the result has a row for each such partition and a `status` column. The default is `false`. This argument is optional.

### Return type
<a name="athena-duckdb-functions-glue-glue-repair-table-return-type"></a>

A table with one row for each partition that the call registers, with one column for each partition key, typed as the key, and `location` (`VARCHAR`). With `missing := true`, the table also has one row for each registered partition whose location holds no files, and a last column, `status` (`VARCHAR`), that is `added` or `missing`.

### Examples
<a name="athena-duckdb-functions-glue-glue-repair-table-examples"></a>

The following SQL statement registers the `dt=2026-10-02` directory as a partition. The directory holds a data file, but no registered partition uses it. The `glue_rename_partition` examples renamed the partition that used it from `2026-10-02` to `2026-10-20`, and the `glue_set_partition_location` examples then changed the location of that partition to the `dt=2026-10-20` directory.

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

The statement returns the following result.


| dt | location | 
| --- | --- | 
| `2026-10-02` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-02` | 

The following SQL query reads the table. The row whose data file is in the `dt=2026-10-02` directory now has the partition value `2026-10-02`.

```sql
SELECT id, dt FROM sales_db.partition_demo ORDER BY id
```

The query returns the following results.


| id | dt | 
| --- | --- | 
| `1` | `2026-10-01` | 
| `2` | `2026-10-02` | 

The following SQL statement sets `missing := true` to report the registered partitions whose location holds no files. The `glue_add_partition` examples registered `2026-10-03` and `2026-10-04` at locations without files. The `glue_set_partition_location` examples moved `2026-10-20` to a directory without files. The call registers nothing and keeps all three partitions.

```sql
CALL glue_repair_table(
    'sales_db.partition_demo', missing := true
)
```

The statement returns the following results.


| dt | location | status | 
| --- | --- | --- | 
| `2026-10-03` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-03` | `missing` | 
| `2026-10-04` | `s3://amzn-s3-demo-bucket/tables/partition_demo/imports/2026-10-04` | `missing` | 
| `2026-10-20` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-20` | `missing` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-repair-table-considerations"></a>

The function skips directories that hold no data files, directories that do not follow the `{{key}}={{value}}` layout, and directories whose values cannot be converted to the key types. It also skips directories that are already the location of a partition and directories whose values are already registered as a partition at another location.

The function only adds partitions. It never removes a registered partition, even when its directory no longer exists. To find such partitions, set `missing := true`. To remove one, use the [`glue_drop_partition` function](#athena-duckdb-functions-glue-glue-drop-partition).

With `missing := true`, the function checks only the registered partitions whose location is under the table location. It does not report a partition at another location, even when that location holds no files. A location counts as holding files when any object is stored under it, even an object that is not a data file.

If a partition key is itself named `location` or `status`, the function's own column of that name gets a numeric suffix, such as `status_1`.

## `glue_alter_table` function
<a name="athena-duckdb-functions-glue-glue-alter-table"></a>

Applies a list of actions to a Hive table: add, drop, or rename partitions, set the location of a partition, and set the location of the table. The function checks every action against the AWS Glue Data Catalog before it applies any of them. If a check fails, the call changes nothing. It returns one row for each action, in the order of the list.

Each action is a `STRUCT` with an `action` field and the fields that the action uses. Unlike the other partition functions, `glue_alter_table` takes each partition as a list of `STRUCT` values with `key` and `value` fields, such as `[{key: 'dt', value: '2026-10-05'}]`.

### Syntax
<a name="athena-duckdb-functions-glue-glue-alter-table-syntax"></a>

```sql
CALL glue_alter_table({{table}}, {{actions}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-alter-table-arguments"></a>

The `glue_alter_table` function takes the following arguments:

**{{table}}**  
The name of a Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value. Unless every action is `'set_table_location'`, use a partitioned table.

**{{actions}}**  
The actions to apply, as a constant list of `STRUCT` values, one for each action. The `action` field is one of `'add'`, `'drop'`, `'rename'`, `'set_partition_location'`, or `'set_table_location'`. The `partition` field names the partition that the action changes. The `new_partition` field holds the new values for `'rename'`. The `location` field holds the Amazon S3 location for `'add'` (optional) and for the two location actions. The `BOOLEAN` fields `if_not_exists` (for `'add'`) and `if_exists` (for `'drop'`) skip the action instead of failing. A `'set_partition_location'` action on a partition that does not exist makes the call fail. Leave out the fields that an action does not use.

### Return type
<a name="athena-duckdb-functions-glue-glue-alter-table-return-type"></a>

A table with one row for each action and the columns `action`, `partition`, and `location` (all `VARCHAR`). The `action` column describes the action, such as `add partition`. The `partition` column holds the partition values, separated by commas. The `location` column holds the location that the action set, or `NULL` when the action sets no location.

### Examples
<a name="athena-duckdb-functions-glue-glue-alter-table-examples"></a>

The following SQL statement adds one partition and renames another in one call. The result has one row for each action. The rename row shows `NULL` in the `location` column, because a rename keeps the partition's location.

```sql
CALL glue_alter_table('sales_db.partition_demo', [
    {
        action: 'add',
        partition: [{key: 'dt', value: '2026-10-05'}]
    },
    {
        action: 'rename',
        partition: [{key: 'dt', value: '2026-10-03'}],
        new_partition: [
            {key: 'dt', value: '2026-10-13'}
        ]
    }
])
```

The statement returns the following results.


| action | partition | location | 
| --- | --- | --- | 
| `add partition` | `2026-10-05` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-05` | 
| `rename partition` | `2026-10-03` | `NULL` | 

The following SQL query shows the added partition and the renamed partition, which keeps its location.

```sql
SELECT dt, location
FROM glue_partitions('sales_db.partition_demo')
WHERE dt IN ('2026-10-05', '2026-10-13')
ORDER BY dt
```

The query returns the following results.


| dt | location | 
| --- | --- | 
| `2026-10-05` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-05` | 
| `2026-10-13` | `s3://amzn-s3-demo-bucket/tables/partition_demo/dt=2026-10-03` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-alter-table-considerations"></a>

The function checks all the actions before it applies any of them, but the AWS Glue Data Catalog has no transactions. If a change fails after the checks, for example because of a service error, the changes that the function already applied stay in place.

## `glue_drop_partition` function
<a name="athena-duckdb-functions-glue-glue-drop-partition"></a>

Removes a registered partition of a Hive table from the AWS Glue Data Catalog and returns whether it removed one. The partition's data files stay in Amazon S3, and queries of the table no longer read them.

If the partition does not exist, the call fails, unless you set `if_exists := true`. Then the call succeeds and returns `false`.

### Syntax
<a name="athena-duckdb-functions-glue-glue-drop-partition-syntax"></a>

```sql
CALL glue_drop_partition({{table}}, {{partition}}
    [, if_exists := {{if_exists}} ])
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-drop-partition-arguments"></a>

The `glue_drop_partition` function takes the following arguments:

**{{table}}**  
The name of a partitioned Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

**{{partition}}**  
The partition to remove, as a constant `STRUCT` with one field for each partition key, such as `{dt: '2026-10-20'}`.

**{{if\_exists}}**  
The option for a partition that does not exist, as a `BOOLEAN` value. When `true`, the call succeeds if the partition does not exist. The default is `false`. This argument is optional.

### Return type
<a name="athena-duckdb-functions-glue-glue-drop-partition-return-type"></a>

A table with one row and one column, `dropped` (`BOOLEAN`), which is `true` when the call removed the partition.

### Examples
<a name="athena-duckdb-functions-glue-glue-drop-partition-examples"></a>

The following SQL statement removes the `2026-10-20` partition.

```sql
CALL glue_drop_partition(
    'sales_db.partition_demo', {dt: '2026-10-20'}
)
```

The statement returns the following result.


| dropped | 
| --- | 
| `true` | 

The following SQL statement removes the same partition again with `if_exists := true`. The partition no longer exists, so the call returns `false` instead of failing.

```sql
CALL glue_drop_partition(
    'sales_db.partition_demo', {dt: '2026-10-20'},
    if_exists := true
)
```

The statement returns the following result.


| dropped | 
| --- | 
| `false` | 

The following SQL query lists the partitions that remain.

```sql
SELECT dt
FROM glue_partitions('sales_db.partition_demo')
ORDER BY dt
```

The query returns the following results.


| dt | 
| --- | 
| `2026-10-01` | 
| `2026-10-02` | 
| `2026-10-04` | 
| `2026-10-05` | 
| `2026-10-13` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-drop-partition-considerations"></a>

To register the partition again later, use the [`glue_add_partition` function](#athena-duckdb-functions-glue-glue-add-partition), or `glue_repair_table` when its directory follows the `{{key}}={{value}}` layout under the table location.

## `glue_set_table_location` function
<a name="athena-duckdb-functions-glue-glue-set-table-location"></a>

Changes the Amazon S3 location of a Hive table in the AWS Glue Data Catalog and returns the new location. The function changes metadata only. It does not move data files, so after the change an unpartitioned table reads the files at the new location.

Existing partitions keep their own locations. Partitions that you add later without a location go under the new table location.

### Syntax
<a name="athena-duckdb-functions-glue-glue-set-table-location-syntax"></a>

```sql
CALL glue_set_table_location({{table}}, {{location}})
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-set-table-location-arguments"></a>

The `glue_set_table_location` function takes the following arguments:

**{{table}}**  
The name of a Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value. The table can be partitioned or unpartitioned.

**{{location}}**  
The new location, as a `VARCHAR` value. It must start with `s3://` or `s3a://` and must not be `NULL` or empty. The function removes a trailing slash.

### Return type
<a name="athena-duckdb-functions-glue-glue-set-table-location-return-type"></a>

A table with one row and one column, `location` (`VARCHAR`), the new location of the table.

### Examples
<a name="athena-duckdb-functions-glue-glue-set-table-location-examples"></a>

The following SQL statement changes the location of a table.

```sql
CALL glue_set_table_location(
    'sales_db.location_demo',
    's3://amzn-s3-demo-bucket/tables/location_demo_v2/'
)
```

The statement returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/location_demo_v2` | 

The following SQL query reads the new location from the table definition.

```sql
SELECT location
FROM glue_get_table_response('sales_db.location_demo')
```

The query returns the following result.


| location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/location_demo_v2` | 

The following SQL query counts the rows of the table. The data file stayed at the old location, so the table now reads as empty.

```sql
SELECT count(*) AS row_count FROM sales_db.location_demo
```

The query returns the following result.


| row\_count | 
| --- | 
| `0` | 

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-glue-glue-set-table-location-differences-from-engine-version-3"></a>

In place of the Athena engine version 3 `ALTER TABLE {{table}} SET LOCATION` statement, use `CALL glue_set_table_location`. It works on Hive tables only.

## `glue_replace_columns` function
<a name="athena-duckdb-functions-glue-glue-replace-columns"></a>

Replaces the whole list of data columns of a Hive table in the AWS Glue Data Catalog and returns the columns as the AWS Glue Data Catalog now stores them. Use it to add, remove, reorder, rename, or widen columns in one call. The partition keys do not change.

The function changes metadata only and does not rewrite data files. DuckDB matches Parquet, JSON, and Avro columns by name. As a result, a renamed column reads as `NULL` in existing files, and a new column reads as `NULL` in files written before it. CSV columns are matched by position, so a CSV table must keep its number of columns, and a new name renames the column at that position.

The function removes the comments of columns that you do not list in `comments`, unless you set `keep_comments := true`, which keeps the comments of the columns that stay.

### Syntax
<a name="athena-duckdb-functions-glue-glue-replace-columns-syntax"></a>

```sql
CALL glue_replace_columns({{table}}, {{columns}}
    [, comments := {{comments}} ]
    [, keep_comments := {{keep_comments}} ])
```

### Arguments
<a name="athena-duckdb-functions-glue-glue-replace-columns-arguments"></a>

The `glue_replace_columns` function takes the following arguments:

**{{table}}**  
The name of a Hive table, as `{{database}}.{{table}}` or `{{catalog}}.{{database}}.{{table}}`. It must be a constant `VARCHAR` value.

**{{columns}}**  
The new data columns, as a constant `STRUCT` that maps each column name to a type name, in the new column order, such as `{id: 'BIGINT', note: 'VARCHAR'}`. Do not list the partition keys. A table with bucket or sort columns must keep them.

**{{comments}}**  
The column comments to set, as a constant `STRUCT` that maps column names to comments, such as `{id: 'order number'}`. A `NULL` comment removes the comment of that column. This argument is optional.

**{{keep\_comments}}**  
The option to keep existing comments, as a `BOOLEAN` value. When `true`, columns that stay keep their comments unless `comments` changes them. The default is `false`. This argument is optional.

### Return type
<a name="athena-duckdb-functions-glue-glue-replace-columns-return-type"></a>

A table with one row and one column, `columns` (`STRUCT(name VARCHAR, type VARCHAR, comment VARCHAR)[]`), the data columns as stored, with Hive type names such as `bigint` and `string`.

### Examples
<a name="athena-duckdb-functions-glue-glue-replace-columns-examples"></a>

The following SQL statement widens the `id` column from `INTEGER` to `BIGINT`, adds a `DATE` column named `added_on`, and sets a comment on `id`.

```sql
CALL glue_replace_columns(
    'sales_db.columns_demo',
    {id: 'BIGINT', note: 'VARCHAR', added_on: 'DATE'},
    comments := {id: 'order number'}
)
```

The statement returns the following result.


| columns | 
| --- | 
| `[{'name': id, 'type': bigint, 'comment': order number}, {'name': note, 'type': string, 'comment': NULL}, {'name': added_on, 'type': date, 'comment': NULL}]` | 

The following SQL query reads the table. The new column reads as `NULL` in the existing data file.

```sql
SELECT id, note, added_on FROM sales_db.columns_demo
```

The query returns the following result.


| id | note | added\_on | 
| --- | --- | --- | 
| `1` | `first` | `NULL` | 

The following SQL statement removes the `added_on` column, renames `note` to `memo`, and keeps the existing comment on `id`.

```sql
CALL glue_replace_columns(
    'sales_db.columns_demo',
    {id: 'BIGINT', memo: 'VARCHAR'},
    keep_comments := true
)
```

The statement returns the following result.


| columns | 
| --- | 
| `[{'name': id, 'type': bigint, 'comment': order number}, {'name': memo, 'type': string, 'comment': NULL}]` | 

The following SQL query reads the table. The table is stored as Parquet, and DuckDB matches Parquet columns by name, so the renamed column reads as `NULL`.

```sql
SELECT id, memo FROM sales_db.columns_demo
```

The query returns the following result.


| id | memo | 
| --- | --- | 
| `1` | `NULL` | 

### Considerations
<a name="athena-duckdb-functions-glue-glue-replace-columns-considerations"></a>

A column that stays can only be widened: from a smaller to a larger integer type, from `FLOAT` to `DOUBLE`, or from any type to `VARCHAR`. Other type changes make the call fail, because existing data files keep their types. In a CSV table, every column stays, matched by position. In other tables, a column stays when the new list has a column with the same name, compared without regard to case.