Re: pgsql-general@postgresql.org

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Anton Andreev <fn30762(at)fmi(dot)uni-sofia(dot)bg>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pgsql-general@postgresql.org
Date: 2007-04-24 13:00:53
Message-ID: 20070424130053.GA4009@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moran 2007-04-24 13:02:54 Re: [GENERAL] pg_buffercache view
Previous Message Anton Andreev 2007-04-24 12:58:25 Re: [pgadmin-support] questions about cursors