Skip to content

Commit 316e7c6

Browse files
authored
Update create-mask-policy.md (#2253)
multi column use mask policy
1 parent c88c4a4 commit 316e7c6

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

docs/en/sql-reference/10-sql-commands/00-ddl/12-mask-policy/create-mask-policy.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
4343
CREATE 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
5253
CREATE ROLE 'MANAGERS';
@@ -69,14 +70,24 @@ AS
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
7379
ALTER 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
7685
SELECT * 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

Comments
 (0)