CREATE REDACTION POLICY creates a data redaction policy for a table.
1 2 3 | CREATE REDACTION POLICY policy_name ON table_name [ WHEN (when_expression) ] [ ADD COLUMN column_name WITH redaction_function_name ( [ argument [, ...] ] )] [, ... ]; |
Specifies the name of a redaction policy.
Specifies the name of the table to which the redaction policy is applied.
Specifies the expression used for the redaction policy to take effect. The redaction policy takes effect only when this expression is true.
When a query statement is querying a table where a redaction policy is enabled, the redacted data is invisible in the query only if the WHEN expression for the redaction policy is true. Generally, the WHEN clause is used to specify the users for which the redaction policy takes effect.
The WHEN clause must comply with the following rules:
Specifies the name of the table column to which the redaction policy is applied.
Specifies the redaction function applied to the specified table column.
Specifies the list of arguments of the redaction function.
The system provides three built-in redaction functions: MASK_NONE, MASK_FULL, and MASK_PARTIAL. For details about the function specifications, see Data Redaction Functions. You can also define your own redaction functions, which must comply with the following rules:
Built-in redaction functions can cover common redaction scenarios of sensitive information. Therefore, you are advised to use built-in redaction functions to create redaction policies.
Create a table object emp as user alice, and insert data into the table.
1 2 | CREATE TABLE emp(id int, name varchar(20), salary NUMERIC(10,2)); INSERT INTO emp VALUES(1, 'July', 1230.10), (2, 'David', 999.99); |
Create a redaction policy mask_emp for the emp table as user alice to make the salary column invisible to user matu.
1 | CREATE REDACTION POLICY mask_emp ON emp WHEN(current_user = 'matu') ADD COLUMN salary WITH mask_full(salary); |
Grant the SELECT permission on the emp table to user matu as user alice.
1 | GRANT SELECT ON emp TO matu; |
Switch to user matu.
1 | SET ROLE matu PASSWORD '{password}'; |
Query the emp table. Data in the salary column has been redacted.
1 | SELECT * FROM emp; |