Re: BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...
Дата
Msg-id CA+TgmobetS_LA2p3c631GzOLfuLyr1sp8CZOTFSqyVjRt4YrtA@mail.gmail.com
обсуждение исходный текст
Ответ на BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...  ("" <danielb@megasystems.us>)
Список pgsql-bugs
On Thu, Jul 21, 2011 at 2:48 PM,  <danielb@megasystems.us> wrote:
> I wrote some code in a PLPGSQL function to generate a printout string of
> some information. Basically, I create a string of printed characters, whi=
ch
> my calling program will then print out...
>
> I wrote an IF conditional to generate different printing based on what in=
put
> data I got...
>
> I declared the variable "put_the_in_city_online boolean :=3D false" in my
> declaration section. I then had the following IF conditional inside a FOR
> LOOP structure with a record variable called "rec"...
>
> -- If the applicant has electric services,
> -- then we display a line indicating such...
> IF (rec.has_electric =3D 'Y') THEN
> =A0IF (put_the_in_city_online =3D FALSE) THEN
> =A0 =A0application_page_01 :=3D application_page_01 ||
> =A0 =A0 =A0' =A0SERVICES: ELECTRIC =A0 ' ||
> =A0 =A0 =A0rec.electric_rate_category || ' =A0 =A0 =A0 =A0 =A0 =A0 =A0'
> =A0 =A0 =A0|| rec.in_or_out_of_city || end_of_line;
>
> =A0 =A0 =A0 =A0 =A0put_the_in_city_online :=3D true;
> =A0ELSE
> =A0 =A0application_page_01 :=3D application_page_01 ||
> =A0 =A0 =A0' =A0 =A0 =A0 =A0 =A0 =A0ELECTRIC =A0 ' ||
> =A0 =A0 =A0rec.electric_rate_category || end_of_line;
> =A0END IF;
> END IF;
>
> The bug occurs in the execution of these statements. I enter inside the
> first IF statement no problem, but the 2nd IF statement executes the
> opposite of what it should. The ELSE code is executing when the IF code
> should be executing!
>
> For some reason, POSTGRESQL does not evaluate ((put_the_in_city_online =
=3D
> FALSE) =3D true) correctly. This statement is true, but corresponding
> statements are not executed; the statements for ((put_the_in_city_online =
=3D
> FALSE) =3D false) end up being executed!
>
> I don't see any flaw in my logic. Postgresql doesn't seem to work correct=
ly
> based on logic!

I can't help wondering if you are somehow getting bitten by the
strange semantics of NULL comparisons.  Note that:

IF (something_that_is_null) THEN
...
END IF;

...will not trigger the if, and:

IF (something_that_is_null =3D false) THEN
...
END IF;

won't either.

--=20
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

Предыдущее
От: "Mario Danelli"
Дата:
Сообщение: BUG #6129: The installation fails with the error message: "Unable to write inside TEMP environment path"
Следующее
От: noordsij
Дата:
Сообщение: Re: BUG #6086: Segmentation fault