Received: from mail.ttu.ee (kelly.va.ttu.ee [193.40.247.62]) by hub.org (8.9.3/8.9.3) with ESMTP id IAA61924 for ; Wed, 8 Mar 2000 08:07:12 -0500 (EST) (envelope-from l950681@ttu.ee) Received: from thule (thulema.datanet.ee [195.222.30.249]) by mail.ttu.ee (Netscape Messaging Server 3.6) with SMTP id AAA1517 for ; Wed, 8 Mar 2000 15:00:40 +0200 From: "Raigo Lukk" To: pgsql-general@hub.org Date: Wed, 8 Mar 2000 15:08:07 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Trigger Priority: normal X-mailer: Pegasus Mail for Win32 (v3.01d) Message-ID: <77360C5D27.AAA1517@mail.ttu.ee> Hi I sent this message already, but did not get it back from list. So I aplogise if somebody gets it two times. > twice inside of one transaction (WRT key changes), it's possible to > fool the trigger and end up with inconsistent data in a multiuser > environment. OK let's assume that customer is not deleted while order is enetered. At my work I have used InterBase quite a lot. Up to IB 5 there was also no foreign keys, so it had to be done with triggers just like in PostgreSQL. So when using IB 4 I usually did something like this: CREATE EXCEPTION CHILD_INSERT_RESTRICT "Cannot INSERT ORDER because CUSTOMER does not exist in CUSTOMER table"; CREATE TRIGGER BI_ORDER FOR ORDER BEFORE INSERT AS DECLARE VARIABLE numrows INTEGER; BEGIN select count(distinct CustomerID) from customer where CustomerID=NEW.CustomerID into numrows; IF (numrows = 0 ) THEN BEGIN EXCEPTION CHILD_INSERT_RESTRICT; END END I think there is some small syntax differences in PostgreSQL. So, can somebody please put this into PostgreSQL syntax for me? I searched the manuals but found no Exeption ... is it possible to use Exceptions in PostgreSQL? Also, does there excist special aliases like NEW and OLD in PostgreSQL? Thanks Raigo