Re: Postgres trigger side-effect is occurring out of order with row-level security select policy

From: "Charles Clavadetscher (SwissPUG)" <clavadetscher(at)swisspug(dot)org>
To: "Carl Sverre" <sverre(dot)carl(at)gmail(dot)com>
Cc: "Adrian Klaver" <adrian(dot)klaver(at)aklaver(dot)com>, "" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Postgres trigger side-effect is occurring out of order with row-level security select policy
Date: 2018-10-01 03:53:58
Message-ID: 92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

An addition

On 01.10.2018 05:18:15, Charles Clavadetscher (SwissPUG) <clavadetscher(at)swisspug(dot)org> wrote:
Hello

On 01.10.2018 05:00:02, Carl Sverre <sverre(dot)carl(at)gmail(dot)com> wrote:
Thank you for the detailed report Charles. I think you may be missing the “returning id” clause in the insert. Can you verify it works when you use “returning id”? Thanks!
[Charles] : You are right:

testuser(at)charles(dot)localhost=> INSERT INTO a VALUES ('fails2') RETURNING id;
NOTICE:  inside trigger handler
ERROR:  new row violates row-level security policy for table "a"

This implies that the returning_id is evaluated before the trigger executes, i.e. Adrian's assumption is probably correct.

Regards
Charles
[Charles] : In the RLS documentation (https://www.postgresql.org/docs/current/static/ddl-rowsecurity.html)

"To specify which rows are visible or modifiable according to a policy, an expression is required that returns a Boolean result. This expression will be evaluated for each row prior to any conditions or functions coming from the user's query."

I assume that the returning clause is essentially a condition or function from the user query or it is implemented as such. Therefore the policy is applied prior to it.
The most knowlegdable person on this list on the RLS topic is Stephen Frost. He may shed light on the matter.

Regards
Charles

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arup Rakshit 2018-10-01 04:26:48 Re: Why my query not using index to sort?
Previous Message Charles Clavadetscher (SwissPUG) 2018-10-01 03:18:15 Re: Postgres trigger side-effect is occurring out of order with row-level security select policy