Re: strange infinite loop in plpgsql

From: "Vyacheslav Kalinin" <vka(at)mgcp(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: strange infinite loop in plpgsql
Date: 2007-11-10 17:21:48
Message-ID: 9b1af80e0711100921t46fcc821j7c4cee199f9c7cb7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Isn't "EXTRACT(dow FROM day) IN (0,6)" always true thus making select
return a row every time?

On 11/10/07, rihad <rihad(at)mail(dot)ru> wrote:
>
> I've been reading the online docs, but... code like this somehow ends up
> in an indefinite loop:
>
> CREATE OR REPLACE FUNCTION foo() RETURNS int AS $$
> DECLARE
> timeout int;
> day date;
> BEGIN
> day := current_date + 1;
> 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;
> END; $$ LANGUAGE plpgsql;
>
> It's Saturday at our place, and the "days" table has only one record for
> tomorrow's date.
>
> I hope it's been a very very long day for me :-) Thank you for your help.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-11-10 17:36:34 Re: strange infinite loop in plpgsql
Previous Message rihad 2007-11-10 17:06:26 strange infinite loop in plpgsql