Re: Triggers

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Triggers
Date: 2002-08-16 14:27:27
Message-ID: 3D5D0BCF.5080304@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
>
> I think we check constraints (including NOT NULL) before firing
> triggers.

Seems like the trigger gets fired before the constraint checking. I have
the following table and trigger and SQL that all seem to work:

create table TMP_LI (

cart_id integer references TMP_CART(id),
li_id integer not null,
shop_id integer references CHARISMA_SHOPS(id),
prod_id char(12) references PRODUCTS(id),
quantity int2 not null,
price integer not null,

primary key (cart_id, li_id)
);

create or replace function set_price() returns opaque as '
declare
row record;
begin
select into row sell_price from products where id=new.prod_id;
new.price = row.sell_price;
return new;
end;
' language 'plpgsql';

create trigger insert_into_tmp_li before insert or update
on tmp_li for each row
execute procedure set_price();

insert into tmp_li(cart_id,li_id,shop_id,prod_id,quantity,price)
values('31','0','','289000101554','1')

Jc

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Darren Ferguson 2002-08-16 14:33:19 Re: Triggers
Previous Message Tom Lane 2002-08-16 14:14:02 Re: Triggers