From: Richard Rosenberg <richrosenberg@earthlink.net>
To: pgsql-sql@postgresql.org
Subject: polymorphic function in 7.4 vs. 8.3
Date: Thu, 11 Jun 2009 13:16:12 -0700
Message-ID: <200906111316.12662.richrosenberg@earthlink.net> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: richrosenberg@earthlink.net
Subject: Re: polymorphic function in 7.4 vs. 8.3
In-Reply-To: <200906111316.12662.richrosenberg@earthlink.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox