cursor in plpgsql

From: "Grigoriy G(dot) Vovk" <vovk(at)sled(dot)rpa(dot)ryazan(dot)su>
To: pgsql-general(at)postgresql(dot)org
Subject: cursor in plpgsql
Date: 2000-04-03 10:56:51
Message-ID: 38E878F2.599EF55@sled.rpa.ryazan.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Titus Brown 2000-04-03 11:14:32 6.5.3: Two 'INHERITS' problems.
Previous Message Peter Eisentraut 2000-04-03 10:42:05 Re: sql92