Re: Cursor

From: "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar>
To: "'Xavier Bermeo'" <xbermeo(at)gmail(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Cursor
Date: 2008-08-19 18:38:00
Message-ID: 022701c9022a$b4e46a00$8f01010a@iptel.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> De: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org
<mailto:pgsql-sql-owner(at)postgresql(dot)org>] En nombre de Xavier Bermeo
> Enviado el: Sábado, 16 de Agosto de 2008 14:54
> Para: pgsql-sql(at)postgresql(dot)org
> Asunto: [SQL] Cursor
>
> Hi, guys.......
> I have problems with cursosrs.
> Anyone have an example complete the how load and read each position of a
cursor?
> I wait your answer........
> Thanks.......guys

Hi Xavier. This is a very simple example of a function with an implicit
cursor.
Regards,
Fernando.

CREATE OR REPLACE FUNCTION f_cursor()
RETURNS void AS
$BODY$
DECLARE
idx INTEGER;
a mytable.col1%TYPE;
b mytable.col2%TYPE;
c mytable.col3%TYPE;
d mytable.col4%TYPE;

BEGIN
idx :=0;

FOR a, b, c, d IN
SELECT col1, col2, col3, col4
FROM mytable
ORDER BY col1 ;

LOOP
-- Comment: Every iteration in loop will read a row from the cursor
idx := idx + 1;
raise notice 'Row %: [%, %, %, %]', idx, a, b, c, d;
END LOOP;
-- Comment: all rows have been read
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

In response to

  • Cursor at 2008-08-16 17:53:48 from Xavier Bermeo

Browse pgsql-sql by date

  From Date Subject
Next Message EXT-Rothermel, Peter M 2008-08-19 20:58:47 LIMIT question
Previous Message Edward W. Rouse 2008-08-19 18:03:48 Re: Join question