# AGGREGATION POLICY

Config path: `/<database>/<schema>/aggregation_policy/<name>.yaml`

Example:

```yaml
body: |-
  CASE WHEN IS_ROLE_IN_SESSION('SYSADMIN') THEN NO_AGGREGATION_CONSTRAINT()
       ELSE AGGREGATION_CONSTRAINT(MIN_ROW_COUNT => 5, MIN_ENTITY_COUNT => 2)
  END

references:
  - object_type: TABLE
    object_name: test_table_1
    columns: [id]

  - object_type: VIEW
    object_name: test_view_1
    columns: [id]

comment: my aggregation policy
```

## Schema

* <mark style="background-color:red;">**body**</mark> (str) - policy SQL expression
* ~~**references**~~ (dict)
  * **object\_type** (str) - reference object type (e.g. `TABLE`, `VIEW`)
  * **object\_name** (ident) - reference object name
  * **columns** (list)
    * *{items}* (ident) - optional reference column names defining "entity"
* **comment** (str)

## Usage notes

1. Management of aggregation policies requires active warehouse due to unavoidable [POLICY\_REFERENCES](https://docs.snowflake.com/en/sql-reference/functions/policy_references.html) table function calls.
2. Make sure to allow aggregation for role `SYSADMIN`, especially if aggregation policy is being applied to views. Otherwise SnowDDL will have to re-create VIEW on every run due to inability to verify column data types.\
   \
   Example of check: `CASE WHEN IS_ROLE_IN_SESSION('SYSADMIN') THEN NO_AGGREGATION_CONSTRAINT() ELSE ... END`
3. Parameter `references` is deprecated since `0.33.0`. Use policy reference parameters directly in [TABLE](/basic/yaml-configs/table.md) or [VIEW](/basic/yaml-configs/view.md) configs instead.

## Links

* [CREATE AGGREGATION POLICY](https://docs.snowflake.com/en/sql-reference/sql/create-aggregation-policy)
* [SHOW AGGREGATION POLICIES](https://docs.snowflake.com/en/sql-reference/sql/show-aggregation-policies)
* [DESC AGGREGATION POLICY](https://docs.snowflake.com/en/sql-reference/sql/desc-aggregation-policy)
* [Parser & JSON Schema (GitHub)](https://github.com/littleK0i/SnowDDL/blob/master/snowddl/parser/aggregation_policy.py)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.snowddl.com/basic/yaml-configs/aggregation-policy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
