更新时间:2024-05-07 GMT+08:00
ALTER ROW LEVEL SECURITY POLICY
功能描述
对已存在的行访问控制策略(包括行访问控制策略的名称,行访问控制指定的用户,行访问控制的策略表达式)进行修改。
注意事项
表的所有者或管理员用户才能进行此操作。
语法格式
修改已存在行访问控制策略的名称
1
|
ALTER [ ROW LEVEL SECURITY ] POLICY policy_name ON table_name RENAME TO new_policy_name; |
修改已存在行访问控制策略的指定用户、策略表达式
1 2 3 |
ALTER [ ROW LEVEL SECURITY ] POLICY policy_name ON table_name [ TO { role_name | PUBLIC } [, ...] ] [ USING ( using_expression ) ]; |
参数说明
示例
--创建数据表all_data。 gaussdb=# CREATE TABLE all_data(id int, role varchar(100), data varchar(100)); --创建行访问控制策略,当前用户只能查看用户自身的数据。 gaussdb=# CREATE ROW LEVEL SECURITY POLICY all_data_rls ON all_data USING(role = CURRENT_USER); gaussdb=# \d+ all_data Table "public.all_data" Column | Type | Modifiers | Storage | Stats target | Description --------+------------------------+-----------+----------+--------------+------------- id | integer | | plain | | role | character varying(100) | | extended | | data | character varying(100) | | extended | | Row Level Security Policies: POLICY "all_data_rls" FOR ALL TO public USING (((role)::name = "current_user"())) Has OIDs: no Options: orientation=row, compression=no --创建用户alice、bob。 gaussdb=# CREATE ROLE alice WITH PASSWORD "********"; gaussdb=# CREATE ROLE bob WITH PASSWORD "********"; --修改行访问控制all_data_rls的名称。 gaussdb=# ALTER ROW LEVEL SECURITY POLICY all_data_rls ON all_data RENAME TO all_data_new_rls; --修改行访问控制策略影响的用户。 gaussdb=# ALTER ROW LEVEL SECURITY POLICY all_data_new_rls ON all_data TO alice, bob; gaussdb=# \d+ all_data Table "public.all_data" Column | Type | Modifiers | Storage | Stats target | Description --------+------------------------+-----------+----------+--------------+------------- id | integer | | plain | | role | character varying(100) | | extended | | data | character varying(100) | | extended | | Row Level Security Policies: POLICY "all_data_new_rls" FOR ALL TO alice,bob USING (((role)::name = "current_user"())) Has OIDs: no Options: orientation=row, compression=no, enable_rowsecurity=true --修改行访问控制策略表达式。 gaussdb=# ALTER ROW LEVEL SECURITY POLICY all_data_new_rls ON all_data USING (id > 100 AND role = current_user); gaussdb=# \d+ all_data Table "public.all_data" Column | Type | Modifiers | Storage | Stats target | Description --------+------------------------+-----------+----------+--------------+------------- id | integer | | plain | | role | character varying(100) | | extended | | data | character varying(100) | | extended | | Row Level Security Policies: POLICY "all_data_new_rls" FOR ALL TO alice,bob USING (((id > 100) AND ((role)::name = "current_user"()))) Has OIDs: no Options: orientation=row, compression=no, enable_rowsecurity=true --删除用户alice、bob。 gaussdb=# DROP ROLE alice, bob; --删除访问控制策略。 gaussdb=# DROP ROW LEVEL SECURITY POLICY all_data_new_rls ON all_data; --删除数据表all_data。 gaussdb=# DROP TABLE all_data;
父主题: SQL语法