| From: | Richard Huxton <dev(at)archonet(dot)com> | 
|---|---|
| To: | Jake Stride <nsuk(at)users(dot)sourceforge(dot)net> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: Cascades Failing in 8.0.x | 
| Date: | 2005-08-16 14:23:15 | 
| Message-ID: | 4301F6D3.1040408@archonet.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general pgsql-hackers | 
Jake Stride wrote:
> I seem to be having some problems with cascading updates, I seem to
> remember that this worked in the database in 7.4 but seems to fail in 8,
> can anyone give me any pointer please as I seem to be able to find
> anything about this online.
> No when I try to do an update I get the following error:
> 
> update users set username='new' where username='old';
> ERROR:  insert or update on table "company" violates foreign key
> constraint "$5"
> DETAIL:  Key (alteredby)=(old) is not present in table "users".
> CONTEXT:  SQL statement "UPDATE ONLY "public"."company" SET "assigned" =
> $1 WHERE "assigned" = $2"
> 
> surely this should not fail because of the 'ON UPDATE CASCADE'?
Hmm - I can reproduce it on 8.0.2 on my Mac laptop, but the following 
works fine on version 7.4.7 which I also have here.
--
-- Begin test
--
CREATE TABLE foo (a int, b text, PRIMARY KEY (a));
CREATE TABLE bar (
   x int,
   y int NOT NULL REFERENCES foo(a) ON UPDATE CASCADE,
   z int NOT NULL REFERENCES foo(a) ON UPDATE CASCADE
);
INSERT INTO foo VALUES (1,'aaa');
INSERT INTO foo VALUES (2,'bbb');
INSERT INTO bar VALUES (101, 1, 1);
INSERT INTO bar VALUES (102, 2, 2);
UPDATE foo SET a=3 WHERE a=1;
--
-- End test
--
There is something similar mentioned on the bugs list - "Cascading 
updates run seperately". Does this look like your problem?
-- 
   Richard Huxton
   Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrus | 2005-08-16 14:31:24 | Prevent inserting document without rows | 
| Previous Message | Tom Lane | 2005-08-16 14:23:05 | Re: Testing of MVCC | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2005-08-16 14:34:10 | Re: Cascades Failing | 
| Previous Message | Tom Lane | 2005-08-16 14:23:05 | Re: Testing of MVCC |