@@ -41,12 +41,13 @@ This example illustrates the process of setting up a masking policy to selective
4141``` sql
4242-- Create a table and insert sample data
4343CREATE TABLE user_info (
44- id INT ,
45- email STRING
44+ user_id INT ,
45+ phone VARCHAR ,
46+ email VARCHAR
4647);
4748
48- INSERT INTO user_info (
id, email)
VALUES (
1 ,
' [email protected] ' );
49- INSERT INTO user_info (
id, email)
VALUES (
2 ,
' [email protected] ' );
49+ INSERT INTO user_info (
user_id, phone, email)
VALUES (
1 , ' 91234567 ' ,
' [email protected] ' );
50+ INSERT INTO user_info (
user_id, phone, email)
VALUES (
2 , ' 81234567 ' ,
' [email protected] ' );
5051
5152-- Create a role
5253CREATE ROLE ' MANAGERS' ;
6970 END
7071 COMMENT = ' hide_email' ;
7172
73+ CREATE MASKING POLICY phone_mask AS (val nullable(string)) RETURNS nullable(string) - > CASE
74+ WHEN current_role() IN (' MANAGERS' ) THEN val
75+ ELSE ' *********'
76+ END COMMENT = ' hide_phone' ;
77+
7278-- Associate the masking policy with the 'email' column
7379ALTER TABLE user_info MODIFY COLUMN email SET MASKING POLICY email_mask;
7480
81+ -- Associate the masking policy with the 'phone' column
82+ ALTER TABLE user_info MODIFY COLUMN phone SET MASKING POLICY phone_mask;
83+
7584-- Query with the Root user
7685SELECT * FROM user_info;
7786
78- id|email |
79- -- +---------+
80- 2 |********* |
81- 1 |********* |
82- ```
87+ user_id │ phone │ email │
88+ Nullable(Int32) │ Nullable(String) │ Nullable(String) │
89+ ─────────────────┼──────────────────┼──────────────────┤
90+ 2 │ ********* │ ********* │
91+ 1 │ ********* │ ********* │
92+
93+ ```
0 commit comments