Re: Create a trigger only for certain users

From: Ezequiel Luis Pellettieri <ezequiel(dot)pellettieri(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Create a trigger only for certain users
Date: 2016-05-14 00:26:46
Message-ID: CAGsySmg+qcK8j+XAWXzH34TydgWGeSjEX9K3J_n9hCVE_t19gg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thank you so very much Adrian for your answer. I'm still in 9.2 but I'll
give it a try on 1 and 2 and let you know how it goes.
The main goal for this trigger is to audit activity in certain tables for
only 2 users in the database.
Cheers
Pelle.-

2016-05-11 11:22 GMT-03:00 Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>:

> 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(dot)klaver(at)aklaver(dot)com
>

--

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2016-05-14 01:50:56 Re: is this a good approach?
Previous Message Michael Moore 2016-05-13 23:52:13 please ignore question 1 in my previous post