Skip site navigation (1) Skip section navigation (2)

Re: Operator Precedence problem?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: Operator Precedence problem?
Date: 2000-08-12 15:56:30
Message-ID: 22816.966095790@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> Which makes me think that the precedence of 'or' is not what I
> expected.

OR is certainly lower-precedence than AND --- this is hard-wired in the
grammar and not subject to change across databases.  It's also required
by SQL92:

         <search condition> ::=
                <boolean term>
              | <search condition> OR <boolean term>

         <boolean term> ::=
                <boolean factor>
              | <boolean term> AND <boolean factor>

         <boolean factor> ::=
              [ NOT ] <boolean test>

         <boolean test> ::=
              <boolean primary> [ IS [ NOT ] <truth value> ]

         <truth value> ::=
                TRUE
              | FALSE
              | UNKNOWN

         <boolean primary> ::=
                <predicate>
              | <left paren> <search condition> <right paren>

BTW, I notice that we do not correctly implement the IS tests.
The parser turns them into "<primary> = 't'::bool" and so on,
which is wrong because it will yield NULL for NULL input, which
is contrary to the spec for these tests.  We need specialized
functions comparable to the ones for IS NULL (in fact, IS UNKNOWN
should be equivalent to IS NULL except for requiring a boolean
input, AFAICT).

			regards, tom lane

In response to

pgsql-sql by date

Next:From: Jesus AneirosDate: 2000-08-12 20:57:56
Subject: Re: Operator Precedence problem?
Previous:From: Philip WarnerDate: 2000-08-12 13:59:24
Subject: Re: Operator Precedence problem?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group