Re: Shorthand syntax for triggers - Mailing list pgsql-general

From Sergey Konoplev
Subject Re: Shorthand syntax for triggers
Date
Msg-id CAL_0b1tpJbeubKrhp9Nme=fYFJU2PG9q+2c_-FsBsZ7A7m-q4A@mail.gmail.com
Whole thread Raw
In response to Shorthand syntax for triggers  (Joe Van Dyk <joe@tanga.com>)
Responses Re: Shorthand syntax for triggers
List pgsql-general
On Wed, Oct 10, 2012 at 9:22 AM, Joe Van Dyk <joe@tanga.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.ru@gmail.com Skype: gray-hemp Phone: +14158679984


pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: pymssql Connection to the database failed for an unknown reason
Next
From: Gavin Flower
Date:
Subject: Re: Index only scan