From: | Ferindo Middleton Jr <fmiddleton(at)sleekcollar(dot)com> |
---|---|
To: | pgsql-sql <pgsql-sql(at)postgresql(dot)org> |
Subject: | UPDATE/INSERT on multiple co-dependent tables |
Date: | 2004-11-10 02:26:12 |
Message-ID: | 1100053572.9414.142.camel@scnmaster.sleekcollar.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
--
www.sleekcollar.com
Ferindo Middleton, Jr.
Chief Architect
Sleekcollar Internet Application & Artistic Visualizations
ferindo(dot)middleton(at)sleekcollar(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Ferindo Middleton, Jr | 2004-11-10 02:35:58 | UPDATE/INSERT on multiple co-dependent tables |
Previous Message | Michael Fuhr | 2004-11-10 01:33:01 | Re: Aggregate like AVG() with Money Data Type |