Re: strange infinite loop in plpgsql
От | rihad |
---|---|
Тема | Re: strange infinite loop in plpgsql |
Дата | |
Msg-id | 47367C90.1040009@mail.ru обсуждение исходный текст |
Ответ на | Re: strange infinite loop in plpgsql (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | 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. > > Isn't the new "day" re-evaluated on every loop iteration? I'm totally > confused. It's morning again over at our place, so... of course it's not! I stupidly did a SELECT date+1 instead of SELECT day+1, resulting in an infinite loop. A hard to spot bug, especially when your eyes are half closed. Good thing is that the solution came to me while I was still in bed a minute ago :-) But your idea later on of separating EXTRACT outside the disk-touching code might be a nice cpu-memory trade-off that I hadn't thought of (or wasn't aware). It turns out any SQL "thing" can be in an IF or WHILE etc. ? I'll go read the docs more attentively.
В списке pgsql-general по дате отправления: