cursor in plpgsql - Mailing list pgsql-general

From Grigoriy G. Vovk
Subject cursor in plpgsql
Date
Msg-id 38E878F2.599EF55@sled.rpa.ryazan.su
Whole thread Raw
Responses Re: cursor in plpgsql  (wieck@debis.com (Jan Wieck))
List pgsql-general
Sorry for my bad english!

Can I use "DECLARE CURSOR" in plpgsql function?
I have :
    create table ipacc(ip_from inet,
            sourse_ports int2,
            ip_to inet,
            dist_port,
            bytes int4,
            packets int4,
            when_time datetime)

I want to build report (I'm planing step):
    1. CURSOR select distinct ip_from from ipacc;
    2. FETCH from cursor into variable;
    3. select sum(bytes) from ipacc where ip_from = variable;
    4. Do while FETCH return row;
I do:
CREATE FUNCTION report() RETURNS text AS '
BEGIN WORK;
    DECLARE
        host_cursor CURSOR FOR SELECT DISTINCT ip_from FROM ipacc;
        host record;
        host_sum int4;
    BEGIN
        WHILE (FETCH FROM host_cursor INTO :host) LOOP;
        SELECT sum(bytes) from ipacc where ip_from=host;
        END LOOP;
    END;
psql report - CREATE
I do: select report();
psql report - NOTICE: plpgsql: ERROR during compile of report near line
3
ERROR: parse error at or near "CURSOR"

Where I do mistake?
--
---------
Grigoriy G. Vovk

pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: sql92
Next
From: Titus Brown
Date:
Subject: 6.5.3: Two 'INHERITS' problems.