PL/PgSQL Boolean Comparison Operator Binding

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: PgSql General <pgsql-general(at)postgresql(dot)org>
Subject: PL/PgSQL Boolean Comparison Operator Binding
Date: 2005-01-15 16:55:51
Message-ID: 500EE0C5-6716-11D9-8CD3-000D93AE0944@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bo Lorentsen 2005-01-15 16:59:57 Re: OID Usage
Previous Message Bo Lorentsen 2005-01-15 16:53:08 Re: OID Usage