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

  1. Query on a table with a row access policy
  2. Evaluate the policy for each row with the current role
  3. Does the policy return TRUE for this row? Yes: Row is visible. No: Row is filtered out.
  4. Apply masking policies to visible rows
  5. 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

Snowflake topics

Snowflake Fundamentals

Warehouses & Performance

Staging & SnowSQL

Tables & Data Handling

Cloud Integrations

Storage & Optimization

Security & Governance

Views, Pipelines & Automation

Data Types & SQL Fundamentals

Semi-Structured Data Deep Dive

Advanced Features

Data Sharing & Collaboration

Cost Management & Monitoring

Databases, Schemas & Objects

Performance Deep Dive

Advanced Security & Governance

Stored Procedures & UDFs

Ecosystem & Integrations

SnowPro Certification Prep

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Mastering Snowflake

The modern data cloud, from architecture to SnowPro certification. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Snowflake SQL Sharpen the SQL you use in Snowflake: 150 query problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Snowflake  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

{{ sec.h }}

{{ sec.body }}

{{ sec.body }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
Want to run this yourself? Unlike the SQL and Python courses, Snowflake needs a real account — there's no in-browser engine for it. Click Copy above, then paste it into a free Snowflake trial (30 days, no card required) and run it in Snowsight.
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic