Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id A37094758EE for ; Mon, 15 Jul 2002 16:17:21 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id BDF95D600; Mon, 15 Jul 2002 13:17:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id B1A795C02; Mon, 15 Jul 2002 13:17:22 -0700 (PDT) Date: Mon, 15 Jul 2002 13:17:22 -0700 (PDT) From: Stephan Szabo To: Andre Schlieper Cc: Subject: Re: problems removing foreign-key triggers, postgresql 7.1.1 In-Reply-To: <3D31C999.99790392@gmx.de> Message-ID: <20020715131412.U41271-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200207/210 X-Sequence-Number: 4895 On Sun, 14 Jul 2002, Andre Schlieper wrote: > Hi there, > I've some problems droping tiggers (foreign key-constraint) on > postgresql 7.1.1, > example-tables are like this : > > CREATE TABLE pers ( > pid INT NOT NULL PRIMARY KEY, > pname TEXT NOT NULL); > > CREATE TABLE tasks ( > taskid SERIAL NOT NULL PRIMARY KEY, > pid INT NOT NULL CONSTRAINT tasks__ref_p REFERENCES > pers, > task TEXT NOT NULL); > > This creates two simple tables, linked with one foreign-key > "tasks_ref_p". > This constraint is done with three triggers (2 on the pk table, 1 on the > fk table), wich are named: > RI_ConstraintTrigger_594265 > RI_ConstraintTrigger_594267 > RI_ConstraintTrigger_594263 > > > I tried to delete one of these triggers with > drop trigger "RI_ConstraintTrigger_594265" on pers; > that fails with > ERROR: DropTrigger: there is no trigger ri_constrainttrigger_594265 on > relation pers The first one should be on tasks, so I think you may have been referencing the wrong table. > I also tried to delete these triggers with > DELETE FROM pg_trigger WHERE tgname='RI_ConstraintTrigger_594265'; > wich worked, all trigger are away from pg_trigger. Doing this is dangerous as you've noticed... The second error you got was because it couldn't find the appropriate number of triggers on the relation. > Q1 : How can I get DROP TRIGGER to work, why does it not work here ? > Q2: what's the right strategy to delete directly on pg_trigger ? was it > only luck that it is working that way; deleting on pg_triggers and > fixing on pg_class(reltriggers) ? Doing the delete/update will work (assuming that you correctly set the number of triggers as opposed to setting it to 0 unconditionally - I believe pg_dump in data only mode outputs a statement that will do that for you). If there are triggers and you set reltriggers to 0, it will work until you add a trigger at which point I think it starts failing again.