Re: need hint for a trigger... - Mailing list pgsql-general

From fabrizio.ermini@sysdat.it
Subject Re: need hint for a trigger...
Date
Msg-id 3AB243B9.14342.1AF3320@localhost
Whole thread Raw
In response to Re: need hint for a trigger...  (Jan Wieck <JanWieck@Yahoo.com>)
Responses Re: need hint for a trigger...
List pgsql-general
On 16 Mar 2001, at 9:51, Jan Wieck wrote:

> fabrizio.ermini@sysdat.it wrote:
> >
> > I would like that when a record gets changed in table1, the same
> > changes reflect on the correspondent record in table2. Eventual
> > changes made on the first 3 fields of table2 should be overwritten,
> > leaving the other fields untouched.
>
>     Since  field1 is the key, it seems impossible to identify the
>     row if someone changed field1 in table2. As  long  as  nobody
>     does that,
>
Right. I've taken measures at application level against this
happening, indeed; However, I'll double check them...

>         CREATE FUNCTION table1_upd () RETURNS opaque AS '
>         BEGIN
>             UPDATE table2 SET field1 = NEW.field1,
>                               field2 = NEW.field2,
>                               field3 = NEW.field3
>                    WHERE field1 = OLD.field1;
>             RETURN NEW;
>         END;'
>         LANGUAGE 'plpgsql';
>
>         CREATE TRIGGER table1_upd AFTER UPDATE ON table1
>             FOR EACH ROW EXECUTE PROCEDURE table1_upd ();
>
> Jan
>
Now this is what I call a good example!
Thank you very much Jan, you've saved me a lot of time.

Ciao!


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Fabrizio Ermini               Alternate E-mail:
C.so Umberto, 7               faermini@tin.it
loc. Meleto Valdarno          Mail on GSM: (keep it short!)
52020 Cavriglia (AR)          faermini@sms.tin.it

pgsql-general by date:

Previous
From: Ron Peterson
Date:
Subject: ssl connections with psql
Next
From: Peter Eisentraut
Date:
Subject: Re: ssl connections with psql