I was recently testing some logic based on columns of type boolean and
noticed some unintuitive behavior in PL/PgSQL.
I had a construct like the following:
IF NOT col1 AND NOT col2 THEN ...
In a scenario where both col1 and col2 were false, this condition was
not triggered. If I rewrote it as:
IF ( NOT col1 ) AND ( NOT col2 ) THEN ...
the condition was triggered as expected.
I would expect NOT to bind more closely than AND. The docs on what
behavior to expect here are pretty sparse in both the Logical Operators
section (9.1) and Expression Evaluation Rules (4.2.11). I couldn't find
anything either confirming or contradicting my expectations. Also, I
didn't try this in standard SQL in a case construct, but I would assume
the behavior would be the same?
If this is known and expected behavior, what would be the most
appropriate section of the docs for further explanation of order of
evaluation?
PostgreSQL 7.4.6 on i686-pc-linux-gnu, compiled by GCC 2.95.4.
-tfo
--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005