Skip to content

Instantly share code, notes, and snippets.

@2tony2
Created June 27, 2025 17:11
Show Gist options
  • Select an option

  • Save 2tony2/4cc21697907e57336ef307c721504a80 to your computer and use it in GitHub Desktop.

Select an option

Save 2tony2/4cc21697907e57336ef307c721504a80 to your computer and use it in GitHub Desktop.
-- Create a masking policy for email addresses
CREATE OR REPLACE MASKING POLICY email_mask AS (val string)
RETURNS string ->
CASE
WHEN CURRENT_ROLE() IN ('ANALYST') THEN val
ELSE REGEXP_REPLACE(val, '.+\@', '*****@')
END;
-- Create a tag for PII data
CREATE TAG pii_email_data;
-- Assign the masking policy to the tag
ALTER TAG pii_email_data SET MASKING POLICY email_mask;
-- Now tag any email column - automatic protection
ALTER TABLE customers MODIFY COLUMN email_address SET TAG pii_email_data = 'sensitive';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment