pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: grupos <grupos@carvalhaes.net>
To: pgsql-sql@postgresql.org
Subject: RETURN SET OF DATA WITH CURSOR
Date: Thu, 15 Dec 2005 13:26:29 -0200
Message-ID: <43A18B25.1010705@carvalhaes.net> (raw)

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)



view thread (5+ messages)  latest in thread

Message-ID: <43A18B25.1010705@carvalhaes.net>
Permalink:  ../43A18B25.1010705@carvalhaes.net/
Also on:    postgresql.org/message-id/43A18B25.1010705@carvalhaes.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: grupos@carvalhaes.net
  Subject: Re: RETURN SET OF DATA WITH CURSOR
  In-Reply-To: <43A18B25.1010705@carvalhaes.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox