Re: Updating

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: Bob Pawley <rjpawley(at)shaw(dot)ca>
Subject: Re: Updating
Date: 2008-03-17 01:27:36
Message-ID: 200803161827.36449.aklaver@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sunday 16 March 2008 5:36 pm, Bob Pawley wrote:
> Would it be possible to get an example of such coding??
>
> Bob
>
>
> ----- Original Message -----
> From: "Adrian Klaver" <aklaver(at)comcast(dot)net>
> To: <pgsql-general(at)postgresql(dot)org>
> Cc: "Bob Pawley" <rjpawley(at)shaw(dot)ca>
> Sent: Sunday, March 16, 2008 5:14 PM
> Subject: Re: [GENERAL] Updating
>
> > On Sunday 16 March 2008 3:32 pm, Bob Pawley wrote:
> >> Is there a method available for triggering a function after an update on
> >> a
> >> particular column in a table?
> >>
> >> The only way that I have found is to trigger after an update on the
> >> whole table, which of course can lead to problems.
> >>
> >> Bob
> >
> > I trigger can be constrained to fire for each row. Inside the trigger
> > function
> > you can test to see if the column in question has been updated and do the
> > appropriate thing. If the column has not been changed do nothing and
> > RETURN
> > NEW which makes the function non-op.
> > --
> > Adrian Klaver
> > aklaver(at)comcast(dot)net
> >
> > --
> > Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-general

CREATE FUNCTION foo() RETURNS trigger AS
$Body$
BEGIN
IF NEW.colname != OLD.colname THEN
..."Do something"..;
RETURN whatever;
ELSE
RETURN NEW:
END IF;
END;
$Body$ LANGUAGE plpgsql;

CREATE TRIGGER foo_test BEFORE UPDATE ON foo_table FOR EACH ROW EXECUTE
PROCEDURE foo();
--
Adrian Klaver
aklaver(at)comcast(dot)net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tuanhoanganh 2008-03-17 04:37:16 array function problem
Previous Message Harvey, Allan AC 2008-03-17 01:09:27 Re: Updating