Module 18 · Lesson 6 of 10Detailed study · about 38 min

Snowflake projection, aggregation and join policies

Use privacy controls to limit returned columns, minimum group sizes and permitted join keys with three practical tests.

Before you beginSet up the Maple Market governance lab

Choose which part of the query to restrict

The restaurant and retail teams at Maple Market can exchange summary information with a fulfillment partner. The partner needs a match count and revenue by region. The partner has no business reason to list individual email addresses or single-customer sales. Choose which operations to allow, and share the smallest useful dataset.

These three examples use separate disposable tables to expose one policy at a time. Run as the schema and table owner in Enterprise Edition or higher. Creating each policy needs its named CREATE privilege on the schema. Attaching needs account-level APPLY for that policy type or policy-level APPLY plus ownership of the object. The lab uses the specific policy privileges. Snowflake currently marks Join Policies as open preview. Projection and aggregation are documented Enterprise features.

What each policy protects
PolicyQuestionExamples of reach
MaskingWhat value can this role read?Replace an email with REDACTED or a domain
Row accessWhich rows can this role see?Show India sales only
ProjectionMay this field appear in the final output?Fail when EMAIL is selected
AggregationHow small can a result group be?Combine small groups into a remainder
JoinMust the query join, and on which keys?Require a match on MATCH_ID

Projection policy for a column that cannot appear in results

Projection means choosing the columns returned to the reader. On the scratch table, SELECT CUSTOMER_ID works and produces 101 and 102. SELECT EMAIL fails because the policy forbids EMAIL in the final result. ENFORCEMENT = FAIL is the default. NULLIFY is another option when callers need a stable column shape with NULL values.

A projection restriction does not protect every use of the data inside a query. Snowflake documents permitted filters and joins for certain shapes, which can expose information indirectly. For data a partner should never use, omit it from the approved object. Do not grant a path to the same unprotected field.

SQL · runnable example
USE ROLE M18_OWNER;
USE SCHEMA LS_M18_GOV_LAB.GOV;
CREATE TABLE PROJECTION_TEST (CUSTOMER_ID NUMBER, EMAIL VARCHAR);
INSERT INTO PROJECTION_TEST VALUES (101,'asha@example.invalid'),(102,'luc@example.invalid');
CREATE PROJECTION POLICY NO_EMAIL AS () RETURNS PROJECTION_CONSTRAINT ->
  PROJECTION_CONSTRAINT(ALLOW => FALSE, ENFORCEMENT => 'FAIL');
GRANT APPLY ON PROJECTION POLICY NO_EMAIL TO ROLE M18_OWNER;
ALTER TABLE PROJECTION_TEST MODIFY COLUMN EMAIL SET PROJECTION POLICY NO_EMAIL;
SELECT CUSTOMER_ID FROM PROJECTION_TEST ORDER BY CUSTOMER_ID;

Verify that the protected projection fails

Run separately. Expect a projection policy violation. An ordinary object-access denial means you did not reach the policy test.

SQL · runnable example
SELECT EMAIL FROM LS_M18_GOV_LAB.GOV.PROJECTION_TEST;

Aggregation policy for group-size protection

A group of one reveals one record. A policy with MIN_GROUP_SIZE => 2 requires at least two input records per group in this teaching exercise. The India group has two orders and returns 180. Europe and US each have one order, so Snowflake pools them into a remainder with a NULL region label and a total of 350. If the remainder itself is too small, its values are suppressed.

This small threshold is for learning. When one person has multiple records, a row count can overstate privacy. Product support for entity-level aggregation lets you specify the entity key on supported objects. Carefully choose an identifier and threshold. Some queries, including window functions on the constrained data, are restricted. Group rules alone cannot guarantee protection against repeated comparisons of results.

Expected aggregation result
REGIONREVENUE
IN180
NULL (remainder)350
SQL · runnable example
USE SCHEMA LS_M18_GOV_LAB.GOV;
CREATE TABLE AGG_TEST (REGION VARCHAR, AMOUNT NUMBER);
INSERT INTO AGG_TEST VALUES ('IN',100),('IN',80),('EU',200),('US',150);
CREATE AGGREGATION POLICY AT_LEAST_TWO AS () RETURNS AGGREGATION_CONSTRAINT ->
  AGGREGATION_CONSTRAINT(MIN_GROUP_SIZE => 2);
GRANT APPLY ON AGGREGATION POLICY AT_LEAST_TWO TO ROLE M18_OWNER;
ALTER TABLE AGG_TEST SET AGGREGATION POLICY AT_LEAST_TWO;
SELECT REGION, SUM(AMOUNT) AS REVENUE FROM AGG_TEST
GROUP BY REGION ORDER BY REGION NULLS LAST;

Verify that individual amounts are not returned

Run only this negative check. It fails because there is no aggregation.

SQL · runnable example
SELECT REGION, AMOUNT FROM LS_M18_GOV_LAB.GOV.AGG_TEST;

Join policy for an approved match key

Require an explicit join on MATCH_ID and keep the example’s input free of direct contact fields. JOIN_REQUIRED specifies whether a join is necessary. ALLOWED JOIN KEYS belongs on the protected table or view, where Snowflake knows the column names. Our match connects ID 101 and returns North route. ID 102 has no approved peer.

A join policy restricts the query shape and keys. The consumer still needs SELECT on the objects it queries. A successful join may return other columns unless another control protects them. Check alternate objects and joins as part of review. Review preview constraints and supported join shapes before using the feature in production.

Expected match
MATCH_IDROUTE_NAME
101North route
SQL · runnable example
USE SCHEMA LS_M18_GOV_LAB.GOV;
CREATE JOIN POLICY MATCH_ONLY AS () RETURNS JOIN_CONSTRAINT ->
  JOIN_CONSTRAINT(JOIN_REQUIRED => TRUE);
GRANT APPLY ON JOIN POLICY MATCH_ONLY TO ROLE M18_OWNER;
CREATE TABLE JOIN_TEST (MATCH_ID NUMBER, SEGMENT VARCHAR);
CREATE TABLE ROUTE_MAP (MATCH_ID NUMBER, SEGMENT VARCHAR, ROUTE_NAME VARCHAR);
INSERT INTO JOIN_TEST VALUES (101,'priority'),(102,'regular');
INSERT INTO ROUTE_MAP VALUES (101,'priority','North route'),(104,'regular','West route');
ALTER TABLE JOIN_TEST SET JOIN POLICY MATCH_ONLY ALLOWED JOIN KEYS (MATCH_ID);
SELECT J.MATCH_ID, R.ROUTE_NAME
FROM JOIN_TEST J INNER JOIN ROUTE_MAP R ON J.MATCH_ID = R.MATCH_ID;

Verify both denied join shapes

Run the two SELECT statements separately. The first fails because a join is required. The second fails because SEGMENT is not an allowed key.

SQL · runnable example
SELECT MATCH_ID FROM LS_M18_GOV_LAB.GOV.JOIN_TEST;
SELECT J.MATCH_ID FROM LS_M18_GOV_LAB.GOV.JOIN_TEST J
JOIN LS_M18_GOV_LAB.GOV.ROUTE_MAP R ON J.SEGMENT = R.SEGMENT;

Release a privacy policy only after checking the approved answer

Review the permitted reader role, result columns, cohort sizes and match keys. Test the query users actually run. Have a partner contract and a process for investigating unexpected access. Keep the test tables private and use the capstone cleanup to remove the disposable database.

A common release error is applying a restriction to a view while still granting access to its unrestricted base table. Inspect the grants on both surfaces and repeat the allowed and forbidden query as the actual reader. Data minimization, separate policy controls and audit evidence work together.

Design a privacy-preserving query surface Choose the permitted result before granting a reader access.
  1. Private sourceSelect the required data to Minimal partner dataset
  2. Minimal partner datasetApply explicit query rules to Policy checks
  3. Policy checksTest both outcomes to Reader tests
Private source
Contains the full approved data.
Minimal partner dataset
Includes only necessary fields.
Policy checks
Allow projection, aggregation and joins for the intended use.
Reader tests
Keep permitted output and expected denials.

Interview practice

Explain the decision and the evidence you would use to test it.

How do a masking policy and a projection policy differ?

A mask can return a substituted value. A projection policy controls whether the column appears in the final result at all, or whether it returns NULL under a nullify rule.

What is the NULL region in the aggregate exercise?

It marks the remainder group. Europe and US were individually too small, but combined they satisfy the minimum. The total 350 is for both and does not name either group.

Would a join policy make a partner analysis private by itself?

I would restrict the source fields and the applicable join key, then review the result shape and partner access paths. A permitted join still returns whatever the rest of the approved query can expose.

Words used in this lesson
Projection policy
Controls which columns can appear in the final result.
Aggregation policy
Requires results to combine a minimum group of input records or entities.
Join policy
Requires a join and can limit the join keys.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 1

Snowflake projection, aggregation and join policies

Private source
Minimal partner dataset
Policy checks
Reader tests

Design a privacy-preserving query surface

Choose the permitted result before granting a reader access.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Design a privacy-preserving query surface

    Choose the permitted result before granting a reader access.

    Private source → Minimal partner dataset → Policy checks → Reader tests

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

All records are fictional. Outputs are expected or simulated. Live practice needs an authorized scratch account, test roles, an approved warehouse and the editions listed in the lesson.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

What happens to the two one-sale groups when the minimum group size is two?

Try it yourself

Choose a policy and a separate safety control for a partner that matches accounts by an approved ID.

Compare your reasoning

Require the approved join key and give the partner a view or table containing only the fields needed for matching. Verify direct reads and other keys fail.

Connect this lesson to the learning path

Official sources and curriculum

Module 18 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab