From: | rihad <rihad(at)mail(dot)ru> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: strange infinite loop in plpgsql |
Date: | 2007-11-11 03:52:48 |
Message-ID: | 47367C90.1040009@mail.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>> rihad <rihad(at)mail(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2007-11-11 05:34:45 | Re: any way for ORDER BY x to imply NULLS FIRST in 8.3? |
Previous Message | Tom Lane | 2007-11-11 01:55:30 | Re: (Never?) Kill Postmaster? |