CREATE AGGREGATION POLICY

statementsupportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Object: AGGREGATION POLICY

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

NameRequiredDescription
nameIdentifier 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_expressionSpecifies 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

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.

See also