pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Rosenberg <richrosenberg@earthlink.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-sql@postgresql.org
Subject: Re: polymorphic function in 7.4 vs. 8.3
Date: Thu, 11 Jun 2009 14:42:17 -0700
Message-ID: <200906111442.17861.richrosenberg@earthlink.net> (raw)

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



view thread (6+ messages)  latest in thread

Message-ID: <200906111442.17861.richrosenberg@earthlink.net>
Permalink:  ../200906111442.17861.richrosenberg@earthlink.net/
Also on:    postgresql.org/message-id/200906111442.17861.richrosenberg@earthlink.net

 · 

reply

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, tgl@sss.pgh.pa.us
  Subject: Re: polymorphic function in 7.4 vs. 8.3
  In-Reply-To: <200906111442.17861.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