See the postgresql documentation at:
>[mailto:pgadmin-support-owner(at)postgresql(dot)org] On Behalf Of
>Sent: dinsdag 24 april 2007 13:45
>Subject: [pgadmin-support] questions about cursors
>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
> mycursor CURSOR FOR select distinct(fund_id) from
> iterator integer;
Please see chapter 188.8.131.52 "FETCH" (in the 8.2 documentation).
Important for you is: "As with SELECT INTO, the special variable FOUND
may be checked to see whether a row was obtained or not."
>FETCH mycursor INTO iterator;
>--fetch next from mycursor --gives an error
WHILE (FOUND) LOOP
FETCH mycursor INTO interator;
-- instead of
>WHILE (FETCH next from mycursor) LOOP
> -- some computations here
I believe this should work. I've never really used cursors before, as I
can usually do it with regular SQL statements (which are usually
I should also advise that you can create your own aggregate (see CREATE
AGGREGATE in the documentation), which might, or might not, be easier
for your purposes.
>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.
When FOUND evaluates to false, you should have completed. (In case of
errors, you will probably have an exception being thrown).
>I will greatly appreciate any help, pgsql is my database of choice.
Hope this helps...
In response to
pgadmin-support by date
|Next:||From: Anton Andreev||Date: 2007-04-24 12:58:25|
|Subject: Re: [pgadmin-support] questions about cursors|
|Previous:||From: Anton Andreev||Date: 2007-04-24 11:45:10|
|Subject: questions about cursors|
pgsql-general by date
|Next:||From: Jeff Lanzarotta||Date: 2007-04-24 12:53:02|
|Subject: How does server handle clients that disconnect ungracefully?|
|Previous:||From: Wilkinson, Jim||Date: 2007-04-24 12:45:13|
|Subject: Re: hi |