CREATE ROW ACCESS POLICY

statementsupportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Object: ROW ACCESS POLICY

Creates a new row access policy in the current/specified schema or replaces an existing row access policy. After creating a row access policy, add the policy to a table using an ALTER TABLE command or a view using an ALTER VIEW command. This command supports the following variants: - CREATE OR ALTER ROW ACCESS POLICY: Creates a row access policy if it doesn’t exist or alters an existing row access policy.

Syntax

supportedpartialnot supportednot scored

Snowflake supports the following syntax to create a row access policy.

CREATE [ OR REPLACE ] ROW ACCESS POLICY [ IF NOT EXISTS ] <name> AS
( <arg_name> <arg_type> [ , ... ] ) RETURNS BOOLEAN -> <body>
[ COMMENT = '<string_literal>' ]

For more information, see CREATE OR ALTER <object>.

CREATE OR ALTER ROW ACCESS POLICY <name> AS
( <arg_name> <arg_type> [ , ... ] ) RETURNS BOOLEAN -> <body>
[ COMMENT = '<string_literal>' ]

Parameters

NameRequiredDescription
namerequiredIdentifier for the row access 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 (for example, “My object”). Identifiers enclosed in double quotes are also case-sensitive. For more details, see Identifier requirements.
{AS ( <arg_name> <arg_type> [ , ... ] )}requiredThe signature for the row access policy. A signature specifies a set of attributes that must be considered to determine whether the row is accessible. The attribute values come from the database object (for example, a table or view) to be protected by the row access policy.
RETURNS BOOLEANrequiredA row access policy must evaluate to true or false. A user that queries a table protected by a row access policy sees rows in the output based on how the body is written.
bodyrequiredSQL expression that operates on the argument values in the signature to determine which rows to return for a query on a table that is protected by a row access policy. The body can be any boolean-valued SQL expression. Snowflake supports expressions that invoke User-defined functions overview, Writing external functions, and expressions that use sub-queries.
COMMENT = 'string_literal'optionalSpecifies a comment for the row access policy. Default: No value

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE ROW ACCESS POLICY | Schema | OWNERSHIP | Row Access Policy | Required to execute a CREATE OR ALTER ROW ACCESS POLICY statement for an existing row access policy. 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 masking policy DDL and privileges, see Managing Column-level Security.

See also