CREATE DATA MOVEMENT RULE¶
Creates a new data movement rule in the current/specified schema or replaces an existing data movement rule.
A data movement rule controls a single movement type and returns the maximum number of rows that the movement type can move. After you create a data movement rule, add it to a data movement policy so that Snowflake enforces or reports on it.
Syntax¶
Required parameters¶
nameString that specifies the identifier (that is, name) for the data movement rule; must be unique for the schema in which the data movement rule is created.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more information, see Identifier requirements.
TYPE = 'movement_type'Specifies the movement type that the rule controls. A rule controls exactly one movement type.
Supported values:
COPY_INTO_EXTERNAL_STAGE- Rows unloaded to an external stage with COPY INTO <location>.COPY_INTO_INTERNAL_STAGE- Rows unloaded to an internal stage with COPY INTO <location>.SNOWSIGHT_UI- Rows returned to the Snowsight worksheet results grid.AGENT_ACCESS- Rows accessed by an agent.UI_DOWNLOAD- Rows downloaded via the Download button in Snowsight (workspace results pane, notebook cells, and Query History). Does not apply to all download surfaces; for example, downloads in Streamlit apps, notebooks in the Visual Studio Code extension, the Export as HTML option in workspaces, and CoWork are not covered.PROGRAMMATIC_FETCH- Rows fetched programmatically, for example through a driver or connector.
MAX_ROWS AS () RETURNS INTEGER -> ( expression )SQL expression body that returns an INTEGER, which sets the maximum number of rows that the movement type can move.
The return value determines the behavior:
NULL- No limit on the number of rows.0- Block the movement.- A positive integer - The maximum number of rows that the movement type can move.
The expression can contain CASE and other logic statements. It can call SYS_CONTEXT to read session and movement context and adjust the returned limit accordingly.
Optional parameters¶
COMMENT = 'string_literal'Specifies a comment for the data movement rule.
Default: No value
Access control requirements¶
A role used to execute this operation must have the following privileges at a minimum:
| Privilege | Object | Notes |
|---|---|---|
| CREATE DATA MOVEMENT RULE | 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.
Usage notes¶
- A rule can’t appear in both the
ENFORCE_RULESandALERT_RULESof a data movement policy at the same time. - A data movement policy can have at most one rule per movement type in each of
ENFORCE_RULESandALERT_RULES. - A
UI_DOWNLOADrule can only be used inENFORCE_RULES, not inALERT_RULES. - The MAX_ROWS expression body can use SYS_CONTEXT to read session and movement context.
- GET_DDL is supported for this object type. If you want to update an existing data movement rule and need to see its current definition, run the GET_DDL function.
- 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.
-
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.
Examples¶
Create a rule that lets the COMP_TEAM_ROLE role unload any number of rows to an external stage, but blocks all other
roles:
Create a rule that caps unloads to an external stage at 1000 rows: