Re: Manual Trigger Creation

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Manual Trigger Creation
Date: 2001-03-19 23:49:03
Message-ID: Pine.BSF.4.21.0103191540040.26890-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Mon, 19 Mar 2001, Josh Berkus wrote:

> Stephan,
>
> > Yeah, it doesn't play nice with alter table at all. :(
> > Actually, for recreating -- All you really need to do is kill the
> > three triggers that it creates (drop trigger should work) and use
> > alter table to add them again.
>
> How can I drop them if they are <unnamed> triggers? I've been doing
> that by editing pg_trigger, but that just got me into a system table
> mess that it took 2 hours to fix ... and lost me half my foriegn keys to
> boot.

You can use the real trigger name (tgname) and drop trigger, but you
need to double quote the name:
drop trigger "RI_ConstraintTrigger_<n>" on <table>;
... (for all three)

> Is there, perhaps, a way I can name my constraints in the original
> CREATE TABLE statement? Aha! I see ... I never noticed the optional
> [CONSTRAINT constraint_name] phrase before. 'S what I get for crossing
> over from Transact-SQL without retraining!

> > You could do this (4 is unnecessary and 3 and 5 can be combined),
> > although
> > I think you might be better off using alter table add constraint to
> > do
> > that.
>
> I'm interested in the approach for another reason. I have a number of
> tables that must match a NON-UNIQUE value in a reference table, and thus
> I'd like to test them against a query or view.

Well, if you're going against non-unique values then the referential
actions aren't really meaningful anymore [you'd have to look at
match partial's semantics, probably], and you'd probably need to
reimplement that part.
In general you can add the constraint triggers the same way pg_dump does.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-03-19 23:52:12 Re: count() and multiple tables
Previous Message Tom Lane 2001-03-19 23:49:02 Re: Manual Trigger Creation