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

From Alvaro Herrera
Subject Re: pgsql-general@postgresql.org
Date
Msg-id 20070424130053.GA4009@alvh.no-ip.org
Whole thread Raw
In response to pgsql-general@postgresql.org  (Anton Andreev <fn30762@fmi.uni-sofia.bg>)
List pgsql-general
Anton Andreev wrote:
> Hi,
>
> I am trying to use cursors and I am really frustrated already. Do  I
> need to install an extension?

No, you just need to have a look at the docs.
http://www.postgresql.org/docs/8.2/static/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING

> 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$
> [...]

Try something like this:

CREATE OR REPLACE FUNCTION database_correction()
 RETURNS double precision LANGUAGE plpgsql AS
$body$
DECLARE
   fund INTEGER;
BEGIN
   FOR fund IN SELECT DISTINCT(fund_id) FROM "NAV_values_bfb_history" LOOP
     RAISE NOTICE $$ foo bar $$;
     -- some computations here
   END LOOP;
   RETURN 42.0;
END;
$body$;

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

pgsql-general by date:

Previous
From: Anton Andreev
Date:
Subject: Re: [pgadmin-support] questions about cursors
Next
From: Bill Moran
Date:
Subject: Re: pg_buffercache view