行级安全性 - 更新行
嗨,我正在与Postgres合作,我有一个角色“ my_role”,我想仅在我的Corporate_ID与其他表相关的情况下从一个表中更新记录。
我想为人表创建一个政策,我从公司表中有一个corporate_id来驱动以获取此信息,这就是这样的事情:
SELECT * FROM person p
INNER JOIN person_brand a ON p.person_id=a.person_id
INNER JOIN brand b ON a.brand_id=b.brand_id
INNER JOIN corporate c on b.corporate_id=c.corporate_id
WHERE c.corporate_id=corporate_id
我的政策将是这样的:
ALTER TABLE core.person ENABLE ROW LEVEL SECURITY;
CREATE POLICY person_corporation_all
ON person
AS PERMISSIVE
FOR UPDATE
TO "my_role"
USING (EXISTS(SELECT 1 FROM person p
INNER JOIN person_brand a ON p.person_id=a.person_id
INNER JOIN brand b ON a.brand_id=b.brand_id
INNER JOIN corporate c on b.corporate_id=c.corporate_id
WHERE c.corporate_id=corporate_id));
但是请告诉我这个错误:
ERROR: column reference "corporate_id" is ambiguous
SQL state: 42702
我需要什么将变量发送到我的查询中?
问候
Hi I am working with Postgres, I have one role "my_role", and I want to update records from one table only where my corporate_id is related to other table.
I want to create a Policy to person table, and I have a corporate_id from my corporate table to drive to get this information would be something like these:
SELECT * FROM person p
INNER JOIN person_brand a ON p.person_id=a.person_id
INNER JOIN brand b ON a.brand_id=b.brand_id
INNER JOIN corporate c on b.corporate_id=c.corporate_id
WHERE c.corporate_id=corporate_id
I my policy will be something like these:
ALTER TABLE core.person ENABLE ROW LEVEL SECURITY;
CREATE POLICY person_corporation_all
ON person
AS PERMISSIVE
FOR UPDATE
TO "my_role"
USING (EXISTS(SELECT 1 FROM person p
INNER JOIN person_brand a ON p.person_id=a.person_id
INNER JOIN brand b ON a.brand_id=b.brand_id
INNER JOIN corporate c on b.corporate_id=c.corporate_id
WHERE c.corporate_id=corporate_id));
But show me this error:
ERROR: column reference "corporate_id" is ambiguous
SQL state: 42702
What I need to send as variable into my query?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您将有一个嵌套策略,因为在验证中您有
person
表,您需要将其删除,并使用表person
的名称介绍列。 , 例如:You will have a nested policy because inside the verification you have the
person
table again, you will need to remove it, and refers to the columns using the name of the tableperson
, for example: