Search Postgresql Archives

Re: strange infinite loop in plpgsql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



rihad <rihad@xxxxxxx> 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.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux