数据库中有 3 个表 - 部门、员工、帐户。一个部门有很多员工。Employee 包含列department_id bigint
Account 表包含列login varchar
,employee_id bigint
用于将 Postgres 用户(角色)绑定到 Employee 中的行。
我的目标是让用户只看到和使用那些值department_id
与用户相同的 Employee 行。
必须有类似的东西:
CREATE POLICY locale_policy ON employee
TO justuser, operator
USING (department_id =
(SELECT department_id FROM employee WHERE id =
(SELECT employee_id FROM account WHERE login = CURRENT_USER)
)
)
但是由于来自 Employee 的子查询,它正在提高infinite recursion detected in policy for relation employee
.
编辑:关系由以下定义:
create table department(
id serial primary key);
create table employee(
id serial primary key,
department_id int8 not null references department(id));
create table account(
id serial primary key,
login varchar(100) not null unique,
employee_id int8 not null unique references employee(id));