pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raigo Lukk <l950681@ttu.ee>
To: pgsql-general@postgreSQL.org
Subject: Re: Trigger
Date: Tue, 7 Mar 2000 20:04:27 +0200
Message-ID: <77360BFD1645.AAA3C8F@mail.ttu.ee> (raw)
In-Reply-To: <200003071436.JAA19804@candle.pha.pa.us>
References: <13288F4408ADD11186FF0060B06A431303648CA2@MSGWAW1>

Hi

>     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



view thread (47+ messages)  latest in thread

Message-ID: <77360BFD1645.AAA3C8F@mail.ttu.ee>
Permalink:  ../77360BFD1645.AAA3C8F@mail.ttu.ee/
Also on:    postgresql.org/message-id/77360BFD1645.AAA3C8F@mail.ttu.ee

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: l950681@ttu.ee
  Subject: Re: Trigger
  In-Reply-To: <77360BFD1645.AAA3C8F@mail.ttu.ee>
  References: <13288F4408ADD11186FF0060B06A431303648CA2@MSGWAW1> <77360BFD1645.AAA3C8F@mail.ttu.ee>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox