Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0BA98634DCE for ; Fri, 3 Apr 2009 10:51:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 26648-02 for ; Fri, 3 Apr 2009 10:50:59 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from QMTA01.emeryville.ca.mail.comcast.net (qmta01.emeryville.ca.mail.comcast.net [76.96.30.16]) by mail.postgresql.org (Postfix) with ESMTP id 152556330EE for ; Fri, 3 Apr 2009 10:51:07 -0300 (ADT) Received: from OMTA01.emeryville.ca.mail.comcast.net ([76.96.30.11]) by QMTA01.emeryville.ca.mail.comcast.net with comcast id azqX1b0020EPchoA11qa1w; Fri, 03 Apr 2009 13:50:34 +0000 Received: from tucker.local ([24.17.164.54]) by OMTA01.emeryville.ca.mail.comcast.net with comcast id b1r51b00X1Ak4z48M1r6XX; Fri, 03 Apr 2009 13:51:06 +0000 From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: FUNCTION problem Date: Fri, 3 Apr 2009 06:51:05 -0700 User-Agent: KMail/1.9.10 Cc: peterw@borstad.com References: <1521645855.2691471238710811603.JavaMail.root@sz0030a.emeryville.ca.mail.comcast.net> <49D5489E.5010904@borstad.com> <200904021816.44804.aklaver@comcast.net> In-Reply-To: <200904021816.44804.aklaver@comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904030651.05480.aklaver@comcast.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.166 tagged_above=0 required=5 tests=AWL=0.166 X-Spam-Level: X-Archive-Number: 200904/31 X-Sequence-Number: 32377 On Thursday 02 April 2009 6:16:44 pm Adrian Klaver wrote: > > > Now I remember. Its something that trips me up, the RECORD in RETURN setof > RECORD is not the same thing as the RECORD in DECLARE RECORD. See below for > a better explanation- > http://www.postgresql.org/docs/8.3/interactive/plpgsql-declarations.html#PL >PGSQL-DECLARATION-RECORDS Note that RECORD is not a true data type, only a > placeholder. One should also realize that when a PL/pgSQL function is > declared to return type record, this is not quite the same concept as a > record variable, even though such a function might use a record variable to > hold its result. In both cases the actual row structure is unknown when the > function is written, but for a function returning record the actual > structure is determined when the calling query is parsed, whereas a record > variable can change its row structure on-the-fly. > > > > -- > Adrian Klaver > aklaver@comcast.net For this particular case the following works. CREATE OR REPLACE FUNCTION test_function(integer) RETURNS record AS $Body$ DECLARE croid integer; DECLARE R RECORD; BEGIN SELECT INTO croid 2; SELECT INTO R croid,$1; RETURN R; END; $Body$ LANGUAGE plpgsql; -- Adrian Klaver aklaver@comcast.net