From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Noah Misch <noah(at)leadboat(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Precedence of standard comparison operators |
Date: | 2015-08-10 00:06:11 |
Message-ID: | 25558.1439165171@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Noah Misch <noah(at)leadboat(dot)com> writes:
> On Sun, Aug 09, 2015 at 07:16:02PM -0400, Tom Lane wrote:
>> Noah Misch <noah(at)leadboat(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2015-08-10 00:18:06 | Re: [patch] A \pivot command for psql |
Previous Message | Daniel Verite | 2015-08-09 23:51:58 | Re: [patch] A \pivot command for psql |