Skip site navigation (1) Skip section navigation (2)

Re: Update and trigger

From: "Medi Montaseri" <montaseri(at)gmail(dot)com>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Update and trigger
Date: 2008-06-11 07:54:55
Message-ID: 8078a1730806110054o693aab9ifa284cbb56af5b04@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
Thanks...but a difference seems to be that the rule is not specific to
update on a particular col but any col of a row getting updated...

Thanks

On Tue, Jun 10, 2008 at 10:21 PM, A. Kretschmer <
andreas(dot)kretschmer(at)schollglas(dot)com> wrote:

> am  Tue, dem 10.06.2008, um 18:45:51 -0700 mailte Medi Montaseri folgendes:
> > Hi,
> >
> > I need to increament a counter such as myTable.Counter of type integer
> > everytime myTable.status a boolean column is updated. Can you help me
> complete
> > this...
> >
> > create trigger counter_trigger after update on myTable.counter
> > execute procedure 'BEGIN statement; statement; statement END'
>
> much simpler, use a RULE instead a TRIGGER like my example:
>
> Suppose, i have a table called foo, it contains now:
>
> test=# select * from foo;
>  i
> ---
>  1
>  2
> (2 rows)
>
>
> I create a sequence and a RULE:
>
> test=*# create sequence foo_counter;
> CREATE SEQUENCE
> test=*# create or replace rule foo_update as on update to foo do also
> select nextval('foo_counter');
> CREATE RULE
>
>
> And now i do a update on foo:
>
>
> test=*# update foo set i=2;
>  nextval
> ---------
>       1
> (1 row)
>
> test=*# update foo set i=3;
>  nextval
> ---------
>       2
> (1 row)
>
>
> test=*# select currval('foo_counter');
>  currval
> ---------
>       2
> (1 row)
>
>
>
> Andreas
> --
> Andreas Kretschmer
> Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
> GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

pgsql-sql by date

Next:From: A. KretschmerDate: 2008-06-11 08:35:51
Subject: Re: Update and trigger
Previous:From: Craig RingerDate: 2008-06-11 05:35:32
Subject: Re: Update and trigger

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group