From: Ferindo Middleton, Jr <fmiddleton@verizon.net>
To: pgsql-sql@postgresql.org
Subject: UPDATE/INSERT on multiple co-dependent tables
Date: Tue, 9 Nov 2004 21:35:58 -0500
Message-ID: <000c01c4c6ce$03da7e70$1001a8c0@RENNYSLAPTOP> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: fmiddleton@verizon.net
Subject: Re: UPDATE/INSERT on multiple co-dependent tables
In-Reply-To: <000c01c4c6ce$03da7e70$1001a8c0@RENNYSLAPTOP>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox