Re: need hint for a trigger...
От | fabrizio.ermini@sysdat.it |
---|---|
Тема | Re: need hint for a trigger... |
Дата | |
Msg-id | 3AB243B9.14342.1AF3320@localhost обсуждение исходный текст |
Ответ на | Re: need hint for a trigger... (Jan Wieck <JanWieck@Yahoo.com>) |
Ответы |
Re: need hint for a trigger...
|
Список | 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 по дате отправления: