Re: Create a trigger only for certain users - Mailing list pgsql-sql

From Adrian Klaver
Subject Re: Create a trigger only for certain users
Date
Msg-id e2c2bbac-4279-f680-f4d6-e093de9ae611@aklaver.com
Whole thread Raw
In response to Create a trigger only for certain users  (Ezequiel Luis Pellettieri <ezequiel.pellettieri@gmail.com>)
Responses Re: Create a trigger only for certain users
List pgsql-sql
On 05/11/2016 07:12 AM, Ezequiel Luis Pellettieri wrote:
> Hi guys, I'm going to build a trigger on update for a few tables, but I
> have to ignore updates for certain users. Is there a way to accomplish
> this task?


A thought, assuming plpgsql:

1) Use session_user/current_user:
http://www.postgresql.org/docs/9.5/interactive/functions-info.html

2) In BEFORE trigger code:
http://www.postgresql.org/docs/9.5/interactive/plpgsql-trigger.html

test for the user and return NULL if there is a match:

"Row-level triggers fired BEFORE can return null to signal the trigger 
manager to skip the rest of the operation for this row (i.e., subsequent 
triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for 
this row)."

Another thought, assuming Postgres 9.5+:

Use Row Level Security:

http://www.postgresql.org/docs/9.5/static/sql-createpolicy.html

>
> Thanks in advance.
>
> Regards.
> Pelle.-
>
> --
> *
> *
> *
> *
> *
> *


-- 
Adrian Klaver
adrian.klaver@aklaver.com



pgsql-sql by date:

Previous
From: Ezequiel Luis Pellettieri
Date:
Subject: Create a trigger only for certain users
Next
From: Michael Moore
Date:
Subject: Re: python install defies all efforts and leaves programmer a broken shell of a man