Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id CFC669FBB52 for ; Wed, 25 Apr 2007 15:32:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 55465-02 for ; Wed, 25 Apr 2007 15:32:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1BBC49FBAF9 for ; Wed, 25 Apr 2007 15:32:27 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l3PIWP1v003416; Wed, 25 Apr 2007 14:32:25 -0400 (EDT) To: Richard Albright cc: pgsql-sql@postgresql.org Subject: Re: sql wrapped plpgsql set returning function In-reply-to: <1177524609.17790.1.camel@MSI1036> References: <1177524609.17790.1.camel@MSI1036> Comments: In-reply-to Richard Albright message dated "Wed, 25 Apr 2007 14:10:09 -0400" Date: Wed, 25 Apr 2007 14:32:25 -0400 Message-ID: <3415.1177525945@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/248 X-Sequence-Number: 28248 Richard Albright writes: > I have figured out my looping issue, but am having difficulty wrapping > my set returning plpgsql function getmovavgset with a getmovavg sql func > when i run the following: Hm, worksforme (see attached trivial example). What PG version are you using? regards, tom lane regression=# create function foo() returns setof int8_tbl as $$ regression$# declare r record; regression$# begin regression$# for r in select * from int8_tbl loop regression$# return next r; regression$# end loop; regression$# end$$ language plpgsql; CREATE FUNCTION regression=# select * from foo(); q1 | q2 ------------------+------------------- 123 | 456 123 | 4567890123456789 4567890123456789 | 123 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 (5 rows) regression=# select foo(); ERROR: set-valued function called in context that cannot accept a set CONTEXT: PL/pgSQL function "foo" line 4 at return next regression=# create function foowrap() returns setof int8_tbl as $$ regression$# select * from foo(); regression$# $$ language sql; CREATE FUNCTION regression=# select foowrap(); foowrap -------------------------------------- (123,456) (123,4567890123456789) (4567890123456789,123) (4567890123456789,4567890123456789) (4567890123456789,-4567890123456789) (5 rows) regression=#