Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C440D635629 for ; Wed, 1 Apr 2009 20:55:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 17991-02 for ; Wed, 1 Apr 2009 20:55:57 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from QMTA15.emeryville.ca.mail.comcast.net (qmta15.emeryville.ca.mail.comcast.net [76.96.27.228]) by mail.postgresql.org (Postfix) with ESMTP id D27A7635511 for ; Wed, 1 Apr 2009 20:55:57 -0300 (ADT) Received: from OMTA06.emeryville.ca.mail.comcast.net ([76.96.30.51]) by QMTA15.emeryville.ca.mail.comcast.net with comcast id aBsC1b00116AWCUAFPvxDi; Wed, 01 Apr 2009 23:55:57 +0000 Received: from tucker.local ([24.17.164.54]) by OMTA06.emeryville.ca.mail.comcast.net with comcast id aPvv1b00e1Ak4z48SPvwTv; Wed, 01 Apr 2009 23:55:56 +0000 From: Adrian Klaver To: pgsql-sql@postgresql.org, peterw@borstad.com Subject: Re: FUNCTION problem Date: Wed, 1 Apr 2009 16:55:58 -0700 User-Agent: KMail/1.9.10 References: <49D3F948.4060908@borstad.com> In-Reply-To: <49D3F948.4060908@borstad.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904011655.58801.aklaver@comcast.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/8 X-Sequence-Number: 32354 On Wednesday 01 April 2009 4:31:20 pm Peter Willis wrote: > Hello, > > I am having a problem with a FUNCTION. > The function creates just fine with no errors. > > However, when I call the function postgres produces an error. > > Perhaps someone can enlighten me. > > > --I can reproduce the error by making a test function > --that is much easier to follow that the original: > > CREATE OR REPLACE FUNCTION test_function(integer) > RETURNS SETOF RECORD AS > $BODY$ > DECLARE croid integer; > BEGIN > > --PERFORM A SMALL CALCULATION > --DOESNT SEEM TO MATTER WHAT IT IS > > SELECT INTO croid 2; > > --A SELECT STATEMENT OUTPUTS RECORDS (one in this case) > SELECT croid,$1; > END; > > $BODY$ > LANGUAGE 'plpgsql' VOLATILE > > > > > --The call looks like the following: > > SELECT test_function(1); > > > > > > --The resulting error reads as follows: > > ERROR: query has no destination for result data > HINT: If you want to discard the results of a SELECT, use PERFORM instead. > CONTEXT: PL/pgSQL function "test_function" line 5 at SQL statement > > ********** Error ********** > > ERROR: query has no destination for result data > SQL state: 42601 > Hint: If you want to discard the results of a SELECT, use PERFORM instead. > Context: PL/pgSQL function "test_function" line 5 at SQL statement You have declared function to RETURN SETOF. In order for that to work you need to do RETURN NEXT. See below for difference between RETURN and RETURN NEXT: http://www.postgresql.org/docs/8.3/interactive/plpgsql-control-structures.html#PLPGSQL-CONTROL-STRUCTURES-LOOPS -- Adrian Klaver aklaver@comcast.net