From: | Richard Rosenberg <richrosenberg(at)earthlink(dot)net> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: polymorphic function in 7.4 vs. 8.3 |
Date: | 2009-06-11 21:42:17 |
Message-ID: | 200906111442.17861.richrosenberg@earthlink.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Tom, thanks for your prompt reply. I think I may have my head on straight now,
this should work:
CREATE TABLE atest1
(
id integer NOT NULL,
descr text,
CONSTRAINT atest1_pkey PRIMARY KEY (id)
);
CREATE OR REPLACE FUNCTION test1_trg()
RETURNS trigger AS
'
DECLARE
some_rec public.atest1;
BEGIN
some_rec.id := NEW.id;
some_rec.descr := NEW.descr;
select into some_rec * from dd_test(some_rec) as (id int4, descr text);
--some_rec := dd_test(some_rec);
RETURN some_rec;
END;
'
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION dd_test(anyelement)
RETURNS record AS
'
DECLARE
any_row alias for $1;
some_row record;
BEGIN
some_row := any_row;
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 test1_trg();
insert into public.atest1 values(123, 'some text');
insert into public.atest1 values(-90, 'some text');
This gives the same result. Also in the trigger function test1_trg the syntax
of the call to the polymorphic function makes a difference in terms of the
error that is thrown. A simple assignment like:
. . .
some_rec := dd_test(some_rec);
. . .
Throws a syntax error, while a 'SELECT INTO. . .' like:
. . .
select into some_rec * from dd_test(some_rec) as (id int4, descr text);
. . .
Throws this:
ERROR: column "some_rec" does not exist
SQL state: 42703
Context: PL/pgSQL function "test1_trg" line 7 at select into variables
Sorry for the earlier typo(s), and thanks for any help.
Richard
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-06-11 21:49:46 | Re: polymorphic function in 7.4 vs. 8.3 |
Previous Message | Tom Lane | 2009-06-11 20:39:38 | Re: polymorphic function in 7.4 vs. 8.3 |