UPDATE/INSERT on multiple co-dependent tables
От | Ferindo Middleton Jr |
---|---|
Тема | UPDATE/INSERT on multiple co-dependent tables |
Дата | |
Msg-id | 1100053572.9414.142.camel@scnmaster.sleekcollar.com обсуждение исходный текст |
Ответы |
Re: UPDATE/INSERT on multiple co-dependent tables
|
Список | pgsql-sql |
Is it possible for an UPDATE/INSERT query string to function in such a way that it requires two like fields in differenttables to be equal to/'in sync with' one another: <br /><br /> Example: I have two tables: registration & schedules....<br /> they both record a class_id, start_date, end_date... I want to make sure that if the schedule_id fieldis updated in the registration table; that class_id, start_date & end_date fields automatically change to matchthe schedules.id record in the schedules table.... I've devised a function to handle this but pgsql recognizes the queryto be 'infinitely recursive:<br /><br /> CREATE RULE registration_update AS<br /> ON UPDATE TO registration<br /> DO<br/> UPDATE registration SET class_id = schedules.class_id WHERE new.schedule_id = (SELECT schedules.id FROM schedulesWHERE id = new.schedule_id);<br /><br /> What I'm doing is kind of redundant but necessary for backwards-compatibility<br/><table cellpadding="0" cellspacing="0" width="100%"><tr><td> -- <br /> www.sleekcollar.com<br/> Ferindo Middleton, Jr.<br /> Chief Architect<br /> Sleekcollar Internet Application & ArtisticVisualizations<br /><a href="mailto:ferindo.middleton@sleekcollar.com"><u>ferindo.middleton@sleekcollar.com</u></a></td></tr></table>
В списке pgsql-sql по дате отправления: