Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 248A1475458 for ; Tue, 21 Jan 2003 09:57:23 -0500 (EST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by postgresql.org (Postfix) with ESMTP id 6FFCE475425 for ; Tue, 21 Jan 2003 09:57:22 -0500 (EST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 18azuo-00034z-00; Tue, 21 Jan 2003 15:02:14 +0000 Content-Type: text/plain; charset="iso-8859-1" From: Gary Stainburn Organization: Ringways Garages Ltd To: ddurst@larubber.com, Subject: Re: returning setof in plpgsql Date: Tue, 21 Jan 2003 14:56:02 +0000 User-Agent: KMail/1.4.3 References: <52900.216.86.192.34.1043145602.squirrel@www.la-rubber.com> In-Reply-To: <52900.216.86.192.34.1043145602.squirrel@www.la-rubber.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200301211456.02748.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/318 X-Sequence-Number: 11183 On Tuesday 21 Jan 2003 10:40 am, David Durst wrote: > I have a function that I want to return setof a table in plpgsql. > > Here is what I have: > > CREATE FUNCTION lookup_account(varchar(32)) RETURNS SETOF accounts AS ' > DECLARE > aname ALIAS FOR $1; > rec RECORD; > BEGIN > select into rec * from accounts where accountname = aname; > return rec; > END;' > LANGUAGE 'plpgsql'; > > This seems to hang when I attempt to select it using: > > select accountid( > lookup_account('some account')), > accountname(lookup_account('some account')), > type(lookup_account('some account')), > balance(lookup_account('some account')); > > Does anyone see a problem w/ my approach?? Hi David, I've never done this but I seem to remember seeing something about this recently. Firstly, I think you need 7.3.1 to do this. You then have to create a 'type' as being a set of your table. You then define the function as returning that type. Sorry I can't be more specific, but as I said, I've never done it. Gary > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000