pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedFrom: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ezequiel Luis Pellettieri <ezequiel.pellettieri@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Create a trigger only for certain users
Date: Wed, 11 May 2016 07:22:15 -0700
Message-ID: <e2c2bbac-4279-f680-f4d6-e093de9ae611@aklaver.com> (raw)
In-Reply-To: <CAGsySmgA1hEa_viRUZGbgJp7ZfGDQWXmcSSjUtyyCA7uvED01w@mail.gmail.com>
References: <CAGsySmgA1hEa_viRUZGbgJp7ZfGDQWXmcSSjUtyyCA7uvED01w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (4+ messages) latest in thread
Message-ID: <e2c2bbac-4279-f680-f4d6-e093de9ae611@aklaver.com>
Permalink: ../e2c2bbac-4279-f680-f4d6-e093de9ae611@aklaver.com/
Also on: postgresql.org/message-id/e2c2bbac-4279-f680-f4d6-e093de9ae611@aklaver.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: adrian.klaver@aklaver.com, ezequiel.pellettieri@gmail.com
Subject: Re: Create a trigger only for certain users
In-Reply-To: <e2c2bbac-4279-f680-f4d6-e093de9ae611@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox