Обсуждение: loop query results

Поиск
Список
Период
Сортировка

loop query results

От
Stefan Reuschke
Дата:
With the following function I expected to get an iteration through the results. But the loop seems to be performed two
timesinstead.
 

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 6Xecht_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



Re: loop query results

От
Dennis Björklund
Дата:
On Wed, 4 Dec 2002, Stefan Reuschke wrote:

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

I tried you exact example in 7.2.1 and got every row only once. It doesn't
help you find the error perhaps, but it doesn't hurt to know that it works
as intended here.

-- 
/Dennis