From: | Sim Zacks <sim(at)compulab(dot)co(dot)il> |
---|---|
To: | Anton Andreev <fn30762(at)fmi(dot)uni-sofia(dot)bg> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [pgadmin-support] questions about cursors |
Date: | 2007-04-26 13:09:05 |
Message-ID: | 1637593189.20070426150905@compulab.co.il |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgadmin-support pgsql-general |
Anton,
Wrong mailing list. You should send this type of query to
pgsql-general(at)postgresql(dot)org in the future. The documentation is confusing,
though. Try This:
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;
while found Loop
-- some computations here
FETCH mycursor INTO iterator;
END LOOP;
CLOSE mycursor;
END;
Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax
________________________________________________________________________________
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
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly
From | Date | Subject | |
---|---|---|---|
Next Message | Liviu Rau | 2007-04-27 09:37:28 | Pgadmin does not execute backup on table on tablespace |
Previous Message | Joris Dobbelsteen | 2007-04-25 20:31:35 | Re: Server not listening |
From | Date | Subject | |
---|---|---|---|
Next Message | Bill Moran | 2007-04-26 13:28:57 | Re: [GENERAL] pg_buffercache view |
Previous Message | Sorin N. Ciolofan | 2007-04-26 13:05:14 | Re: [GENERAL] pg_buffercache view |