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

Reply via email to