X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9AA4F9DCD3A for ; Wed, 7 Dec 2005 19:06:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19160-09 for ; Wed, 7 Dec 2005 19:06:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail45.e.nsc.no (mail45.e.nsc.no [193.213.115.45]) by postgresql.org (Postfix) with ESMTP id DFE009DCB9B for ; Wed, 7 Dec 2005 19:06:44 -0400 (AST) Received: from [192.168.0.57] (062016183238.customer.alfanett.no [62.16.183.238]) (authenticated bits=0) by mail45.nsc.no (8.13.5/8.13.5) with ESMTP id jB7N6jba004419 for ; Thu, 8 Dec 2005 00:06:45 +0100 (CET) From: "Leif B. Kristensen" To: pgsql Subject: Error from trigger Date: Thu, 8 Dec 2005 00:06:44 +0100 User-Agent: KMail/1.8.1 X-Face: %iea8o"[SI'kMDS.`hz7lU=?\^lC9J-]CVjo; f{4-C:$?uVUEjyN~uYFn%*aH_c3d09U>=?utf-8?q?x=0A=09TXtaoj=7EMV=2E8PgG7hik9=3BcCT2N6+u?=@Y{wH\p3*_f~FH9k,Wi74e[_l%.7b^'zJ)8S'^G<(=?utf-8?q?=3D=0A=09zw8=5CPMC3=27=7BKl9=2EzL*ks!b6wA?=,c~'F`k&Vq|ELDGa|4 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/61 X-Sequence-Number: 23603 Hello, I have a trigger that will delete records referring to an "events" table=20 upon deletion. I have used it without problems for a number of times: CREATE OR REPLACE FUNCTION delete_event_cascade() RETURNS TRIGGER AS $$ BEGIN DELETE FROM event_citations WHERE event_fk =3D OLD.event_id; DELETE FROM participants WHERE event_fk =3D OLD.event_id; RETURN OLD; END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_event_cascade BEFORE DELETE ON events FOR EACH ROW EXECUTE PROCEDURE delete_event_cascade(); The event_citations table is a cross-reference between events and=20 sources, and goes like this: CREATE TABLE event_citations ( event_fk INTEGER REFERENCES events (event_id), source_fk INTEGER REFERENCES sources (source_id), PRIMARY KEY (event_fk, source_fk) ); I'm doing a little cleanup, and perform this query: pgslekt=3D> select * from event_citations where source_fk=3D553; event_fk | source_fk =2D---------+----------- 2600 | 553 2592 | 553 2817 | 553 19919 | 553 19920 | 553 (5 rader) Then I do an adjustment in the "sources" table: pgslekt=3D> update sources set=20 parent_id=3D553,small_text=3D'',large_text=3D'23.04.1745 ved Solum: \"Abrah= am=20 Niels=F8n Aafos 49 aar 5 dage\"' where source_id=3D554; UPDATE 1 And then, as I try to delete event #2600, I get the following message: pgslekt=3D> delete from events where event_id=3D2600; ERROR: relation with OID 1141502 does not exist CONTEXT: SQL statement "DELETE FROM event_citations WHERE event_fk=3D $1 " PL/pgSQL function "delete_event_cascade" line 2 at SQL statement I run a quick check: pgslekt=3D> select * from event_citations where event_fk=3D2600; event_fk | source_fk =2D---------+----------- (0 rader) The record seems to have disappeared into thin air. There has not been=20 performed any inserts or updates in the database between the 'update'=20 and the 'delete' above. And the event won't go away.=20 This is hardly a practical problem, because an event that isn't linked=20 to a "person" through the "participants" table will never print=20 anywhere, and the referring "participant" disappeared. But I don't like=20 it anyway. I'm running PostgreSQL 8.0.4. =2D-=20 Leif Biberg Kristensen | Registered Linux User #338009 http://solumslekt.org/ | Cruising with Gentoo/KDE