Re: Postgres trigger side-effect is occurring out of order withrow-level security select policy - Mailing list pgsql-general

From Charles Clavadetscher (SwissPUG)
Subject Re: Postgres trigger side-effect is occurring out of order withrow-level security select policy
Date
Msg-id 92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com
Whole thread Raw
In response to Re: Postgres trigger side-effect is occurring out of order withrow-level security select policy  ("Charles Clavadetscher (SwissPUG)" <clavadetscher@swisspug.org>)
Responses Re: Postgres trigger side-effect is occurring out of order withrow-level security select policy  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-general
An addition


On 01.10.2018 05:18:15, Charles Clavadetscher (SwissPUG) <clavadetscher@swisspug.org> wrote:

Hello


On 01.10.2018 05:00:02, Carl Sverre <sverre.carl@gmail.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@charles.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

pgsql-general by date:

Previous
From: "Charles Clavadetscher (SwissPUG)"
Date:
Subject: Re: Postgres trigger side-effect is occurring out of order withrow-level security select policy
Next
From: Arup Rakshit
Date:
Subject: Re: Why my query not using index to sort?