CREATE STORAGE LIFECYCLE POLICY

statementsupportedGovernance (policies, tags, data quality)

docs.snowflake.com ↗

Object: STORAGE LIFECYCLE POLICY

Creates a new storage lifecycle policy in the current or specified schema, or replaces an existing policy. The policy runs an expression on arguments that you specify to determine which rows to expire in the table that the policy is attached to. The arguments in a policy refer to columns in your tables. After you create a policy, use the ALTER TABLE command to add the policy to a table.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] STORAGE LIFECYCLE POLICY [ IF NOT EXISTS ] <name>
  AS ( <arg_name> <arg_type> [ , ... ] )
  RETURNS BOOLEAN -> <body>
  [ ARCHIVE_TIER = { COOL | COLD } ]
  [ ARCHIVE_FOR_DAYS = <number_of_days> ]
  [ COMMENT = '<string_literal>' ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]

Parameters

NameRequiredDescription
namerequiredString that specifies the identifier for the storage lifecycle policy. This must be unique for the schema. 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.
AS ( arg_name arg_type [ , ... ] )requiredThe signature for the policy. You must include at least one argument in the signature. A signature specifies a set of attributes that must be considered to determine whether the row is ready for expiration. The attribute values come from the database object (table).
RETURNS BOOLEAN -> bodyrequiredA storage lifecycle policy must evaluate to true or false. A user that queries a table protected by a storage lifecycle policy sees rows in the output based on how the body is written.
  • body — SQL expression that Snowflake uses to determine which rows to expire. To transform the data, you can use built-in functions such as Conditional expression functions or user-defined functions (UDFs). Note Currently, only SQL and JavaScript UDFs are supported in the body of a storage lifecycle policy.
ARCHIVE_TIER = { COOL | COLD }optionalSpecifies the type of storage tier to use for archiving rows. After you set the ARCHIVE_TIER for a policy, you can’t modify it. For more information, see Archive storage tiers. If you don’t specify this parameter, the policy is an expiration policy that deletes rows without archiving them. COOL requires that you set an archival period (ARCHIVE_FOR_DAYS) of 90 days or longer to enable archiving. COLD requires that you set an archival period (ARCHIVE_FOR_DAYS) of 180 days or longer to enable archiving. For supported cloud providers, see Storage lifecycle policies. Default: No value
ARCHIVE_FOR_DAYS = number_of_daysoptionalSpecifies the number of days to keep rows that match the policy expression in archive storage. If set, Snowflake moves the data into archive storage according to the value you select for ARCHIVE_TIER. If unset, Snowflake expires the rows from the table without archiving the data. Values: ARCHIVE_TIER = COOL: 90 - 2147483647 ARCHIVE_TIER = COLD: 180 - 2147483647 Default: Unset
COMMENT = 'string_literal'optionalSpecifies a comment for the storage lifecycle policy. Default: No value
TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )optionalSpecifies the tag name and the tag string value. The tag value is always a string, and the maximum number of characters for the tag value is 256. For information about specifying tags in a statement, see Tag quotas.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE STORAGE LIFECYCLE POLICY | Schema | None 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.

See also

Referenced by