Re: 9.5 "chained equality" behavior

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joshua Ma <josh(at)benchling(dot)com>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: 9.5 "chained equality" behavior
Date: 2017-05-30 21:23:59
Message-ID: 3482.1496179439@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua Ma <josh(at)benchling(dot)com> writes:
> Our team is upgrading from 9.4 to 9.5, and we noticed this behavior change:
> 9.5:
> # SELECT true = true = true;
> ERROR: syntax error at or near "="
> LINE 1: SELECT true = true = true;

> Now, there's actually a larger problem with this, since it's not actually
> chained equality and only looks like it. It looks like 9.4 is evaluating
> right-to-left. We're going to fix usages of this to instead do (a = b && a
> = c) instead of (a = b = c).

> However, I wanted to email in because I couldn't see what in the 9.5
> changelog (https://www.postgresql.org/docs/9.6/static/release-9-5.html)
> would cause this to syntax error.

This is a consequence of commit c6b3c939b "Make operator precedence follow
the SQL standard more closely", which removed the former "%right '='"
grammar declaration. That caused "a = b = c" to be parsed as "a = (b = c)",
which was surprising, and wouldn't work at all unless a was boolean.
Now "=" is declared %nonassoc, so that if you actually want behavior like
that, you need to write some parens. But it seems much more likely that
people writing that are making a mistake.

We discussed the associativity-of-= issue in the thread leading up to
that patch,
https://www.postgresql.org/message-id/flat/12603.1424360914%40sss.pgh.pa.us
but I evidently forgot to mention this detail in the commit log message,
so it didn't get into the release notes either.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2017-05-30 21:32:20 Re: 9.5 "chained equality" behavior
Previous Message John R Pierce 2017-05-30 21:20:22 Re: Access Management question