RE: Help creating rules/triggers/functions

From: Sondaar Roelof <roelof(dot)sondaar(at)scania(dot)com>
To: "'Blaise Carrupt'" <bc(at)mjtsa(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: RE: Help creating rules/triggers/functions
Date: 2001-03-05 08:39:47
Message-ID: F28A2B83DFE0D411A7B3006097487147468FBC@sv7007.scania.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mjtsa(dot)com]
> Sent: 02 March 2001 16:29
> To: roelof(dot)sondaar(at)scania(dot)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 Content-Type Size
DBcreate.scania.02.sql application/octet-stream 12.3 KB

Browse pgsql-sql by date

  From Date Subject
Next Message rocael 2001-03-05 10:55:16 count number of weeks??
Previous Message Josh Berkus 2001-03-05 02:04:56 Re: From mailing list: PL/PGSQL returning recordset