loop query results

From: Stefan Reuschke <reuschke_ukl(at)web(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: loop query results
Date: 2002-12-04 08:58:37
Message-ID: 200212040858.gB48wbX04370@mailgate5.cinetic.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


With the following function I expected to get an iteration through the results. But the loop seems to be performed two times instead.

The function (postgres 7.2):

create function echt_char_laenge ()
returns integer
as

'
declare
char_auslese record;

begin
for char_auslese in select * from varlaenge loop
raise notice ''%, %'', char_auslese.id_var, char_auslese.var_text;
end loop;

return 0;
end;
'
language 'plpgsql';

------------------------------------------------------------

the result:

select echt_char_laenge ();

NOTICE: 1, text 1X
NOTICE: 2, text 2X
NOTICE: 3, text 3X
NOTICE: 4, text 4X
NOTICE: 5, text 5X
NOTICE: 6, text 6X
NOTICE: 1, text 1X
NOTICE: 2, text 2X
NOTICE: 3, text 3X
NOTICE: 4, text 4X
NOTICE: 5, text 5X
NOTICE: 6, text 6X
echt_char_laenge
------------------
0
(1 row)

----------

and the result as expected:

select * from varlaenge;

id_var | var_text
--------+-------------
1 | text 1X
2 | text 2X
3 | text 3X
4 | text 4X
5 | text 5X
6 | text 6X
(6 rows)

Any ideas?

Thanx
Stefan

______________________________________________________________________________
Schneller als andere! Die Blitz-SMS von WEB.DE FreeMail!
http://freemail.web.de/features/?mc=021167

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Dennis Björklund 2002-12-04 09:21:46 Re: loop query results
Previous Message Vernon Wu 2002-12-04 05:22:37 Re: How does postgres handle non literal string values