X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F06428B9F61; Thu, 3 Feb 2005 16:48:21 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50060-08; Thu, 3 Feb 2005 16:48:12 +0000 (GMT) Received: from ganymede.hub.org (blk-224-186-245.eastlink.ca [24.224.186.245]) by svr1.postgresql.org (Postfix) with ESMTP id 038BD8B9F72; Thu, 3 Feb 2005 16:48:12 +0000 (GMT) Received: by ganymede.hub.org (Postfix, from userid 1000) id 8C5B038E68; Thu, 3 Feb 2005 12:48:11 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by ganymede.hub.org (Postfix) with ESMTP id 8AEA638CF7; Thu, 3 Feb 2005 12:48:11 -0400 (AST) Date: Thu, 3 Feb 2005 12:48:11 -0400 (AST) From: "Marc G. Fournier" X-X-Sender: scrappy@ganymede.hub.org To: George Weaver Cc: "Marc G. Fournier" , pgsql-sql@postgresql.org Subject: Re: PL/PgSQL - returning multiple columns ... In-Reply-To: <00c701c50978$f01c9e20$6400a8c0@Dell4500> Message-ID: <20050203124751.C62562@ganymede.hub.org> References: <20050202170643.R27579@ganymede.hub.org> <00c701c50978$f01c9e20$6400a8c0@Dell4500> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.098 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, RCVD_IN_NJABL_DUL, RCVD_IN_SORBS_DUL X-Spam-Level: * X-Archive-Number: 200502/68 X-Sequence-Number: 20179 Perfect, worked like a charm ... but the RETURNS still needs to be a SETOF, other then that, I'm 'away to the races' ... thanks :) On Wed, 2 Feb 2005, George Weaver wrote: > Hi Marc, > > One option is to create a simple data type and return the rowtype of the > datatype > > eg CREATE TYPE tserverload AS ("server_name" text, "load_avg" int4); > > CREATE FUNCTION getserverload() > > RETURNS tserverload > > AS > > 'DECLARE > > r tserverload%rowtype; > > etc. > > You would then return r, comprised of r.server_name and r.load_avg. > > George > > > > ----- Original Message ----- From: "Marc G. Fournier" > > To: > Sent: Wednesday, February 02, 2005 3:10 PM > Subject: [SQL] PL/PgSQL - returning multiple columns ... > > >> >> I have a function that I want to return 'server_name, avg(load_avg)' ... if >> I wanted to return matching rows in a table, I can do a 'setof ', >> with a for loop inside ... but what do I set the 'RETURNS' to if I want to >> return the results of query that returns only two fields of a table, or, in >> the case of the above, one column and oen 'group by' column? >> >> thanks ... >> >> >> ---- >> Marc G. Fournier Hub.Org Networking Services (http://www.hub.org) >> Email: scrappy@hub.org Yahoo!: yscrappy ICQ: 7615664 >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 9: the planner will ignore your desire to choose an index scan if your >> joining column's datatypes do not match >> > > > ---- Marc G. Fournier Hub.Org Networking Services (http://www.hub.org) Email: scrappy@hub.org Yahoo!: yscrappy ICQ: 7615664