CREATE AGGREGATION POLICY
statementsupportedGovernance (policies, tags, data quality)Enterprise+Creates a new aggregation policy in the current/specified schema or replaces an existing aggregation policy. After creating an aggregation policy, assign the aggregation policy to a table using an ALTER TABLE command or a view using an ALTER VIEW command.
Syntax
supportedpartialnot supportednot scored
CREATE [ OR REPLACE ] AGGREGATION POLICY [ IF NOT EXISTS ] <name>
AS () RETURNS AGGREGATION_CONSTRAINT -> <body>
[ COMMENT = '<string_literal>' ]
Parameters
| Name | Required | Description |
|---|---|---|
name | Identifier for the aggregation policy; must be unique for your schema. The identifier value must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g. "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more details, see Identifier requirements. | |
MIN_GROUP_SIZE => integer_expression | Specifies how many rows or entities must be included in the groups returned by a query against the aggregation-constrained table or view. There is a difference between passing a 1 and a 0 as the argument to the function. Both require results to be aggregated. Passing a 1 also requires that each aggregation group contain at least one record from the aggregation-constrained table. So for outer joins, at least one record from the aggregation-constrained table must match a record from an unprotected table. Passing a 0 allows the query to return groups that consist entirely of records from another table. So for outer joins between an aggregation-constrained table and an unprotected table, a group could consist of records from the unprotected table that do not match any records in the aggregation-constrained table. | |
COMMENT = 'string_literal' | Adds a comment or overwrites an existing comment for the aggregation policy. |
Usage notes
- If you want to update an existing aggregation policy and need to see the current body of the policy, run the DESCRIBE AGGREGATION POLICY command or GET_DDL function.
- Regarding metadata: Attention Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.
- The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
- CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.
Access control requirements
A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE AGGREGATION POLICY | Schema | Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control. For additional details on aggregation policy DDL and privileges, see Privileges and commands.