From: | Richard Rosenberg <richrosenberg(at)earthlink(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | polymorphic function in 7.4 vs. 8.3 |
Date: | 2009-06-11 20:16:12 |
Message-ID: | 200906111316.12662.richrosenberg@earthlink.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I have the following setup which works great in version 8.3 but throws an
error in 7.4:
CREATE TABLE atest1
(
id integer NOT NULL,
descr text,
CONSTRAINT atest1_pkey PRIMARY KEY (id)
);
CREATE OR REPLACE FUNCTION test_trg()
RETURNS "trigger" AS
'
DECLARE
any_rec wfsys.atest1;
BEGIN
any_rec.id := NEW.id;
any_rec.descr := NEW.descr;
select into any_rec * from dd_test(any_rec);
--any_rec := dd_test(any_rec);
RETURN any_rec;
END;
'
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION dd_test(anyelement)
RETURNS record AS
'
DECLARE
any_rec alias for $1;
some_row record;
BEGIN
some_row := any_rec;
if some_row.id < 0 then
raise notice ''id is < 0!'';
some_row.descr := ''some other value'';
end if;
RETURN some_row;
END;
'
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER trg_atest1
BEFORE INSERT
ON atest1
FOR EACH ROW
EXECUTE PROCEDURE test_trg();
Finally, firing the trigger like so:
insert into wfsys.atest1 values(123, 'some text');
Gives the following error:
ERROR: column "any_rec" does not exist
CONTEXT: PL/pgSQL function "test_trg" line 7 at select into variables
********** Error **********
ERROR: column "any_rec" does not exist
SQL state: 42703
Context: PL/pgSQL function "test_trg" line 7 at select into variables
It works great on 8.3 (my dev server), but throws the error on the machine I
am forced to work with, which is running version 7.4. I realize that
polymorphic functions were pretty new in v7.4, is there a workaround or am I
making a silly mistake? Or both?
Incidentally, I get the same error when I change the polymorphic function's
argument from "anyelement" to "wfsys.atest1" so it seems that it is occurring
in the trigger function. Thanks for any help.
Richard
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-06-11 20:39:38 | Re: polymorphic function in 7.4 vs. 8.3 |
Previous Message | Rob Sargent | 2009-06-11 16:05:39 | Re: Avoiding "will create implicit index" NOTICE |