pgsql-general@postgresql.org - Mailing list pgsql-general

From Anton Andreev
Subject pgsql-general@postgresql.org
Date
Msg-id 462DF230.1040504@fmi.uni-sofia.bg
Whole thread Raw
Responses Re: pgsql-general@postgresql.org
List pgsql-general
Hi,

I am trying to use cursors and I am really frustrated already. Do  I
need to install an extension?

1. Problem number one is that what ever I use in front of the fetch
command it is not being accepted, it gives a syntax error. If I use a
number ,"all" or "forward" it gives an error again?????????? I want to
do something like the code below:

CREATE OR REPLACE FUNCTION database_correction()
  RETURNS double precision AS
$BODY$
DECLARE
    mycursor CURSOR FOR select distinct(fund_id) from
"NAV_values_bfb_history";
    iterator integer;

BEGIN
open mycursor;

FETCH mycursor INTO iterator;

--fetch next  from  mycursor  --gives  an error

WHILE (FETCH next from mycursor) LOOP
    -- some computations here
END LOOP;

CLOSE mycursor;
END;

2. What is the right way to check that the cursor has ended. In
sqlserver there is a variable "@@fetch_status". I have to make here some
comparison in the while clause, but I am not sure what it should be. I
could not find a single example for cursor in a loop.

I will greatly appreciate any help, pgsql is my database of choice.

Cheers,
Anton



pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Setting table ids in slony
Next
From: "Peter Neu"
Date:
Subject: Problem Backing Up a DB