

# Iceberg functions in DuckDB

Use Iceberg functions to inspect the metadata of Apache Iceberg tables, such as snapshots, history, schemas, manifests, data files, column statistics, partitions, branches and tags, and properties. You can also read an Iceberg table directly from its location in Amazon S3, and you can set and remove the properties of an Iceberg table. Other functions compute the values of the Iceberg `bucket` and `truncate` partition transforms.

Call the table functions in the `FROM` clause of a query. Most metadata functions take the table name as a string literal in the form `'[catalog.database.]table'`, for example `'sales_db.orders_iceberg'`. Write the name as a literal; you cannot compute it with a subquery.

Most examples in this topic use `sales_db.orders_iceberg`, an unpartitioned Iceberg table in format version 2 with the columns `order_id`, `customer`, `region`, `amount`, and `order_date`. The table has two snapshots: the first adds two rows in one data file, and the second adds one row in another data file. Snapshot IDs, file paths, and timestamps differ for every table, so most examples select counts or a few narrow columns. The examples that set and remove properties use a second table, `sales_db.props_iceberg`, so that `orders_iceberg` stays unchanged.

The following table lists the Iceberg functions that this topic describes.


| Function | Description | 
| --- | --- | 
| [iceberg\_bucket](#athena-duckdb-functions-iceberg-iceberg-bucket) | Returns the bucket number that the Iceberg `bucket` partition transform computes for a value. | 
| [iceberg\_column\_stats](#athena-duckdb-functions-iceberg-iceberg-column-stats) | Returns the column statistics that an Iceberg table stores for each data file, one row per file and column. | 
| [iceberg\_files](#athena-duckdb-functions-iceberg-iceberg-files) | Returns one row for each data file and delete file of an Iceberg table, with the file's statistics. | 
| [iceberg\_history](#athena-duckdb-functions-iceberg-iceberg-history) | Returns the history of an Iceberg table: when each snapshot became the current snapshot. | 
| [iceberg\_manifests](#athena-duckdb-functions-iceberg-iceberg-manifests) | Returns one row for each manifest file of an Iceberg table. | 
| [iceberg\_metadata](#athena-duckdb-functions-iceberg-iceberg-metadata) | Returns one row for each manifest entry of an Iceberg table, with the file that the entry tracks. | 
| [iceberg\_partition\_specs](#athena-duckdb-functions-iceberg-iceberg-partition-specs) | Returns the partition specs of an Iceberg table, one row per partition field. | 
| [iceberg\_partition\_stats](#athena-duckdb-functions-iceberg-iceberg-partition-stats) | Returns the bounds of each partition field in each manifest of an Iceberg table. | 
| [iceberg\_partitions](#athena-duckdb-functions-iceberg-iceberg-partitions) | Returns the record, file, and delete counts for each partition of an Iceberg table. | 
| [iceberg\_refs](#athena-duckdb-functions-iceberg-iceberg-refs) | Returns the branches and tags of an Iceberg table. | 
| [iceberg\_scan](#athena-duckdb-functions-iceberg-iceberg-scan) | Reads the rows of an Iceberg table from its location in Amazon S3. | 
| [iceberg\_scan\_plan](#athena-duckdb-functions-iceberg-iceberg-scan-plan) | Returns the data files that a scan of an Iceberg table reads, with an optional row filter. | 
| [iceberg\_schema\_properties](#athena-duckdb-functions-iceberg-iceberg-schema-properties) | Returns the properties of a database in the AWS Glue Data Catalog as key and value pairs. | 
| [iceberg\_schemas](#athena-duckdb-functions-iceberg-iceberg-schemas) | Returns the fields of every schema of an Iceberg table, one row per top-level field. | 
| [iceberg\_snapshots](#athena-duckdb-functions-iceberg-iceberg-snapshots) | Returns one row for each snapshot of an Iceberg table. | 
| [iceberg\_table\_properties](#athena-duckdb-functions-iceberg-iceberg-table-properties) | Returns the properties of an Iceberg table as key and value pairs. | 
| [iceberg\_truncate](#athena-duckdb-functions-iceberg-iceberg-truncate) | Returns a value truncated as the Iceberg `truncate` partition transform computes it. | 
| [remove\_iceberg\_table\_properties](#athena-duckdb-functions-iceberg-remove-iceberg-table-properties) | Removes one or more properties from an Iceberg table. | 
| [set\_iceberg\_table\_properties](#athena-duckdb-functions-iceberg-set-iceberg-table-properties) | Sets one or more properties of an Iceberg table. | 

## `iceberg_bucket` function
<a name="athena-duckdb-functions-iceberg-iceberg-bucket"></a>

Returns the bucket that `value` falls into when a table is partitioned with the Iceberg `bucket` transform into `num_buckets` buckets. The function hashes the value with the 32-bit Murmur3 hash that the Apache Iceberg specification defines for the value's type. Then it maps the hash to a bucket number from `0` to `num_buckets - 1`.

Use it to find the bucket partition that holds a value, or to check how evenly values spread across buckets. If `value` is `NULL`, the function returns `NULL`.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-bucket-syntax"></a>

```sql
iceberg_bucket({{num_buckets}}, {{value}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-bucket-arguments"></a>

The `iceberg_bucket` function takes the following arguments:

**{{num\_buckets}}**  
The number of buckets, as a positive `INTEGER`.

**{{value}}**  
The value to hash: an `INTEGER`, `BIGINT`, `DECIMAL`, `DATE`, `TIME`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, `TIMESTAMP_NS`, `TIMESTAMPTZ_NS`, `VARCHAR`, `UUID`, or `BLOB` value.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-bucket-return-type"></a>

`INTEGER`

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-bucket-examples"></a>

The following SQL query returns the bucket of the integer `34` in a table with 16 buckets.

```sql
SELECT iceberg_bucket(16, 34) AS result
```

The query returns the following result.


| result | 
| --- | 
| `3` | 

The following SQL query shows that the bucket depends on the type of the value. The integer `34` and the string `'34'` land in different buckets.

```sql
SELECT
    iceberg_bucket(16, 34) AS from_integer,
    iceberg_bucket(16, '34') AS from_string
```

The query returns the following result.


| from\_integer | from\_string | 
| --- | --- | 
| `3` | `9` | 

The following SQL query returns `NULL` for a `NULL` value.

```sql
SELECT
    iceberg_bucket(16, CAST(NULL AS INTEGER)) AS result
```

The query returns the following result.


| result | 
| --- | 
| `NULL` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-bucket-considerations"></a>

The bucket depends on the type of `value`, so pass the value with the type of the partition source column. The number `34` and the string `'34'` land in different buckets. `INTEGER` and `BIGINT` values of the same number land in the same bucket.

`num_buckets` must be greater than `0`. Otherwise the query fails.

There is no form for `REAL` or `DOUBLE` values, because the Iceberg specification does not define the `bucket` transform for floating-point types.

## `iceberg_column_stats` function
<a name="athena-duckdb-functions-iceberg-iceberg-column-stats"></a>

Returns the statistics that the table's manifests store for each column of each data file in the current snapshot, or in the snapshot that you select. Each row names the file, its status and content type, and the column and its type. It also gives the column's lower and upper bounds, its size in bytes, and its counts of values, `NULL` values, and `NaN` values in that file.

The `lower_bound` and `upper_bound` columns hold the bounds as text, and `column_type` gives the column's type, so one result can hold bounds of every type.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-column-stats-syntax"></a>

```sql
iceberg_column_stats({{table_name}} [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-column-stats-arguments"></a>

The `iceberg_column_stats` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-column-stats-return-type"></a>

A table with one row per data file and column, and the columns `status`, `content`, `file_path`, `partition`, `column_name`, `column_type`, `lower_bound`, and `upper_bound` (all `VARCHAR`). The other columns are `column_size`, `value_count`, `null_value_count`, `nan_value_count`, and `file_sequence_number` (all `BIGINT`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-column-stats-examples"></a>

The following SQL query returns the bounds and the value count of the `order_id` column in each data file, with the file's sequence number.

```sql
SELECT
    file_sequence_number,
    lower_bound,
    upper_bound,
    value_count
FROM iceberg_column_stats('sales_db.orders_iceberg')
WHERE column_name = 'order_id'
ORDER BY file_sequence_number
```

The query returns the following results.


| file\_sequence\_number | lower\_bound | upper\_bound | value\_count | 
| --- | --- | --- | --- | 
| `1` | `1` | `2` | `2` | 
| `2` | `3` | `3` | `1` | 

The following SQL query lists the columns and their types.

```sql
SELECT DISTINCT column_name, column_type
FROM iceberg_column_stats('sales_db.orders_iceberg')
ORDER BY column_name
```

The query returns the following results.


| column\_name | column\_type | 
| --- | --- | 
| `amount` | `DECIMAL(10,2)` | 
| `customer` | `VARCHAR` | 
| `order_date` | `DATE` | 
| `order_id` | `INTEGER` | 
| `region` | `VARCHAR` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-column-stats-considerations"></a>

`lower_bound` and `upper_bound` are `VARCHAR` values. Cast them to the type in `column_type` before you compare them as numbers or dates. As text, `'10'` sorts before `'9'`.

## `iceberg_files` function
<a name="athena-duckdb-functions-iceberg-iceberg-files"></a>

Returns the data files and delete files that the current snapshot, or the snapshot that you select, uses. Each row gives the file's content type, path, format, partition spec, record count, and size in bytes. It also gives the per-column statistics that the manifest stores for the file, and the other file fields that the Apache Iceberg specification defines. The `content` column is `0` for a data file.

In `column_sizes`, `value_counts`, `null_value_counts`, `nan_value_counts`, `lower_bounds`, and `upper_bounds`, the keys are Iceberg field IDs, and the bounds are in the binary encoding of the Iceberg specification. The `readable_metrics` column holds the same statistics as a `STRUCT` with one field for each column name, and gives the bounds in the column's own type.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-files-syntax"></a>

```sql
iceberg_files({{table_name}} [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-files-arguments"></a>

The `iceberg_files` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-files-return-type"></a>

A table with one row per file and the columns `content` (`INTEGER`), `file_path` (`VARCHAR`), `file_format` (`VARCHAR`), `spec_id` (`INTEGER`), `record_count` (`BIGINT`), and `file_size_in_bytes` (`BIGINT`). The next columns are `column_sizes`, `value_counts`, `null_value_counts`, and `nan_value_counts` (`MAP(INTEGER, BIGINT)`), `lower_bounds` and `upper_bounds` (`MAP(INTEGER, BLOB)`), `key_metadata` (`BLOB`), and `split_offsets` (`BIGINT[]`). The last columns are `equality_ids` (`INTEGER[]`), `sort_order_id` (`INTEGER`), `first_row_id` (`BIGINT`), `referenced_data_file` (`VARCHAR`), `content_offset` (`BIGINT`), `content_size_in_bytes` (`BIGINT`), and `readable_metrics` (`STRUCT`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-files-examples"></a>

The following SQL query returns the content type, format, and record count of each file.

```sql
SELECT content, file_format, record_count
FROM iceberg_files('sales_db.orders_iceberg')
ORDER BY record_count
```

The query returns the following results.


| content | file\_format | record\_count | 
| --- | --- | --- | 
| `0` | `parquet` | `1` | 
| `0` | `parquet` | `2` | 

The following SQL query reads the lower and upper bounds of the `order_id` column in each file from `readable_metrics`.

```sql
SELECT
    readable_metrics.order_id.lower_bound AS min_order_id,
    readable_metrics.order_id.upper_bound AS max_order_id
FROM iceberg_files('sales_db.orders_iceberg')
ORDER BY min_order_id
```

The query returns the following results.


| min\_order\_id | max\_order\_id | 
| --- | --- | 
| `1` | `2` | 
| `3` | `3` | 

The following SQL query counts the files of the table's first snapshot. The snapshot ID comes from `iceberg_snapshots`. The first snapshot has one data file.

```sql
SELECT count(*) AS data_files
FROM iceberg_files(
    'sales_db.orders_iceberg',
    snapshot_from_id := 1294122691170353594
)
```

The query returns the following result.


| data\_files | 
| --- | 
| `1` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-files-considerations"></a>

To compare a file's bounds with values, use `readable_metrics`, for example `readable_metrics.order_id.lower_bound`. The values in `lower_bounds` and `upper_bounds` are binary.

## `iceberg_history` function
<a name="athena-duckdb-functions-iceberg-iceberg-history"></a>

Returns one row for each entry in the table's snapshot log. Each row gives the time that the snapshot became the current snapshot, the snapshot ID, and the ID of its parent snapshot. It also shows whether the snapshot is an ancestor of the current snapshot.

`parent_id` is `NULL` for the table's first snapshot. A snapshot that is no longer an ancestor of the current snapshot, for example after a rollback, has `is_current_ancestor` set to `false`.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-history-syntax"></a>

```sql
iceberg_history({{table_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-history-arguments"></a>

The `iceberg_history` function takes the following argument:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-history-return-type"></a>

A table with the columns `made_current_at` (`TIMESTAMP_MS`), `snapshot_id` (`BIGINT`), `parent_id` (`BIGINT`), and `is_current_ancestor` (`BOOLEAN`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-history-examples"></a>

The following SQL query lists the history in order and shows, for each entry, whether it is the first snapshot and whether it is an ancestor of the current snapshot.

```sql
SELECT
    parent_id IS NULL AS is_first_snapshot,
    is_current_ancestor
FROM iceberg_history('sales_db.orders_iceberg')
ORDER BY made_current_at
```

The query returns the following results.


| is\_first\_snapshot | is\_current\_ancestor | 
| --- | --- | 
| `true` | `true` | 
| `false` | `true` | 

The following SQL query counts the history entries that are ancestors of the current snapshot.

```sql
SELECT count(*) AS ancestors
FROM iceberg_history('sales_db.orders_iceberg')
WHERE is_current_ancestor
```

The query returns the following result.


| ancestors | 
| --- | 
| `2` | 

## `iceberg_manifests` function
<a name="athena-duckdb-functions-iceberg-iceberg-manifests"></a>

Returns the manifest files that the current snapshot, or the snapshot that you select, lists in its manifest list. Each row gives the manifest's path and length in bytes, its partition spec, and the snapshot that added it. It also gives the numbers of data files and delete files that the manifest adds, keeps, and deletes.

The `content` column is `0` for a manifest of data files and `1` for a manifest of delete files. The `partition_summaries` column holds one summary for each partition field, and is an empty list for an unpartitioned table.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-manifests-syntax"></a>

```sql
iceberg_manifests({{table_name}} [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-manifests-arguments"></a>

The `iceberg_manifests` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-manifests-return-type"></a>

A table with one row per manifest and the columns `content` (`INTEGER`), `path` (`VARCHAR`), `length` (`BIGINT`), `partition_spec_id` (`INTEGER`), and `added_snapshot_id` (`BIGINT`). The next columns are `added_data_files_count`, `existing_data_files_count`, `deleted_data_files_count`, `added_delete_files_count`, `existing_delete_files_count`, and `deleted_delete_files_count` (all `INTEGER`). The last column is `partition_summaries` (`STRUCT(contains_null BOOLEAN, contains_nan BOOLEAN, lower_bound VARCHAR, upper_bound VARCHAR)[]`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-manifests-examples"></a>

The following SQL query counts the manifests of each content type and the data files that they add. Each of the two snapshots added one manifest with one data file.

```sql
SELECT
    content,
    count(*) AS manifests,
    sum(added_data_files_count) AS added_data_files
FROM iceberg_manifests('sales_db.orders_iceberg')
GROUP BY content
ORDER BY content
```

The query returns the following result.


| content | manifests | added\_data\_files | 
| --- | --- | --- | 
| `0` | `2` | `2` | 

## `iceberg_metadata` function
<a name="athena-duckdb-functions-iceberg-iceberg-metadata"></a>

Returns the entries of the manifests in the current snapshot, or in the snapshot that you select. Each row describes one data file or delete file. It gives the manifest that lists the file, and the manifest's sequence number and content type.

The `status` column shows whether the snapshot that wrote the manifest added, kept, or deleted the file: `ADDED`, `EXISTING`, or `DELETED`. Because the status refers to the snapshot that wrote the manifest, an entry in an older manifest can still be `ADDED`. The `content` column shows whether the file holds data or deletes. The row also gives the file's path, format, and record count, and its data and file sequence numbers.

To count the files that a snapshot still uses, leave out the entries whose `status` is `DELETED`.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-metadata-syntax"></a>

```sql
iceberg_metadata({{table_name}} [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-metadata-arguments"></a>

The `iceberg_metadata` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-metadata-return-type"></a>

A table with one row per manifest entry and the columns `manifest_path` (`VARCHAR`), `manifest_sequence_number` (`BIGINT`), `manifest_content` (`VARCHAR`), `status` (`VARCHAR`), and `content` (`VARCHAR`). The other columns are `file_path` (`VARCHAR`), `file_format` (`VARCHAR`), `record_count` (`BIGINT`), `data_sequence_number` (`BIGINT`), and `file_sequence_number` (`BIGINT`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-metadata-examples"></a>

The following SQL query returns the manifest sequence number, status, content type, format, and record count of each entry.

```sql
SELECT
    manifest_sequence_number,
    status,
    content,
    file_format,
    record_count
FROM iceberg_metadata('sales_db.orders_iceberg')
ORDER BY manifest_sequence_number
```

The query returns the following results.


| manifest\_sequence\_number | status | content | file\_format | record\_count | 
| --- | --- | --- | --- | --- | 
| `1` | `ADDED` | `DATA` | `parquet` | `2` | 
| `2` | `ADDED` | `DATA` | `parquet` | `1` | 

The following SQL query counts the files that the current snapshot uses and the records in them.

```sql
SELECT
    count(*) AS live_files,
    sum(record_count) AS records
FROM iceberg_metadata('sales_db.orders_iceberg')
WHERE status <> 'DELETED'
```

The query returns the following result.


| live\_files | records | 
| --- | --- | 
| `2` | `3` | 

## `iceberg_partition_specs` function
<a name="athena-duckdb-functions-iceberg-iceberg-partition-specs"></a>

Returns every partition spec in the table metadata, with one row for each partition field. Each row gives the spec ID, whether the spec is the table's default spec, and the field's ID, name, transform, and source column.

A spec with no fields, such as the spec of an unpartitioned table, returns one row whose field columns are `NULL`.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-partition-specs-syntax"></a>

```sql
iceberg_partition_specs({{table_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-partition-specs-arguments"></a>

The `iceberg_partition_specs` function takes the following argument:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

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

A table with the columns `spec_id` (`INTEGER`), `is_default` (`BOOLEAN`), `field_id` (`BIGINT`), `name` (`VARCHAR`), `transform` (`VARCHAR`), `source_id` (`BIGINT`), and `source_column` (`VARCHAR`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-partition-specs-examples"></a>

The following SQL query returns the spec ID, whether the spec is the default, and whether the row has no partition field. The example table is not partitioned, so its only spec has no fields.

```sql
SELECT
    spec_id,
    is_default,
    name IS NULL AS no_partition_field
FROM iceberg_partition_specs('sales_db.orders_iceberg')
```

The query returns the following result.


| spec\_id | is\_default | no\_partition\_field | 
| --- | --- | --- | 
| `0` | `true` | `true` | 

## `iceberg_partition_stats` function
<a name="athena-duckdb-functions-iceberg-iceberg-partition-stats"></a>

Returns one row for each partition field of each manifest in the current snapshot, or in the snapshot that you select. Each row gives the manifest and the snapshot that added it, the partition spec, and the partition field's ID, name, source columns, transform, and type. It also gives the lower and upper bounds of the field's values in that manifest, and whether any value is `NULL` or `NaN`.

For an unpartitioned table, the function returns no rows.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-partition-stats-syntax"></a>

```sql
iceberg_partition_stats({{table_name}} [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-partition-stats-arguments"></a>

The `iceberg_partition_stats` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

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

A table with the columns `manifest_path` (`VARCHAR`), `added_snapshot_id` (`BIGINT`), `partition_spec_id` (`INTEGER`), `partition_field_id` (`UBIGINT`), `partition_field_name` (`VARCHAR`), `partition_source_columns` (`VARCHAR[]`), `partition_field_transform` (`VARCHAR`), `partition_field_type` (`VARCHAR`), `lower_bound` (`VARCHAR`), `upper_bound` (`VARCHAR`), `contains_null` (`BOOLEAN`), and `contains_nan` (`BOOLEAN`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-partition-stats-examples"></a>

The following SQL query counts the rows that the function returns. The example table is not partitioned, so the count is `0`.

```sql
SELECT count(*) AS partition_field_rows
FROM iceberg_partition_stats('sales_db.orders_iceberg')
```

The query returns the following result.


| partition\_field\_rows | 
| --- | 
| `0` | 

## `iceberg_partitions` function
<a name="athena-duckdb-functions-iceberg-iceberg-partitions"></a>

Returns one row for each partition in the current snapshot, or in the snapshot that you select. Each row gives the number of records, the number of data files, and the total size of the data files in bytes. It also gives the numbers of position delete and equality delete records and files, and the time and the snapshot of the partition's last change.

For an unpartitioned table, the function returns one row for the whole table.

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

```sql
iceberg_partitions({{table_name}} [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

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

The `iceberg_partitions` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

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

A table. For an unpartitioned table, the columns are `record_count` (`BIGINT`), `file_count` (`INTEGER`), `total_data_file_size_in_bytes` (`BIGINT`), `position_delete_record_count` (`BIGINT`), `position_delete_file_count` (`INTEGER`), `equality_delete_record_count` (`BIGINT`), `equality_delete_file_count` (`INTEGER`), `last_updated_at` (`TIMESTAMP_MS`), and `last_updated_snapshot_id` (`BIGINT`).

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

The following SQL query returns the record count, the data file count, and the position delete record count. The example table is not partitioned, so the function returns one row for the whole table.

```sql
SELECT
    record_count,
    file_count,
    position_delete_record_count
FROM iceberg_partitions('sales_db.orders_iceberg')
```

The query returns the following result.


| record\_count | file\_count | position\_delete\_record\_count | 
| --- | --- | --- | 
| `3` | `2` | `0` | 

## `iceberg_refs` function
<a name="athena-duckdb-functions-iceberg-iceberg-refs"></a>

Returns one row for each named reference in the table metadata, that is, each branch, such as `main`, and each tag. Each row gives the reference's name, its type (`BRANCH` or `TAG`), the ID of the snapshot that it points to, and its retention settings. A retention column is `NULL` when the reference does not set it.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-refs-syntax"></a>

```sql
iceberg_refs({{table_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-refs-arguments"></a>

The `iceberg_refs` function takes the following argument:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-refs-return-type"></a>

A table with the columns `name` (`VARCHAR`), `type` (`VARCHAR`), `snapshot_id` (`BIGINT`), `max_reference_age_in_ms` (`BIGINT`), `min_snapshots_to_keep` (`INTEGER`), and `max_snapshot_age_in_ms` (`BIGINT`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-refs-examples"></a>

The following SQL query returns the name and type of each reference.

```sql
SELECT name, type
FROM iceberg_refs('sales_db.orders_iceberg')
ORDER BY name
```

The query returns the following result.


| name | type | 
| --- | --- | 
| `main` | `BRANCH` | 

The following SQL query checks whether each reference points to the table's newest snapshot.

```sql
SELECT
    r.name,
    r.snapshot_id = (
        SELECT
            s.snapshot_id FROM iceberg_snapshots(
                'sales_db.orders_iceberg'
            ) AS s
        ORDER BY s.sequence_number DESC LIMIT 1
    ) AS points_to_newest
FROM iceberg_refs('sales_db.orders_iceberg') AS r
ORDER BY r.name
```

The query returns the following result.


| name | points\_to\_newest | 
| --- | --- | 
| `main` | `true` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-refs-considerations"></a>

When you query an Iceberg table by name, DuckDB reads the table's current snapshot. You cannot read a branch or a tag by its name, and `AT (VERSION => '{{name}}')` fails. To read the snapshot that a reference points to, pass its `snapshot_id` in `AT (VERSION => {{snapshot_id}})`.

## `iceberg_scan` function
<a name="athena-duckdb-functions-iceberg-iceberg-scan"></a>

Reads the rows of an Apache Iceberg table from its location in Amazon S3, without going through a table in the AWS Glue Data Catalog. Pass the location of a table metadata file, or the table directory together with `version`. The function returns the table's columns from the current snapshot of that metadata, or from the snapshot that you select with `snapshot_from_id` or `snapshot_from_timestamp`.

To read an Iceberg table in the AWS Glue Data Catalog, query the table by name instead, for example `SELECT * FROM sales_db.orders_iceberg`. For time travel on a catalog table, write `AT (VERSION => {{snapshot_id}})` or `AT (TIMESTAMP => {{timestamp}})` after the table name.

`iceberg_scan` also accepts the named parameters of `read_parquet` that control how the engine reads the Parquet data files, except `schema`.

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

```sql
iceberg_scan({{location}} [, version := {{version}} ]
    [, version_name_format := {{format}} ]
    [, metadata_compression_codec := {{codec}} ]
    [, allow_moved_paths := {{boolean}} ] [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ])
```

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

The `iceberg_scan` function takes the following arguments:

**{{location}}**  
The Amazon S3 location of a table metadata file, a file whose name ends in `.metadata.json`, as a `VARCHAR` literal. You can also pass the table directory together with `version`.

**{{version}}**  
The metadata version to read when `location` is the table directory, as a `VARCHAR`. The engine looks for `v{{version}}.metadata.json`, then `{{version}}.metadata.json`, in the table's `metadata` directory. This argument is optional.

**{{version\_name\_format}}**  
A file name pattern, as a `VARCHAR` value, that replaces the default patterns for `version`. The pattern must contain `%s` exactly twice: the first stands for the version and the second for the compression suffix. You can pass only one pattern. This argument is optional.

**{{metadata\_compression\_codec}}**  
The compression codec of the metadata files, as a `VARCHAR` value. Set it to `'gzip'` when the metadata files are compressed with gzip. The default is `'none'`. This argument is optional.

**{{allow\_moved\_paths}}**  
The option to look for the table's files under `location`, as a `BOOLEAN`. When `true`, the engine looks for them there even when the metadata records a different table location, for example after the files were copied. The default is `false`. This argument is optional.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to read instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function reads the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

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

A table with the columns of the Iceberg table, in the schema of the snapshot that the function reads.

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

The following SQL query counts the rows of the table from its current metadata file.

```sql
SELECT count(*) AS order_count
FROM iceberg_scan(
    's3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/00003-7f27ce45-a215-4b96-aa29-cfc276a81182.metadata.json'
)
```

The query returns the following result.


| order\_count | 
| --- | 
| `3` | 

The following SQL query reads the table directory with `version` and returns the `order_id` and `customer` columns.

```sql
SELECT order_id, customer
FROM iceberg_scan(
    's3://amzn-s3-demo-bucket/tables/orders_iceberg',
    version := '00003-7f27ce45-a215-4b96-aa29-cfc276a81182'
)
ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | 
| --- | --- | 
| `1` | `alice` | 
| `2` | `bob` | 
| `3` | `carol` | 

The following SQL query reads the table's first snapshot, which holds two rows. The snapshot ID comes from `iceberg_snapshots`.

```sql
SELECT order_id, customer
FROM iceberg_scan(
    's3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/00003-7f27ce45-a215-4b96-aa29-cfc276a81182.metadata.json',
    snapshot_from_id := 1294122691170353594
)
ORDER BY order_id
```

The query returns the following results.


| order\_id | customer | 
| --- | --- | 
| `1` | `alice` | 
| `2` | `bob` | 

The following SQL query looks up the current metadata file of a table in the AWS Glue Data Catalog, which you can then pass to `iceberg_scan`.

```sql
SELECT
    parameters['metadata_location'] AS metadata_location
FROM glue_get_table_response('sales_db.orders_iceberg')
```

The query returns the following result.


| metadata\_location | 
| --- | 
| `s3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/00003-7f27ce45-a215-4b96-aa29-cfc276a81182.metadata.json` | 

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

Pass an Amazon S3 location, not a table name. A table name in `iceberg_scan` makes the query fail.

If the table directory has no `version-hint.text` file, a call with the directory and no `version` fails. You cannot change engine settings to let the engine choose a metadata file on its own. The table in the examples has no such file. Pass the metadata file, or pass the directory with `version`.

To find the current metadata file of a table in the AWS Glue Data Catalog, read the table's `metadata_location` parameter with `glue_get_table_response` in a separate query.

## `iceberg_scan_plan` function
<a name="athena-duckdb-functions-iceberg-iceberg-scan-plan"></a>

Plans a scan of an Iceberg table from its location in Amazon S3 and returns one row for each data file that the scan reads. Each row gives the file's path, format, size, record count, partition values, and delete files. It also gives the snapshot and schema that the plan uses.

With `row_filter`, the plan leaves out the files whose column statistics show that no row in the file can match the filter. Like `iceberg_scan`, the function takes the location of a table metadata file, or the table directory together with `version`, not a table name.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-scan-plan-syntax"></a>

```sql
iceberg_scan_plan({{location}}
    [, row_filter := {{predicate}} ]
    [, produce_sequence_number := {{boolean}} ] [,
    { snapshot_from_id := {{snapshot_id}}
    | snapshot_from_timestamp := {{timestamp}} } ]
    [, version := {{version}} ]
    [, version_name_format := {{format}} ]
    [, metadata_compression_codec := {{codec}} ]
    [, allow_moved_paths := {{boolean}} ])
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-scan-plan-arguments"></a>

The `iceberg_scan_plan` function takes the following arguments:

**{{location}}**  
The Amazon S3 location of a table metadata file, a file whose name ends in `.metadata.json`, as a `VARCHAR` literal. You can also pass the table directory together with `version`.

**{{row\_filter}}**  
A predicate on the table's columns, as a `VARCHAR`, for example `'order_id > 2'`. It cannot be `NULL`. This argument is optional.

**{{produce\_sequence\_number}}**  
The option to fill the `sequence_number` column, as a `BOOLEAN`. When `true`, the function fills the column. The default is `false`, which leaves it `NULL`. This argument is optional.

**{{snapshot\_from\_id}}**  
The ID of the snapshot to plan instead of the current snapshot, as a `UBIGINT`. If no snapshot has this ID, the query fails. This argument is optional.

**{{snapshot\_from\_timestamp}}**  
A point in time, as a `TIMESTAMP`. The function plans the snapshot that was current at this time instead of the current snapshot. You cannot combine it with `snapshot_from_id`. If the time is in the future, the query fails. This argument is optional.

**{{version}}**  
The metadata version to read when `location` is the table directory, as a `VARCHAR`. The engine looks for `v{{version}}.metadata.json`, then `{{version}}.metadata.json`, in the table's `metadata` directory. This argument is optional.

**{{version\_name\_format}}**  
A file name pattern, as a `VARCHAR` value, that replaces the default patterns for `version`. The pattern must contain `%s` exactly twice: the first stands for the version and the second for the compression suffix. You can pass only one pattern. This argument is optional.

**{{metadata\_compression\_codec}}**  
The compression codec of the metadata files, as a `VARCHAR` value. Set it to `'gzip'` when the metadata files are compressed with gzip. The default is `'none'`. This argument is optional.

**{{allow\_moved\_paths}}**  
The option to look for the table's files under `location`, as a `BOOLEAN`. When `true`, the engine looks for them there even when the metadata records a different table location. The default is `false`. This argument is optional.

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

A table with one row per data file and the columns `file_path` (`VARCHAR`), `file_format` (`VARCHAR`), `file_size_in_bytes` (`BIGINT`), `record_count` (`BIGINT`), `sequence_number` (`BIGINT`), and `first_row_id` (`BIGINT`). The next columns are `partition_spec_id` (`INTEGER`), `partition_constants` (`STRUCT`), `delete_files` (a list of `STRUCT` values), `snapshot_id` (`BIGINT`), and `schema_id` (`INTEGER`). The last columns are `metadata` (`VARIANT`), `schema` (`STRUCT`), and `row_filter` (`VARCHAR`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-scan-plan-examples"></a>

The following SQL query counts the data files that a full scan reads and the records in them.

```sql
SELECT
    count(*) AS data_files,
    sum(record_count) AS records
FROM iceberg_scan_plan(
    's3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/00003-7f27ce45-a215-4b96-aa29-cfc276a81182.metadata.json'
)
```

The query returns the following result.


| data\_files | records | 
| --- | --- | 
| `2` | `3` | 

The following SQL query plans a scan with a row filter. The column statistics show that only one file can hold rows with `order_id` greater than 2, so the plan has one file.

```sql
SELECT
    count(*) AS data_files,
    sum(record_count) AS records
FROM iceberg_scan_plan(
    's3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/00003-7f27ce45-a215-4b96-aa29-cfc276a81182.metadata.json',
    row_filter := 'order_id > 2'
)
```

The query returns the following result.


| data\_files | records | 
| --- | --- | 
| `1` | `1` | 

## `iceberg_schema_properties` function
<a name="athena-duckdb-functions-iceberg-iceberg-schema-properties"></a>

Returns one row for each property of a database, which Iceberg calls a namespace, with the columns `key` and `value`. Pass the database name, not a table name.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-schema-properties-syntax"></a>

```sql
iceberg_schema_properties({{database_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-schema-properties-arguments"></a>

The `iceberg_schema_properties` function takes the following argument:

**{{database\_name}}**  
The database, as a `VARCHAR` literal in the form `'[catalog.]database'`.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-schema-properties-return-type"></a>

A table with the columns `key` (`VARCHAR`) and `value` (`VARCHAR`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-schema-properties-examples"></a>

The following SQL query counts the properties of the `sales_db` database. The database has no properties, so the count is `0`.

```sql
SELECT count(*) AS properties
FROM iceberg_schema_properties('sales_db')
```

The query returns the following result.


| properties | 
| --- | 
| `0` | 

## `iceberg_schemas` function
<a name="athena-duckdb-functions-iceberg-iceberg-schemas"></a>

Returns one row for each top-level field of each schema in the table metadata. Each row gives the schema ID and the field's name, Iceberg field ID, type, doc string, and whether the field is required. The `is_current` column is `true` for the fields of the table's current schema.

An Iceberg table gets a new schema each time its columns change, for example when a writer adds, drops, or renames a column. The earlier schemas stay in the table metadata. Use `iceberg_schemas` to see how the columns of a table changed, or to find the field ID of a column.

The `type` column holds the DuckDB type that the field is read as, such as `INTEGER` or `DECIMAL(10,2)`, not the Iceberg type name, such as `int`. A field inside a `STRUCT`, `LIST`, or `MAP` column has no row of its own, and the `type` of the column shows the full nested type. The `doc` column is `NULL` when the field has no doc string.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-schemas-syntax"></a>

```sql
iceberg_schemas({{table_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-schemas-arguments"></a>

The `iceberg_schemas` function takes the following argument:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-schemas-return-type"></a>

A table with one row per field and the columns `schema_id` (`INTEGER`), `name` (`VARCHAR`), `field_id` (`INTEGER`), `type` (`VARCHAR`), `required` (`BOOLEAN`), `doc` (`VARCHAR`), and `is_current` (`BOOLEAN`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-schemas-examples"></a>

The following SQL query lists the fields of the table's current schema, with their field IDs and types, and whether each field is required.

```sql
SELECT field_id, name, type, required
FROM iceberg_schemas('sales_db.orders_iceberg')
WHERE is_current
ORDER BY field_id
```

The query returns the following results.


| field\_id | name | type | required | 
| --- | --- | --- | --- | 
| `1` | `order_id` | `INTEGER` | `false` | 
| `2` | `customer` | `VARCHAR` | `false` | 
| `3` | `region` | `VARCHAR` | `false` | 
| `4` | `amount` | `DECIMAL(10,2)` | `false` | 
| `5` | `order_date` | `DATE` | `false` | 

The following SQL query counts the fields in each schema of the table. The columns of the example table never changed, so the table has one schema, with the ID `0`.

```sql
SELECT schema_id, is_current, count(*) AS fields
FROM iceberg_schemas('sales_db.orders_iceberg')
GROUP BY schema_id, is_current
ORDER BY schema_id
```

The query returns the following result.


| schema\_id | is\_current | fields | 
| --- | --- | --- | 
| `0` | `true` | `5` | 

The following SQL query uses the field ID of `order_id` to read its value count from `iceberg_files`, whose statistics are keyed by field ID. The two data files hold three values in total.

```sql
SELECT
    s.name,
    sum(f.value_counts[s.field_id]) AS value_count
FROM iceberg_schemas('sales_db.orders_iceberg') AS s
CROSS JOIN iceberg_files('sales_db.orders_iceberg') AS f
WHERE s.is_current AND s.name = 'order_id'
GROUP BY s.name
```

The query returns the following result.


| name | value\_count | 
| --- | --- | 
| `order_id` | `3` | 

## `iceberg_snapshots` function
<a name="athena-duckdb-functions-iceberg-iceberg-snapshots"></a>

Returns one row for each snapshot in the table metadata, with the snapshot's sequence number, ID, parent snapshot ID, commit time, manifest list location, operation, and summary. Use it to see when and how a table changed, for example to check whether a write committed before you retry it. You can also use it to find a snapshot ID for time travel.

`summary` is a `MAP` of the counters that the writer recorded for the snapshot, such as `added-records` and `total-records`. To read one counter, write `summary['{{key}}']`.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-snapshots-syntax"></a>

```sql
iceberg_snapshots({{table_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-snapshots-arguments"></a>

The `iceberg_snapshots` function takes the following argument:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-snapshots-return-type"></a>

A table with the columns `sequence_number` (`UBIGINT`), `snapshot_id` (`UBIGINT`), `parent_id` (`BIGINT`), `timestamp_ms` (`TIMESTAMP_MS`), `manifest_list` (`VARCHAR`), `operation` (`VARCHAR`), and `summary` (`MAP(VARCHAR, VARCHAR)`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-snapshots-examples"></a>

The following SQL query lists the snapshots in order, with the operation and the number of rows that each snapshot added.

```sql
SELECT
    sequence_number,
    operation,
    summary['added-records'] AS added_records
FROM iceberg_snapshots('sales_db.orders_iceberg')
ORDER BY sequence_number
```

The query returns the following results.


| sequence\_number | operation | added\_records | 
| --- | --- | --- | 
| `1` | `append` | `2` | 
| `2` | `append` | `1` | 

The following SQL query returns the sequence number and the operation of the newest snapshot.

```sql
SELECT sequence_number, operation
FROM iceberg_snapshots('sales_db.orders_iceberg')
ORDER BY sequence_number DESC
LIMIT 1
```

The query returns the following result.


| sequence\_number | operation | 
| --- | --- | 
| `2` | `append` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-snapshots-considerations"></a>

The function returns snapshots in no fixed order. Add `ORDER BY sequence_number` or `ORDER BY timestamp_ms` when the order matters.

`snapshot_id` is a `UBIGINT` here, while `iceberg_history` and `iceberg_refs` return snapshot IDs as `BIGINT`.

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

In Athena engine version 3, you query the `$snapshots` metadata table, for example `SELECT * FROM "orders_iceberg$snapshots"`. In DuckDB, call `iceberg_snapshots('sales_db.orders_iceberg')` instead.

The columns differ from the Athena engine version 3 `$snapshots` table. For example, the commit time is in `timestamp_ms`, not `committed_at`.

## `iceberg_table_properties` function
<a name="athena-duckdb-functions-iceberg-iceberg-table-properties"></a>

Returns one row for each property in the table's Iceberg metadata, with the columns `key` and `value`. Use it in place of `SHOW TBLPROPERTIES` for an Iceberg table.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-table-properties-syntax"></a>

```sql
iceberg_table_properties({{table_name}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-table-properties-arguments"></a>

The `iceberg_table_properties` function takes the following argument:

**{{table\_name}}**  
The Iceberg table, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

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

A table with the columns `key` (`VARCHAR`) and `value` (`VARCHAR`).

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-table-properties-examples"></a>

The following SQL query lists the properties of the example table.

```sql
SELECT key, value
FROM iceberg_table_properties('sales_db.orders_iceberg')
ORDER BY key
```

The query returns the following results.


| key | value | 
| --- | --- | 
| `write.parquet.compression-codec` | `zstd` | 
| `write.parquet.shred-variants` | `true` | 

The following SQL query looks for a property that the table does not set, so the count is 0.

```sql
SELECT count(*) AS matches
FROM iceberg_table_properties('sales_db.orders_iceberg')
WHERE key = 'write.format.default'
```

The query returns the following result.


| matches | 
| --- | 
| `0` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-table-properties-considerations"></a>

The function returns the properties in the Iceberg metadata, not the AWS Glue table parameters such as `table_type` and `metadata_location`. To read those, use the [`glue_get_table_response` function](duckdb-functions-glue.md#athena-duckdb-functions-glue-glue-get-table-response).

A property that the table does not set returns no row.

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

In Athena engine version 3, you list table properties with `SHOW TBLPROPERTIES`. In DuckDB, use `iceberg_table_properties` for an Iceberg table.

## `iceberg_truncate` function
<a name="athena-duckdb-functions-iceberg-iceberg-truncate"></a>

Returns `value` truncated to `width`, as the Iceberg `truncate` partition transform computes it. For an integer, the result is the largest multiple of `width` that is less than or equal to the value, so a negative value rounds down, away from zero. For a `VARCHAR` value, the result is the first `width` characters, and for a `BLOB` value, the first `width` bytes.

For a `DECIMAL` value, `width` applies to the unscaled value, the digits without the decimal point. For example, with a scale of 2, a width of `50` truncates to a multiple of `0.50`. If `value` is `NULL`, the function returns `NULL`.

### Syntax
<a name="athena-duckdb-functions-iceberg-iceberg-truncate-syntax"></a>

```sql
iceberg_truncate({{width}}, {{value}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-iceberg-truncate-arguments"></a>

The `iceberg_truncate` function takes the following arguments:

**{{width}}**  
The truncation width, as a positive `INTEGER`.

**{{value}}**  
The value to truncate: an `INTEGER`, `BIGINT`, `DECIMAL`, `VARCHAR`, or `BLOB` value.

### Return type
<a name="athena-duckdb-functions-iceberg-iceberg-truncate-return-type"></a>

The type of `value`: `INTEGER`, `BIGINT`, `DECIMAL` with the same precision and scale, `VARCHAR`, or `BLOB`.

### Examples
<a name="athena-duckdb-functions-iceberg-iceberg-truncate-examples"></a>

The following SQL query truncates an integer to a multiple of 10.

```sql
SELECT iceberg_truncate(10, 42) AS result
```

The query returns the following result.


| result | 
| --- | 
| `40` | 

The following SQL query truncates a negative integer. The result rounds down to `-10`, not toward zero.

```sql
SELECT iceberg_truncate(10, -1) AS result
```

The query returns the following result.


| result | 
| --- | 
| `-10` | 

The following SQL query keeps the first three characters of a string.

```sql
SELECT iceberg_truncate(3, 'iceberg') AS result
```

The query returns the following result.


| result | 
| --- | 
| `ice` | 

The following SQL query truncates a decimal with a scale of 2. The width `50` applies to the unscaled value `1065`, so the result is `10.50`.

```sql
SELECT iceberg_truncate(50, 10.65) AS result
```

The query returns the following result.


| result | 
| --- | 
| `10.50` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-iceberg-truncate-considerations"></a>

`width` must be greater than `0`. Otherwise the query fails.

There is no form for `REAL`, `DOUBLE`, date, or time values, because the Iceberg specification does not define the `truncate` transform for them.

## `set_iceberg_table_properties` function
<a name="athena-duckdb-functions-iceberg-set-iceberg-table-properties"></a>

Adds or changes properties in the table's Iceberg metadata, and commits the change to the catalog. Pass the properties as a `STRUCT` or `MAP` literal of property names and values, such as `{'owner': 'analytics'}`.

Run the function as its own statement with `CALL`. It returns one row with a `Success` column that holds the number of properties in the call. You can also set properties with `ALTER TABLE {{table_name}} SET ('{{key}}' = '{{value}}')`.

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

```sql
CALL set_iceberg_table_properties({{table_name}},
    {{properties}})
```

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

The `set_iceberg_table_properties` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table to change, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{properties}}**  
The properties to set, as a `STRUCT` or `MAP` literal whose keys are property names and whose values are `VARCHAR` property values.

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

A table with one row and one column, `Success` (`BIGINT`), the number of properties in the call.

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

The following SQL statement sets two properties on an Iceberg table.

```sql
CALL set_iceberg_table_properties(
    'sales_db.props_iceberg',
    {'owner': 'analytics', 'review_status': 'pending'}
)
```

The statement returns the following result.


| Success | 
| --- | 
| `2` | 

The following SQL query reads the two properties back. The `WHERE` clause leaves out any other properties of the table.

```sql
SELECT key, value
FROM iceberg_table_properties('sales_db.props_iceberg')
WHERE key IN ('owner', 'review_status')
ORDER BY key
```

The query returns the following results.


| key | value | 
| --- | --- | 
| `owner` | `analytics` | 
| `review_status` | `pending` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-set-iceberg-table-properties-considerations"></a>

You cannot set the reserved properties `format-version`, `uuid`, `snapshot-count`, `current-snapshot-id`, `current-snapshot-summary`, `current-snapshot-timestamp-ms`, `current-schema`, `default-partition-spec`, and `default-sort-order`. A call that names one fails.

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

In Athena engine version 3, you set table properties with `ALTER TABLE {{table_name}} SET TBLPROPERTIES`. In DuckDB, write `ALTER TABLE {{table_name}} SET ('{{key}}' = '{{value}}')`, or call `set_iceberg_table_properties`.

## `remove_iceberg_table_properties` function
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties"></a>

Removes the named properties from the table's Iceberg metadata, and commits the change to the catalog. Pass the property names as a list of `VARCHAR` values, such as `['review_status']`.

Run the function as its own statement with `CALL`. It returns one row with a `Success` column that holds the number of properties that the table has after the call, not the number of properties that the call removed. To check the result, read the properties with `iceberg_table_properties`.

### Syntax
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties-syntax"></a>

```sql
CALL remove_iceberg_table_properties({{table_name}},
    {{property_names}})
```

### Arguments
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties-arguments"></a>

The `remove_iceberg_table_properties` function takes the following arguments:

**{{table\_name}}**  
The Iceberg table to change, as a `VARCHAR` literal in the form `'[catalog.database.]table'`.

**{{property\_names}}**  
The names of the properties to remove, as a `VARCHAR[]` list literal.

### Return type
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties-return-type"></a>

A table with one row and one column, `Success` (`BIGINT`), the number of properties that the table has after the call.

### Examples
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties-examples"></a>

The following SQL statement removes one of the two properties that the `set_iceberg_table_properties` example sets. The table also has two default properties, so `Success` is 3: `owner` and the two defaults.

```sql
CALL remove_iceberg_table_properties(
    'sales_db.props_iceberg', ['review_status']
)
```

The statement returns the following result.


| Success | 
| --- | 
| `3` | 

The following SQL query reads back the `owner` and `review_status` properties. Only `owner` is left.

```sql
SELECT key, value
FROM iceberg_table_properties('sales_db.props_iceberg')
WHERE key IN ('owner', 'review_status')
ORDER BY key
```

The query returns the following result.


| key | value | 
| --- | --- | 
| `owner` | `analytics` | 

### Considerations
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties-considerations"></a>

You cannot remove the reserved properties `format-version`, `uuid`, `snapshot-count`, `current-snapshot-id`, `current-snapshot-summary`, `current-snapshot-timestamp-ms`, `current-schema`, `default-partition-spec`, and `default-sort-order`. A call that names one fails.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-iceberg-remove-iceberg-table-properties-differences-from-engine-version-3"></a>

In Athena engine version 3, you remove table properties with `ALTER TABLE {{table_name}} UNSET TBLPROPERTIES`, which DuckDB does not support. For an Iceberg table, call `remove_iceberg_table_properties` instead.