> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Truncate value to a width according to Iceberg partition transforms

# ICEBERG_TRUNCATE

Truncates a value to a specified width, according to the [Iceberg partition transforms specification](https://iceberg.apache.org/spec/#partition-transforms).

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
ICEBERG_TRUNCATE(<value>, <width>)
```

## Parameters

| Parameter | Description                                        | Supported input types                |
| :-------- | :------------------------------------------------- | :----------------------------------- |
| `<value>` | The value to truncate.                             | `INTEGER`, `BIGINT`, `TEXT`, `BYTEA` |
| `<width>` | The truncation width. Must be a positive constant. | `BIGINT`                             |

## Return type

Returns the same type as the input `<value>`:

* `INTEGER` for `INTEGER` input
* `BIGINT` for `BIGINT` input
* `TEXT` for `TEXT` input
* `BYTEA` for `BYTEA` input

## Remarks

The `ICEBERG_TRUNCATE` function can be used in the `PARTITION BY` clause of [`CREATE ICEBERG TABLE`](/reference-sql/commands/data-definition/create-iceberg-table-as-select) commands.

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
CREATE ICEBERG TABLE events
  PARTITION BY (iceberg_truncate(category, 3))
  AS SELECT * FROM source_events
WITH LOCATION = my_iceberg_location;
```

The truncation behavior depends on the input type:

**For integers (`INTEGER`, `BIGINT`):** Returns the largest multiple of `width` that is less than or equal to the value. For negative values, this rounds toward negative infinity.

**For strings (`TEXT`):** Returns the first `width` Unicode code points of the string. If the string is shorter than `width`, returns the original string unchanged.

**For binary (`BYTEA`):** Returns the first `width` bytes of the binary data. If the data is shorter than `width`, returns the original data unchanged.

The `<width>` parameter must be a positive constant value. Using zero, negative values, or non-constant expressions results in an error.

## Example

<div className="query-window">
  ```
  SELECT iceberg_truncate(12345, 100) AS truncated_partition;
  ```

  | truncated\_partition <span>int</span> |
  | :------------------------------------ |
  | 12300                                 |

  <p><span>Rows: 1</span><span>Execution time: 4.81ms</span></p>
</div>
