From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(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-02 17:05:23 |
Message-ID: | Pine.BSF.4.21.0103020901240.51118-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
If you're only doing a simple check for reference, why not use
foreign keys?
In general however, you probably want to use plpgsql to define the
trigger. And trigger functions don't take parameters in the normal
sense, the function should be created taking no args and returning
opaque; the parameters you add in create trigger are passed in
TG_ARGS (i believe). You might want to look at the user and programmer
guides for more information on trigger functions.
On Tue, 27 Feb 2001, Blaise Carrupt wrote:
> Hi all !
>
> I use PostgreSQL 7.0.2 on a HP-UX system.
>
> I would like to create a simple function and a simple trigger (or rule) that
> deny a delete from a table if the row is referenced in another table.
>
> I though it should look like this (from my Ingres experience... :) :
>
> create function A_del(int4 i_id)
> BEGIN
> SELECT id
> FROM b
> where a_id = :i_id;
>
> if rowcount > 0 then
> RAISE EXCEPTION "not allowed !"
> end if;
> END
>
>
> create trigger before delete from A for each row execute procedure A_del(old.id)
>
>
> But it seems to be much more complicated with Postgres (create a C function
> using CurrentTriggerData,...). May I have missed something or is it really much
> more complicated ?
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-03-02 17:18:10 | Re: union & subqueries |
Previous Message | Tangorre, Michael T. | 2001-03-02 16:53:48 | Database Question |