pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...
3+ messages / 3 participants
[nested] [flat]

* BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...
@ 2011-07-21 18:48 danielb@megasystems.us
  2011-07-21 22:23 ` Re: BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional... Tom Lane <tgl@sss.pgh.pa.us>
  2011-07-22 21:30 ` Re: BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional... Robert Haas <robertmhaas@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: danielb@megasystems.us @ 2011-07-21 18:48 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6128
Logged by:          
Email address:      danielb@megasystems.us
PostgreSQL version: 8.3
Operating system:   Windows XP
Description:        A boolean variable doesn't evaluate properly in an IF
conditional...
Details: 

I wrote some code in a PLPGSQL function to generate a printout string of
some information. Basically, I create a string of printed characters, which
my calling program will then print out...

I wrote an IF conditional to generate different printing based on what input
data I got...

I declared the variable "put_the_in_city_online boolean := 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 = 'Y') THEN
  IF (put_the_in_city_online = FALSE) THEN
    application_page_01 := application_page_01 || 
      '  SERVICES: ELECTRIC   ' || 
      rec.electric_rate_category || '              ' 
      || rec.in_or_out_of_city || end_of_line;

          put_the_in_city_online := true;
  ELSE
    application_page_01 := application_page_01 || 
      '            ELECTRIC   ' ||
      rec.electric_rate_category || end_of_line;
  END 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 =
FALSE) = true) correctly. This statement is true, but corresponding
statements are not executed; the statements for ((put_the_in_city_online =
FALSE) = false) end up being executed!

I don't see any flaw in my logic. Postgresql doesn't seem to work correctly
based on logic!



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...
  2011-07-21 18:48 BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional... danielb@megasystems.us
@ 2011-07-21 22:23 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2011-07-21 22:23 UTC (permalink / raw)
  To: danielb@megasystems.us; +Cc: pgsql-bugs

"" <danielb@megasystems.us> writes:
> For some reason, POSTGRESQL does not evaluate ((put_the_in_city_online =
> FALSE) = true) correctly.

This is pretty hard to believe, and you're not going to get anyone to
think it's anything except pilot error unless you provide a complete,
reproducible example.  Selectively quoting from your function does not
provide anything anyone could investigate.  Please see
http://wiki.postgresql.org/wiki/Guide_to_reporting_problems

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional...
  2011-07-21 18:48 BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional... danielb@megasystems.us
@ 2011-07-22 21:30 ` Robert Haas <robertmhaas@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Robert Haas @ 2011-07-22 21:30 UTC (permalink / raw)
  To: danielb@megasystems.us; +Cc: 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, which
> my calling program will then print out...
>
> I wrote an IF conditional to generate different printing based on what input
> data I got...
>
> I declared the variable "put_the_in_city_online boolean := 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 = 'Y') THEN
>  IF (put_the_in_city_online = FALSE) THEN
>    application_page_01 := application_page_01 ||
>      '  SERVICES: ELECTRIC   ' ||
>      rec.electric_rate_category || '              '
>      || rec.in_or_out_of_city || end_of_line;
>
>          put_the_in_city_online := true;
>  ELSE
>    application_page_01 := application_page_01 ||
>      '            ELECTRIC   ' ||
>      rec.electric_rate_category || end_of_line;
>  END 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 =
> FALSE) = true) correctly. This statement is true, but corresponding
> statements are not executed; the statements for ((put_the_in_city_online =
> FALSE) = false) end up being executed!
>
> I don't see any flaw in my logic. Postgresql doesn't seem to work correctly
> 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 = false) THEN
...
END IF;

won't either.

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2011-07-22 21:30 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21 18:48 BUG #6128: A boolean variable doesn't evaluate properly in an IF conditional... danielb@megasystems.us
2011-07-21 22:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-07-22 21:30 ` Robert Haas <robertmhaas@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox