Re: Shorthand syntax for triggers

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Joe Van Dyk <joe(at)tanga(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Shorthand syntax for triggers
Date: 2012-10-10 20:28:41
Message-ID: CAL_0b1tpJbeubKrhp9Nme=fYFJU2PG9q+2c_-FsBsZ7A7m-q4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 10, 2012 at 9:22 AM, Joe Van Dyk <joe(at)tanga(dot)com> wrote:
> I wish I could do:
>
> create trigger some_trigger after insert on products
> execute procedure do $$ begin
> insert into audits values (CHANGED.value);
> end $$ language plpgsql;

IF TG_OP = 'DELETE' THEN RENAME OLD TO myrow;
ELSE RENAME NEW TO myrow; END IF;

and then use

insert into audits values (myrow.value);

>
>
> Changes/improvements:
>
> 1. Triggers default to 'for each row'
>
> 2. Triggers can use anonymous functions
>
> 3. Triggers can access a special CHANGED value that's either NEW for insert
> or updates, or OLD for deletes.
>
> 4. Default for 'after insert' triggers is to return null, as I believe it
> doesn't matter what you return here.
>
> 5. Way less repetitive typing.
>
>
> Thoughts? Is this a terrible idea?

--
Sergey Konoplev

a database and software architect
http://www.linkedin.com/in/grayhemp

Jabber: gray(dot)ru(at)gmail(dot)com Skype: gray-hemp Phone: +14158679984

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2012-10-10 21:06:45 Re: [GENERAL] pg_upgrade not detecting version properly
Previous Message Alban Hertroys 2012-10-10 18:11:38 Re: pymssql Connection to the database failed for an unknown reason