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