From: | fabrizio(dot)ermini(at)sysdat(dot)it |
---|---|
To: | Jan Wieck <JanWieck(at)Yahoo(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: need hint for a trigger... |
Date: | 2001-03-16 15:47:53 |
Message-ID: | 3AB243B9.14342.1AF3320@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 16 Mar 2001, at 9:51, Jan Wieck wrote:
> fabrizio(dot)ermini(at)sysdat(dot)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(at)tin(dot)it
loc. Meleto Valdarno Mail on GSM: (keep it short!)
52020 Cavriglia (AR) faermini(at)sms(dot)tin(dot)it
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2001-03-16 16:10:20 | Re: ssl connections with psql |
Previous Message | Ron Peterson | 2001-03-16 14:59:44 | ssl connections with psql |