create constraint trigger

From: Kyle Bateman <kyle(at)actarg(dot)com>
To: JanWieck(at)Yahoo(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: create constraint trigger
Date: 2000-05-30 00:13:05
Message-ID: 39330791.64796672@actarg.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Jan:

In response to your suggestion about possibly being able to use "create
constraint trigger," I have tried the following:

I have the following trigger function (probably not all that important
what it does...):

create function prd_parm_tf_iu ()
returns opaque as '
declare
trec record;
baseholder varchar;
begin
select into trec min(pos) as n,max(pos) as m,count(*) as c
from prd_parm where new.base = base;
if trec.n != 1 or trec.m != trec.c then
raise exception \'Parameters for base % not in order\',
new.base;
end if;
return new;
end;' language 'plpgsql';

This seems to work pretty good:
create trigger prd_part_tr_iu after insert or update on prd_parm
for each row execute procedure prd_parm_tf_iu();

But when I create it with "create constraint trigger" as shown next, the
trigger doesn't seem to be invoked. It says it is created, but it
allows data to pass that would not be allowed with the "create
trigger." So I'm assuming I'm doing something wrong.

create constraint trigger prd_part_tr_iu after insert or update on
prd_parm
deferrable initially deferred
for each row execute procedure prd_parm_tf_iu();

Any ideas?

Also, its not clear to me how to drop a trigger created with "create
constrataint trigger."

It would be very helpful if I could figure out how to make my triggers
deferred. There are things stored in one table that have to be a
certain way if other things are a certain way in a related table. It is
more than what foreign key relationships can handle. It would really be
great if I could figure out how to have the backend monitor the
consistency of these details.

Without deferral, I can check the consistency in one direction. But if
I try to constrain it in both directions, I get into a problem where I
can't update either table without breaking the constraints. I'm
guessing that if I can get deferral to work, I should be able to update
both tables in a transaction and be OK.

Kyle

Attachment Content-Type Size
kyle.vcf text/x-vcard 291 bytes

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tubagus Nizomi 2000-05-30 03:54:49 Max date in the month
Previous Message Bernie Huang 2000-05-29 21:09:34 storing images!