Row Access Policies
Snowflake · Advanced Security & Governance
Theory
A row access policy is a schema-level object holding a SQL expression that returns TRUE or FALSE for each row. Attached to a table or view with ALTER TABLE orders ADD ROW ACCESS POLICY region_filter ON (region), it is evaluated on every query, and only rows where it returns TRUE are visible. The expression usually checks the current role against a mapping table, for example letting NORTH_SALES see only rows where region = 'NORTH'.
Row access policies are an Enterprise edition feature. A table can have only one row access policy at a time, but one policy can be reused on many tables. When a table has both, the row access policy filters rows first and masking policies then apply to the columns of the remaining rows.
Why we use it
Many teams need the same table but should see only their own slice, such as their region or client. A row policy enforces that centrally, without creating one filtered view or table per team.
When to use it
Use row access policies for multi-region, multi-tenant or need-to-know filtering on shared tables. Use masking policies when users may see the row but not certain values, and secure views for fixed, simple restrictions.
How a Row Policy Filters Data
The policy function returns TRUE or FALSE per row given the current role/context; rows where it returns FALSE are silently excluded from every query against that table, as if they didn't exist.
Row Policies vs Masking Policies
Masking hides the value in a column but still shows the row exists; a row access policy can hide the entire row — the right tool depends on whether unauthorized users should even know a record exists.
Typical Use Case: Regional Data Isolation
A common pattern grants each sales region's role visibility only into rows where region = CURRENT_ROLE()'s mapped region, so one shared table serves every region without duplicating it per team.
How it works
- Query on a table with a row access policy
- Evaluate the policy for each row with the current role
- Does the policy return TRUE for this row? Yes: Row is visible. No: Row is filtered out.
- Apply masking policies to visible rows
- Return only the allowed rows
Example
CREATE OR REPLACE TABLE role_region_access (role_name VARCHAR, allowed_region VARCHAR);
INSERT INTO role_region_access VALUES ('NORTH_SALES','NORTH'), ('SOUTH_SALES','SOUTH');
CREATE OR REPLACE ROW ACCESS POLICY region_filter
AS (region_val VARCHAR) RETURNS BOOLEAN ->
CURRENT_ROLE() IN ('ACCOUNTADMIN','SYSADMIN')
OR EXISTS (SELECT 1 FROM role_region_access WHERE role_name = CURRENT_ROLE() AND allowed_region = region_val);
ALTER TABLE orders ADD ROW ACCESS POLICY region_filter ON (region);Key points
- Row policies hide entire rows, not just column values
- Evaluated automatically on every query against the table
- A mapping table keeps role-to-region rules out of the policy code
- Row access policies apply before masking policies
- Common for multi-region or multi-tenant data isolation