Re: cascading an insert trigger/rule help - Mailing list pgsql-general

From Stephan Szabo
Subject Re: cascading an insert trigger/rule help
Date
Msg-id 20020610165505.M72309-100000@megazone23.bigpanda.com
Whole thread Raw
In response to cascading an insert trigger/rule help  (s <smarie@ekno.com>)
List pgsql-general
On Mon, 10 Jun 2002, s wrote:

> I tried to create a trigger/function set for postgres:
>
>
>     CREATE or REPLACE FUNCTION foo_insert_function() RETURNS opaque as
> '
>       DECLARE
>         rec_num INTEGER;
>       BEGIN
>         -- is the new name already in the fooplus table
>         -- here I check if it's there at all;
>         -- I'd really like to know if it's there for every name/attr
>
>         select count(*) into rec_num
>         from fooplus f
>         where f.name = new.name;
>
>         IF rec_num < 1
>         THEN
>           insert into fooplus(name, attr)
>           select new.name, a.attr
>           from attrib a;
>         END IF;
>       END;
>     ' LANGUAGE plpgsql;
>
>     CREATE TRIGGER foo_insert_trigger
>       AFTER INSERT ON foo
>       FOR EACH ROW
>       EXECUTE PROCEDURE foo_insert_function();
>
> I get errors on insert indicating that the end of the function is
> reached with no return value.  I thought opaque functions didn't
> return a value?

For trigger functions you still need a return, for an
after trigger, return NULL; should probably be fine.

> So I dropped the trigger and tried:
>
>     create rule foo_insert_rule as
>      on insert to foo do
>      insert into fooplus(name, attr)
>        select new.name, a.attr
>        from attrib a;
>
> I get a cache error on when I now try to insert into foo
>
> ERROR:  fmgr_info: function 18075: cache lookup failed
>
> Suggestions?  Pointers to documentation?

Are you absolutely sure you dropped all the triggers?  Often
that error occurs when a trigger function is dropped and the
trigger is not (so it's referencing a now removed function).

You might want to try to find the trigger in question.  Maybe
select * from pg_trigger where tgfoid=18075;
would give them?



pgsql-general by date:

Previous
From: s
Date:
Subject: cascading an insert trigger/rule help
Next
From: Tom Lane
Date:
Subject: Re: Help with data transfer please