pgpl-problem, what's wrong with my loop?

From: Bruno Boettcher <bboett(at)erm1(dot)u-strasbg(dot)fr>
To: pgsql-sql(at)postgresql(dot)org
Subject: pgpl-problem, what's wrong with my loop?
Date: 2000-11-20 16:21:05
Message-ID: 20001120172105.E25191@erm1.u-strasbg.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

once more, i ran into a problem....
i got no syntax error, i don't know how to debug, except for raising
exceptions.... the loop never executes.... making the select call by hand
with fixed values, returns a result... but the second raise is never passed
with the function...so something seems wrong....


CREATE FUNCTION accSum(text,text) RETURNS int4 AS '
DECLARE
col ALIAS FOR $1;
sumup ALIAS FOR $2;
actsum journal.amount%TYPE;
arow journal%ROWTYPE;
conversion float4;
temp float4;
sum int4;
BEGIN
sum := 0;
RAISE NOTICE ''stats %=% '', col,sumup;
FOR arow IN SELECT currency,amount FROM journal WHERE col=sumup LOOP
RAISE NOTICE ''% current line: %'', arow.id,arow.amount;
SELECT conv FROM currencies WHERE tag=arow.currency INTO conversion;
temp := conversion*arow.amount+0.5;
sum := sum + temp;
END LOOP;
return sum;
END;
' LANGUAGE 'plpgsql';

as sayd :
fibu=> select accSum('plus','102');
NOTICE: stats plus=102
accsum
--------
0
(1 row)

fibu=> SELECT currency,amount FROM journal WHERE plus=102;
currency | amount
----------+--------
EUR | 100000
EUR | 100000
EUR | 100000
EUR | 100000
EUR | 100000
(5 rows)

surely some stupid error somewhere.....

--
ciao bboett
==============================================================
bboett(at)earthling(dot)net
http://inforezo.u-strasbg.fr/~bboett http://erm1.u-strasbg.fr/~bboett
===============================================================
the total amount of intelligence on earth is constant.
human population is growing....

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-11-20 16:37:40 Re: pgpl-problem, what's wrong with my loop?
Previous Message Jonathan Ellis 2000-11-20 15:59:33 Re: numeric conversions?