Noah Misch <noah@leadboat.com> writes:
> On Sun, Aug 09, 2015 at 07:16:02PM -0400, Tom Lane wrote:
>> Noah Misch <noah@leadboat.com> writes:
>>> It does risk that. Same deal with making "=" have the same precedence as "<"
>>> instead of keeping it slightly lower.
>> Agreed, but in that case I think our hand is forced by the SQL standard.
> In SQL:2008 and SQL:2011 at least, "=", "<" and "BETWEEN" are all in the same
> boat. They have no precedence relationships to each other; SQL sidesteps the
> question by requiring parentheses. They share a set of precedence
> relationships to other constructs. SQL does not imply whether to put them in
> one %nonassoc precedence group or in a few, but we can contemplate whether
> users prefer an error or prefer the 9.4 behavior for affected queries.
Part of my thinking was that the 9.4 behavior fails the principle of least
astonishment, because I seriously doubt that people expect '=' to be
either right-associative or lower priority than '<'. Here's one example:
regression=# select false = true < false;?column?
----------t
(1 row)
Not only does that seem unintuitive, but I actually had to experiment
a bit before finding a combination of values in which I got a different
result from what you'd expect if you think the precedence is (x = y) < z.
So it's not hard to imagine that somebody might write a query thinking
that that's how it works, and even have it get through desultory testing
before silently giving unexpected answers in production.
So yeah, I do think that getting a syntax error if you don't use
parentheses is the preferable behavior here.
regards, tom lane