From: | "Matt Magoffin" <mmagoffin(at)proxicom(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | trigger inheritence? |
Date: | 2001-03-20 21:20:23 |
Message-ID: | 998hg5$1lkr$1@news.tht.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I had to give a loud "Duh!" after reading your response: that's exactly what
I wanted, thanks!
Now I wonder if there is a way for a trigger that's created on a base table
to be fired on any table that inherits from that base table. Otherwise I'm
still stuck creating triggers for each table that I create (that's inherited
from the base table).
For example, if I have:
CREATE TABLE foo (
"name" text
);
CREATE TRIGGER foo_trigger BEFORE INSERT
ON foo FOR EACH ROW EXECUTE PROCEDURE a_func();
CREATE TABLE bar (
) INHERITS (foo);
I would like foo_trigger to get fired when I execute a
INSERT into bar ("Hello, world.");
but it only seems to fire if the INSERT was on foo, not bar. Any way to do
this?
-- m@
"Stephan Szabo" <sszabo(at)megazone23(dot)bigpanda(dot)com> wrote in message
news:Pine(dot)BSF(dot)4(dot)21(dot)0103201248480(dot)30334-100000(at)megazone23(dot)bigpanda(dot)com(dot)(dot)(dot)
>
> I'd guess you could use TG_RELID or TG_RELNAME inside your trigger.
>
> On Tue, 20 Mar 2001, Matt Magoffin wrote:
>
> > Is there any way to make use of the tableoid either as an argument to
the
> > function or as a reference within the function (in plpgsql)? For
example,
> > I'd like to either
> >
> > CREATE TRIGGER set_default_value BEFORE INSERT
> > ON foo FOR EACH ROW EXECUTE PROCEDURE set_value('tableoid');
> >
> > and within the function set_value():
> >
> > SELECT p.relname::text FROM pg_class p WHERE p.oid = TG_ARGV[0]::oid );
> >
> > - or -
> >
> > CREATE TRIGGER set_default_value BEFORE INSERT
> > ON foo FOR EACH ROW EXECUTE PROCEDURE set_value();
> >
> > and within the function set_value():
> >
> > SELECT p.relname::text FROM pg_class p WHERE p.oid = NEW.tableoid;
> >
> > The former produces the error
> >
> > ERROR: text_oid: error in "tableoid": can't parse "tableoid"
> >
> > and the later produces the error:
> >
> > ERROR: record new has no field tableoid
> >
> > I gather the former method is passing the string "tableoid" into the
> > set_value() function. I just want to be able to write one function that
uses
> > the tableoid value to produce different results instead of unique
functions
> > for each table I create.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
From | Date | Subject | |
---|---|---|---|
Next Message | Oliver Elphick | 2001-03-20 21:28:47 | Re: Special characters |
Previous Message | chris markiewicz | 2001-03-20 21:19:42 | RE: finding and removing a constraint... |