UPDATE/INSERT on multiple co-dependent tables - Mailing list pgsql-sql

From Ferindo Middleton, Jr
Subject UPDATE/INSERT on multiple co-dependent tables
Date
Msg-id 000c01c4c6ce$03da7e70$1001a8c0@RENNYSLAPTOP
Whole thread Raw
Responses Re: UPDATE/INSERT on multiple co-dependent tables
List pgsql-sql
Is it possible for an UPDATE/INSERT query string to function in such a way
that it requires two like fields in different tables to be equal to/'in sync
with' one another:

Example: I have two tables: registration & schedules....
they both record a class_id, start_date, end_date... I want to make sure
that if the schedule_id field is updated in the registration table; that
class_id, start_date & end_date fields automatically change to match the
schedules.id record in the schedules table.... I've devised a function to
handle this but pgsql recognizes the query to be 'infinitely recursive:

CREATE RULE registration_update AS
ON UPDATE TO registration
DO
UPDATE registration SET class_id = schedules.class_id WHERE new.schedule_id
= (SELECT schedules.id FROM schedules WHERE id = new.schedule_id);

What I'm doing is kind of redundant but necessary for
backwards-compatibility



pgsql-sql by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Aggregate like AVG() with Money Data Type
Next
From: Stephan Szabo
Date:
Subject: Re: UPDATE/INSERT on multiple co-dependent tables