PostgreSQL从列中撤消权限

时间:2018-01-05 07:13:02

标签: sql postgresql grant postgresql-9.5

我的PostgreSQL 9.5数据库中有一个名为editor_users的用户组。我的产品表已授予select, insert, update and delete editor_user个成员。

但我想阻止我的id专栏。没有人可能不会更新id列。如何撤消用户的更新权限?

2 个答案:

答案 0 :(得分:1)

您可以为每列提供权限。假设你有一个如下表:

\x48\x31

您可以像这样向CREATE TABLE product ( id serial primary key, mytext text ); 授予权限:

editor_user

答案 1 :(得分:1)

这里有两种选择。第一种是撤销表并授予列。如果您这样做,那么值得使用Indoemation schema或系统目录来发现所有相关列并以编程方式创建授权语句。如果你走这条路线array_aggarray_to_string是你的朋友。

例如你可以:

revoke all on table product from public, ...;
select 'grant insert(' || array_to_string(array_agg(attname), ', ') || ') to ... ;' 
  from pg_attribute
 where attrelid = 'product'::regclass and attnum > 0;

然后将输出复制并粘贴到psql窗口中。

相关问题