行级安全性 - 更新行

发布于 01-23 06:47 字数 1029 浏览 2 评论 0原文

嗨,我正在与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声2025-01-30 06:47:41

您将有一个嵌套策略,因为在验证中您有person表,您需要将其删除,并使用表person的名称介绍列。 , 例如:

CREATE POLICY person_corporation_all
    ON person
    AS PERMISSIVE
    FOR UPDATE
    TO "my_role"
    USING (EXISTS(SELECT 1 FROM person_brand a 
                  INNER JOIN brand b ON a.brand_id=b.brand_id 
                  INNER JOIN corporate c on b.corporate_id=c.corporate_id
                 WHERE a.person_id=person.person_id and  c.corporate_id=person.corporate_id));

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 table person, for example:

CREATE POLICY person_corporation_all
    ON person
    AS PERMISSIVE
    FOR UPDATE
    TO "my_role"
    USING (EXISTS(SELECT 1 FROM person_brand a 
                  INNER JOIN brand b ON a.brand_id=b.brand_id 
                  INNER JOIN corporate c on b.corporate_id=c.corporate_id
                 WHERE a.person_id=person.person_id and  c.corporate_id=person.corporate_id));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文