X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9656B9DCBFF for ; Thu, 15 Dec 2005 11:28:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23454-09 for ; Thu, 15 Dec 2005 11:28:58 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 2221F9DCBFB for ; Thu, 15 Dec 2005 11:28:52 -0400 (AST) Received: from nitrogenio.carvalhaes.net (nitrogenio.carvalhaes.net [200.175.206.51]) by svr4.postgresql.org (Postfix) with ESMTP id 74E7D5AF06B for ; Thu, 15 Dec 2005 15:28:57 +0000 (GMT) Received: from [200.175.206.50] (helo=[192.168.0.10]) by nitrogenio.carvalhaes.net with esmtpa (Exim 4.54) id 1Emv3Z-0002y0-C7 for pgsql-sql@postgresql.org; Thu, 15 Dec 2005 13:30:12 -0200 Message-ID: <43A18B25.1010705@carvalhaes.net> Date: Thu, 15 Dec 2005 13:26:29 -0200 From: grupos User-Agent: Thunderbird 1.5 (Windows/20051025) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: RETURN SET OF DATA WITH CURSOR Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Verificado contra virus. X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.166 required=5 tests=[SUBJ_ALL_CAPS=1.166, UPPERCASE_25_50=0] X-Spam-Score: 1.166 X-Spam-Level: * X-Archive-Number: 200512/129 X-Sequence-Number: 23671 Hi ! I am making one plpgsql function and I need to return of setof data using a cursor. The problem is that my function is returning only the first row and column of the query. This query have more than 80 columns and 1.000 rows. Enyone have any tip to give me? Here the fuction... CREATE OR REPLACE FUNCTION rel_faturamento("varchar","varchar") RETURNS refcursor AS $BODY$ DECLARE data_inicial ALIAS FOR $1; data_final ALIAS FOR $2; ref refcursor; fat_cursor CURSOR FOR SELECT * FROM SF2010 SF2 INNER JOIN SD2010 SD2 ON (SD2.D2_DOC = SF2.F2_DOC) INNER JOIN SB1010 SB1 ON (SB1.B1_COD = SD2.D2_COD) INNER JOIN SA1010 SA1 ON (SF2.F2_CLIENTE = SA1.A1_COD) WHERE F2_EMISSAO >= data_inicial AND F2_EMISSAO <= data_final AND SF2.D_E_L_E_T_<> '*' AND sd2.d2_tes IN (SELECT f4_codigo FROM sf4010 WHERE d_e_l_e_t_ <> '*' AND f4_duplic = 'S' AND f4_codigo >= '500') ORDER BY SF2.F2_EMISSAO, SF2.F2_DOC, SF2.F2_HORA; BEGIN OPEN fat_cursor; LOOP FETCH fat_cursor INTO ref; RETURN ref; END LOOP; CLOSE fat_cursor; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; When I execute it, I only receive the return below: SELECT rel_faturamento('20051201','20051231'); rel_faturamento ----------------- 010876 (1 row)