Search Postgresql Archives

Re: pgsql-general@xxxxxxxxxxxxxx

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux