Re: Operator Precedence problem? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Operator Precedence problem?
Date
Msg-id 22816.966095790@sss.pgh.pa.us
Whole thread Raw
In response to Operator Precedence problem?  (Philip Warner <pjw@rhyme.com.au>)
List pgsql-sql
Philip Warner <pjw@rhyme.com.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


pgsql-sql by date:

Previous
From: Philip Warner
Date:
Subject: Re: Operator Precedence problem?
Next
From: Jesus Aneiros
Date:
Subject: Re: Operator Precedence problem?