Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

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: Tue, 19 Aug 2008 15:38:00 -0300
  • Message-id: <022701c9022a$b4e46a00$8f01010a@iptel.com.ar> <text/plain>

> 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;



  • References:

Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group