Re: hi, what is wrong with my newbie sql?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: hi, what is wrong with my newbie sql?
Дата
Msg-id 5643.1159384875@sss.pgh.pa.us
обсуждение исходный текст
Ответ на hi, what is wrong with my newbie sql?  ("Ronin" <jkoorts@gmail.com>)
Список pgsql-general
"Ronin" <jkoorts@gmail.com> writes:
>         k = 10;
>         FOR k IN 1..10 LOOP
>             k = k +1;
>         END LOOP;

>         return k;

An integer for-loop implicitly declares its control variable, so the "k"
inside the loop is unrelated to the "k" outside.  Hence you get 10.

As for what you'd get if they were the same variable, I dunno why you're
so certain it would be 20.  Munging a loop's control variable by hand is
a good way to trip over undocumented details of the loop implementation.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Andreas Kretschmer
Дата:
Сообщение: Re: hi, what is wrong with my newbie sql?
Следующее
От: Steve Wampler
Дата:
Сообщение: Re: How to create nightly backups in Linux