X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 8D73A11F60E2 for ; Fri, 28 Apr 2006 12:25:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 34744-06 for ; Fri, 28 Apr 2006 12:24:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from canyonero.dot.net.au (canyonero.dot.net.au [202.147.68.14]) by postgresql.org (Postfix) with ESMTP id 45D4211F60B8 for ; Fri, 28 Apr 2006 12:24:53 -0300 (ADT) Received: from [203.129.40.123] (helo=ppp-40-123.grapevine.net.au) by canyonero.dot.net.au with esmtp (Exim 3.35 #1 (Debian)) id 1FZUpt-0000lw-00 for ; Sat, 29 Apr 2006 01:24:49 +1000 Subject: Re: set return function is returning a single record, From: Ross Johnson To: PostgreSQL SQL List In-Reply-To: <20060428105621.GD8542@webserv.wug-glas.de> References: <20060428105621.GD8542@webserv.wug-glas.de> Content-Type: text/plain Date: Sat, 29 Apr 2006 01:24:45 +1000 Message-Id: <1146237886.13720.12.camel@desk.home> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 (2.0.4-7) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/203 X-Sequence-Number: 25012 On Fri, 2006-04-28 at 12:56 +0200, A. Kretschmer wrote: > am 28.04.2006, um 16:14:10 +0530 mailte Penchalaiah P. folgendes: > > 4) The following is the function that retrieves the records from pss : > > > > CREATE or replace FUNCTION ftoc9() RETURNS setof structrankmaster2 > > LANGUAGE 'plpgsql' > > > > AS' DECLARE > > rowdata pss%rowtype; > > BEGIN for i in 1..3 loop > > select * into rowdata from pss ; > > return next rowdata ; > > end loop; > > return; > > end'; > > Your loop is wrong, for i in 1..3 select... and then returns the first > record. > > > Change this to: > > BEGIN > .. > for rowdata in select * from pss ; > return next rowdata ; > end loop; > .. > END; > > *untestet* If you meant to return the first 3 records, then: ... begin for rowdata in select * from pss limit 3 loop return next rowdata ; end loop; return; end'; You can also return a SETOF pss without creating the structrankmaster2 type. If this is actually all you are after, and not just a simplified example then you could also use this (also not tested): CREATE FUNCTION ftoc9() RETURNS SETOF pss AS $$ SELECT * FROM pss LIMIT 3; $$ LANGUAGE SQL; If you do use LIMIT, then ORDER BY might also be needed as well. Ross