Re: strange infinite loop in plpgsql

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: strange infinite loop in plpgsql
Дата
Msg-id 16944.1194716194@sss.pgh.pa.us
обсуждение исходный текст
Ответ на strange infinite loop in plpgsql  (rihad <rihad@mail.ru>)
Ответы Re: strange infinite loop in plpgsql  (rihad <rihad@mail.ru>)
Re: strange infinite loop in plpgsql  (rihad <rihad@mail.ru>)
Список pgsql-general
rihad <rihad@mail.ru> writes:
>      LOOP
>        SELECT date+1 INTO day FROM days WHERE date=day OR EXTRACT(dow
> FROM day) IN (0,6);
>        EXIT WHEN NOT FOUND;
>        timeout := timeout + 86400;
>      END LOOP;

If the EXTRACT condition is true, then the SELECT will always succeed.
This code will get even more whacko once you have more than one row
in "days", because it'll pick a random one of the rows in that case
(in practice, the physically first one).  I think you need something
more like

    LOOP
      IF EXTRACT(dow FROM day) IN (0,6) THEN
        -- don't bother to consult table on weekends
        day := day + 1;
      ELSE
        SELECT date+1 INTO day FROM days WHERE date=day;
        EXIT WHEN NOT FOUND;
      END IF;
      timeout := timeout + 86400;
    END LOOP;

BTW, you forgot to initialize "timeout".

            regards, tom lane

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

Предыдущее
От: rihad
Дата:
Сообщение: strange infinite loop in plpgsql
Следующее
От: Tom Lane
Дата:
Сообщение: Re: (Never?) Kill Postmaster?