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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-sql by date

  From Date Subject
Next Message Jesus Aneiros 2000-08-12 20:57:56 Re: Operator Precedence problem?
Previous Message Philip Warner 2000-08-12 13:59:24 Re: Operator Precedence problem?