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 977A65294F for ; Fri, 6 May 2005 01:47:06 -0300 (ADT) 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 36817-06 for ; Fri, 6 May 2005 04:46:57 +0000 (GMT) Received: from ausimss.pervasive.com (ausimss.pervasive.com [66.45.103.246]) by svr1.postgresql.org (Postfix) with ESMTP id EC8F852968 for ; Fri, 6 May 2005 01:46:54 -0300 (ADT) Received: from ausbayes1.aus.pervasive.com ([172.16.8.6]) by ausimss.pervasive.com with InterScan Messaging Security Suite; Thu, 05 May 2005 23:46:53 -0500 Received: from BLRMAIL1.aus.pervasive.com ([10.3.16.60]) by ausbayes1.aus.pervasive.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 5 May 2005 23:46:53 -0500 content-class: urn:content-classes:message Subject: Re: Select of a function that returns a array Date: Fri, 6 May 2005 10:16:50 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Message-ID: <02767D4600E59A4487233B23AEF5C5992A4086@blrmail1.aus.pervasive.com> Content-Transfer-Encoding: quoted-printable X-MS-Has-Attach: X-MS-TNEF-Correlator: X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Thread-Topic: [SQL] Select of a function that returns a array Thread-Index: AcVRgJIp/X4X1jDjSjuS8viIEEfUvwAcugHA From: "Ramakrishnan Muralidharan" To: =?iso-8859-1?Q?Listas_Evandro_=28N=E3o_use_este_endere=E7o_para_mensagens?= =?iso-8859-1?Q?_pessoais=29?= , "pgsql-sql" X-OriginalArrivalTime: 06 May 2005 04:46:53.0257 (UTC) FILETIME=[9FABD390:01C551F6] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.073 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/70 X-Sequence-Number: 21383 CREATE or replace FUNCTION mean_and_variancepop(var_table varchar, var_col varchar) RETURNS float8[] AS $$ DECLARE a float; b float; BEGIN a =3D 1.02; b =3D3.05; RETURN ARRAY[a,b]; END; $$ LANGUAGE plpgsql;=20 -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Listas Evandro = (N=E3o use este endere=E7o para mensagens pessoais) Sent: Thursday, May 05, 2005 8:08 PM To: pgsql-sql Subject: [SQL] Select of a function that returns a array Hi guys I'm trying to figure out a way to make this select work even for a wrong = value: select mean_and_variancepop('golf', 'temperature'); or select CAST (mean_and_variancepop('golf', 'temperature') AS float(2)); This function return an array the function is: CREATE or replace FUNCTION mean_and_variancepop(var_table varchar, var_col varchar) RETURNS float(2) AS $$ DECLARE curs refcursor; a float; b float; c float; retvals float[2]; sum float:=3D0; BEGIN open curs FOR EXECUTE 'SELECT ' || quote_ident(var_col) || ' FROM ' || quote_ident(var_table); b:=3D0; LOOP -- some computations FETCH curs INTO a; IF NOT FOUND THEN EXIT; -- exit loop END IF; b:=3Db+1; c:=3Da; sum:=3D sum + c; END LOOP; CLOSE curs; retvals[0]:=3D sum / b; retvals[1] :=3D4; RETURN retvals; END; $$ LANGUAGE plpgsql; Thanks -Jr ---------------------------(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