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

# OBJECT_AGG

> Combines key/VARIANT pairs into an object.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Aggregate · Window</span></div>

Rows with NULL key or SQL-NULL value are ignored. Duplicate keys raise an error. DISTINCT removes identical key/value tuples only.

## Syntax

A window function keeps each input row and adds a result for that row. `PARTITION BY` groups rows with matching values; without it, all input rows form one group.

### Aggregate

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
object_agg(key, value)
```

### Window

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
object_agg(key, value) OVER ([PARTITION BY key] [ORDER BY ordering_key] [ROWS frame])
```

* Use a frame that includes all rows in the group or starts at the first row (`UNBOUNDED PRECEDING`). Sliding frames that drop earlier rows are not supported. RANGE frames with a numeric or time offset are not supported.

## Arguments

### Aggregate and window

| Name | Type | Required | Description |
| - | - | - | - |
| key | STRING | Yes | Object field key. |
| value | VARIANT | Yes | Object field value. |

## Returns

* Type: VARIANT
* NULL behavior: Rows with NULL key or SQL-NULL value are ignored. Duplicate keys raise an error. DISTINCT removes identical key/value tuples only.
* Empty input: Returns an empty object on empty input.
* Shape: VARIANT object containing retained keys and values.
* Ordering: Object field order is unspecified.

## Properties

| Property | Value |
| - | - |
| Deterministic | Partial (Unique-key logical mappings follow the inputs, but member ordering/display is not guaranteed.) |
| Supports DISTINCT | Partial (Removes duplicates in grouped aggregation only.) |
| Supports window usage | Partial (Use all rows in the group or start at its first row. Sliding frames and RANGE offsets are not supported.) |
| Supports window frames | Partial (Use all rows in the group or start at its first row. Sliding frames and RANGE offsets are not supported.) |
| Exact result | Yes |

## Usage notes

* With DISTINCT the same key plus different values still errors.
* DISTINCT removes duplicates in grouped aggregation. Do not use it to remove duplicates in a window call.

## Examples

### Build a VARIANT object

* The table displays the logical VARIANT object; object key order and client formatting can differ.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH t("key","value") AS (VALUES ('k1','"v1"'),('k2','"v2"')) SELECT object_agg("key",parse_json("value")) AS result FROM t;
```

| result |
| - |
| \{"k1":"v1","k2":"v2"} |

### Build an object with numeric and boolean values

Object key order and client formatting can differ.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH sample(k, v) AS (VALUES ('count', '2'), ('active', 'true'))
SELECT object_agg(k, parse_json(v)) AS result FROM sample;
```

| result |
| - |
| \{"count":2,"active":true} |

## Limitations

* Sliding windows that drop earlier rows are not supported. Start the frame at the first row in the group.
* The value must already be VARIANT; other values need explicit conversion.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.