Hello Blaise,

I included a script I used to build/maintain a database.
It also includes triggers and history logging.
I hope you can use it.
In the DO NOT use this part are test things which might not be correct.

Best regards,
Roelof
 <<DBcreate.scania.02.sql>> 

> -----Original Message-----
> From: Blaise Carrupt [SMTP:[EMAIL PROTECTED]]
> Sent: 02 March 2001 16:29
> To:   [EMAIL PROTECTED]
> Subject:      RE: [SQL] Help creating rules/triggers/functions
> 
> Hi Roelof !
> 
> I thank you for your answer. It allowed me to find a way to resolve my
> problems. 
> What is missing to your answer is the trigger. In the documentation, I
> found a 
> way doing it with a C procedure. But I was sure Postgres could do it in a 
> simpler way.
> 
> If it interests you, what I got now is :
> 
> DROP FUNCTION a_del();
> 
> CREATE FUNCTION a_del() RETURNS OPAQUE AS
> 'DECLARE
>     id INT4;
>  BEGIN
>     SELECT a_id INTO id                       /* I'm not sure INTO is
> mandatory... */
>        FROM a
>        WHERE a_id = OLD.addr_id;
>        
>     IF FOUND THEN
>         RAISE EXCEPTION ''not allowed !'';
>     END IF;
>     
>     RETURN OLD;
>  END;'
> LANGUAGE 'plpgsql';
> 
> 
> 
> DROP TRIGGER a_del_trg ON a;
> 
> CREATE TRIGGER a_del_trg
> BEFORE DELETE ON a
> FOR EACH ROW
> EXECUTE PROCEDURE a_del();
> 
> 
> It's much more complicate than Ingres, but it works as well. I don't know
> how 
> a_del knows OLD...
> 
> I thank you again for your help.
> 
> 
> ___________________
> B. Carrupt
>        
>        
>    

DBcreate.scania.02.sql


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to