Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fBKG8Cm44197 for ; Thu, 20 Dec 2001 11:08:12 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.7) with HTTP id 532942; Thu, 20 Dec 2001 08:08:14 -0800 From: "Josh Berkus" Subject: Re: Transaction and cascade problem To: "Glenn MacGregor" , X-Mailer: CommuniGate Pro Web Mailer v.3.4.7 Date: Thu, 20 Dec 2001 08:08:14 -0800 Message-ID: In-Reply-To: <00ad01c1895a$c3d5df80$4d00a8c0@catamount> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200112/219 X-Sequence-Number: 6041 Glenn, > I have postgres 7.1 set up with two tables (groups, users). groups > has 2 columns name, groupid where id is the primary key autoincrement > and name is unique. users has 3 columns name, userid, groupid. I > have a constraint on users which says that groupid must exists in the > group table. I also have a cascade delete on the groups table to > delete any users that are in the group I am removing. I regular (no > transaction) mode everything works fine. When I start a transaction > and I add a group to the group table, then delete it before a commit > or rollback I get the following error: > > ERROR: triggered data change violation on relation "groups" Yes. For some technical reason ( I'm not clear on this ) you cannot both add and delete the same row within a PostgreSQL transaction. This is a known issue in 7.1.x; I do not know if it is fixed in 7.2. In the couple of functions where I need to add rows, then drop them, I have been taking the following steps: 1. Add new rows 2. When I'm done with the rows, flag them as invalid. 3. Put SQL in another, regularly-running (1/hour) function that deletes all invalid-flagged rows. Sort of a messy workaround, I know, but there it is. -Josh ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco