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 830B39DD621 for ; Wed, 7 Dec 2005 19:23:06 -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 99739-06 for ; Wed, 7 Dec 2005 19:23:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id B8C629DD5F0 for ; Wed, 7 Dec 2005 19:23:02 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jB7NN59o004508; Wed, 7 Dec 2005 18:23:05 -0500 (EST) To: "Leif B. Kristensen" cc: pgsql Subject: Re: Error from trigger In-reply-to: <200512080006.44606.leif@solumslekt.org> References: <200512080006.44606.leif@solumslekt.org> Comments: In-reply-to "Leif B. Kristensen" message dated "Thu, 08 Dec 2005 00:06:44 +0100" Date: Wed, 07 Dec 2005 18:23:05 -0500 Message-ID: <4507.1133997785@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[AWL=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200512/62 X-Sequence-Number: 23604 "Leif B. Kristensen" writes: > I have a trigger that will delete records referring to an "events" table > 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 = OLD.event_id; > DELETE FROM participants WHERE event_fk = 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 > 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) > ); Is there a reason you don't just mark the FK reference as ON DELETE CASCADE, rather than using a handwritten trigger? > And then, as I try to delete event #2600, I get the following message: > pgslekt=> delete from events where event_id=2600; > ERROR: relation with OID 1141502 does not exist > CONTEXT: SQL statement "DELETE FROM event_citations WHERE event_fk= $1 " > PL/pgSQL function "delete_event_cascade" line 2 at SQL statement Offhand this looks like you might have dropped and recreated the event_citations table? If so it's just the known problem that plpgsql caches plans and doesn't throw them away when the referenced objects change. regards, tom lane