RE: Help creating rules/triggers/functions - Mailing list pgsql-sql

From Sondaar Roelof
Subject RE: Help creating rules/triggers/functions
Date
Msg-id F28A2B83DFE0D411A7B3006097487147468FBC@sv7007.scania.se
Whole thread Raw
In response to Help creating rules/triggers/functions  (Blaise Carrupt <bc@mjtsa.com>)
List pgsql-sql
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:bc@mjtsa.com]
> Sent:    02 March 2001 16:29
> To:    roelof.sondaar@scania.com
> 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
>
>
>

Attachment

pgsql-sql by date:

Previous
From: Ian Harding
Date:
Subject: Re: Temp Tables & Connection Pooling
Next
From: Boulat Khakimov
Date:
Subject: Re: [GENERAL] Re: MySQLs Describe emulator!