如何在 postgresql 表中的某些指定行上授予更新或选择权限?

hap*_*Sun 2 postgresql grant

我想在我的 Postgresql 数据库中创建一些角色并授予一些访问权限。

我有学生角色,我想授予此用户类型:只能编辑学生表中关于他/她的记录,不能编辑其他行

我该怎么做?

谢谢

Boh*_*ian 5

使用适当的 where 子句在表上创建一个视图,然后授予访问权限:

create view students_view as
select col1, col2, col3 -- limit column access here
from mytable
where <whatever>; -- limit row access here

-- limit what he can do here
grant update, select to student_role;
Run Code Online (Sandbox Code Playgroud)

顺便说一句,您不能更新视图是一种普遍存在的误解,但只有当视图是连接或类似复杂的查询时才如此。