pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTransaction and cascade problem
6+ messages / 5 participants
[nested] [flat]
* Transaction and cascade problem
@ 2001-12-20 13:32 Glenn MacGregor <gtm@oracom.com>
0 siblings, 1 reply; 6+ messages in thread
From: Glenn MacGregor @ 2001-12-20 13:32 UTC (permalink / raw)
To: pgsql-sql
Hi All,
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"
After that the transaction must be rolledback. Any clues?
Thanks
Glenn
^ permalink raw reply [nested|flat] 6+ messages in thread
* Transaction and cascade problem
@ 2001-12-20 13:47 Glenn MacGregor <gtm@oracom.com>
0 siblings, 0 replies; 6+ messages in thread
From: Glenn MacGregor @ 2001-12-20 13:47 UTC (permalink / raw)
To: pgsql-sql
Hi All,
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 syas 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"
After that the transaction must be rolledback. Any clues?
Thanks
Glenn
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Transaction and cascade problem
@ 2001-12-20 16:08 Josh Berkus <josh@agliodbs.com>
parent: Glenn MacGregor <gtm@oracom.com>
0 siblings, 2 replies; 6+ messages in thread
From: Josh Berkus @ 2001-12-20 16:08 UTC (permalink / raw)
To: Glenn MacGregor <gtm@oracom.com>; pgsql-sql
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Transaction and cascade problem
@ 2001-12-20 17:09 Tom Lane <tgl@sss.pgh.pa.us>
parent: Josh Berkus <josh@agliodbs.com>
1 sibling, 0 replies; 6+ messages in thread
From: Tom Lane @ 2001-12-20 17:09 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; +Cc: Glenn MacGregor <gtm@oracom.com>; pgsql-sql
"Josh Berkus" <josh@agliodbs.com> writes:
>> 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.
Actually, we've just removed that error check in 7.2. The discussion
concluded that we'd misinterpreted the spec in treating this condition
as an error. You can simply dike out the error call (it's in
src/backend/commands/trigger.c, IIRC) if it's getting in your way in
7.1.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Transaction and cascade problem
@ 2001-12-21 02:57 Christopher Kings-Lynne <chriskl@familyhealth.com.au>
parent: Josh Berkus <josh@agliodbs.com>
1 sibling, 0 replies; 6+ messages in thread
From: Christopher Kings-Lynne @ 2001-12-21 02:57 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; Glenn MacGregor <gtm@oracom.com>; pgsql-sql
> > 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.
Hmmm...I seem to recall that it is fixed in 7.2. Correct me if I'm wrong.
Chris
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Transaction and cascade problem
@ 2001-12-21 14:12 Henshall, Stuart - WCP <SHenshall@westcountrypublications.co.uk>
0 siblings, 0 replies; 6+ messages in thread
From: Henshall, Stuart - WCP @ 2001-12-21 14:12 UTC (permalink / raw)
To: 'Glenn MacGregor' <gtm@oracom.com>; pgsql-sql
IIRC this was for some perceived problem with foreign keys, however on
hackers a while back it was talked about and I believe decided that it
wasn't necessary after all and has been taken out. You might have more luck
therefore with 7.2, or altering 7.1 to take this out (however I'm not 100%
sure on this so check the hackers archives).
- Stuart
-----Original Message-----
From: Glenn MacGregor [mailto:gtm@oracom.com]
Sent: 20 December 2001 13:32
To: pgsql-sql@postgresql.org
Subject: Transaction and cascade problem
Hi All,
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"
After that the transaction must be rolledback. Any clues?
Thanks
Glenn
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2001-12-21 14:12 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-12-20 13:32 Transaction and cascade problem Glenn MacGregor <gtm@oracom.com>
2001-12-20 16:08 ` Josh Berkus <josh@agliodbs.com>
2001-12-20 17:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-12-21 02:57 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2001-12-20 13:47 Transaction and cascade problem Glenn MacGregor <gtm@oracom.com>
2001-12-21 14:12 Re: Transaction and cascade problem Henshall, Stuart - WCP <SHenshall@westcountrypublications.co.uk>
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