X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AB8143A409E for ; Wed, 10 Nov 2004 02:36:00 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63074-03 for ; Wed, 10 Nov 2004 02:35:53 +0000 (GMT) Received: from out007.verizon.net (out007pub.verizon.net [206.46.170.107]) by svr1.postgresql.org (Postfix) with ESMTP id B6D5F3A409A for ; Wed, 10 Nov 2004 02:35:56 +0000 (GMT) Received: from RENNYSLAPTOP ([151.200.47.157]) by out007.verizon.net (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP id <20041110023556.MQUG22257.out007.verizon.net@RENNYSLAPTOP> for ; Tue, 9 Nov 2004 20:35:56 -0600 Reply-To: From: "Ferindo Middleton, Jr" To: Subject: UPDATE/INSERT on multiple co-dependent tables Date: Tue, 9 Nov 2004 21:35:58 -0500 Message-ID: <000c01c4c6ce$03da7e70$1001a8c0@RENNYSLAPTOP> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2742.200 Importance: Normal X-Authentication-Info: Submitted using SMTP AUTH at out007.verizon.net from [151.200.47.157] at Tue, 9 Nov 2004 20:35:56 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/93 X-Sequence-Number: 19412 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