Re: Function Problem

From: Torbj=?ISO-8859-1?B?9g==?=rn Andersson <tobbe(at)embryo(dot)se>
To: Sharon Cowling <sharon(dot)cowling(at)sslnz(dot)com>, "Pgsql-Novice (E-mail)" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Function Problem
Date: 2002-01-30 16:47:38
Message-ID: B87DE23A.149B%tobbe@embryo.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

02-01-30 02.47 Sharon Cowling sharon(dot)cowling(at)sslnz(dot)com
> I know how to do this using cursors inside a stored procedure in Oracle, but I
> understand that I cannot use cursors inside a function in Postgres in the
> version I am using: 7.1.3

You can use cursors i 7.1.3. I suggest something like:
CREATE FUNCTION overdue_key() returns int as '
DECLARE
row record;
BEGIN
FOR row IN
SELECT t key_code FROM faps_key
WHERE date_key_due > now()
LOOP
UPDATE faps_key
SET status = ''Overdue''
WHERE key_code = row.keycode;
END LOOP;
END;'LANGUAGE 'plpgsql';

Code is NOT tested...

Regards

Torbjörn Andersson
---------------------------------------------------
Embryo Communication phone: +46 (0) 31-774 39 11(00)
Kungsgatan 7a fax: +46 (0)31 774 07 80
S-411 19 Göteborg mobile: 0708-30 70 04
Sweden home: http://www.embryo.se/
mail: torbjorn(dot)andersson(at)embryo(dot)se
---------------------------------------------------
"Att idag tänka annorlunda än igår skiljer den vise från den envise." — John
Steinbeck

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Torbj=?ISO-8859-1?B?9g==?=rn Andersson 2002-01-30 16:49:51 Re: 16k query limit
Previous Message Josh Berkus 2002-01-30 16:45:50 Re: text field