postgresql/src/backend
Tom Lane c6b3c939b7 Make operator precedence follow the SQL standard more closely.
While the SQL standard is pretty vague on the overall topic of operator
precedence (because it never presents a unified BNF for all expressions),
it does seem reasonable to conclude from the spec for <boolean value
expression> that OR has the lowest precedence, then AND, then NOT, then IS
tests, then the six standard comparison operators, then everything else
(since any non-boolean operator in a WHERE clause would need to be an
argument of one of these).

We were only sort of on board with that: most notably, while "<" ">" and
"=" had properly low precedence, "<=" ">=" and "<>" were treated as generic
operators and so had significantly higher precedence.  And "IS" tests were
even higher precedence than those, which is very clearly wrong per spec.

Another problem was that "foo NOT SOMETHING bar" constructs, such as
"x NOT LIKE y", were treated inconsistently because of a bison
implementation artifact: they had the documented precedence with respect
to operators to their right, but behaved like NOT (i.e., very low priority)
with respect to operators to their left.

Fixing the precedence issues is just a small matter of rearranging the
precedence declarations in gram.y, except for the NOT problem, which
requires adding an additional lookahead case in base_yylex() so that we
can attach a different token precedence to NOT LIKE and allied two-word
operators.

The bulk of this patch is not the bug fix per se, but adding logic to
parse_expr.c to allow giving warnings if an expression has changed meaning
because of these precedence changes.  These warnings are off by default
and are enabled by the new GUC operator_precedence_warning.  It's believed
that very few applications will be affected by these changes, but it was
agreed that a warning mechanism is essential to help debug any that are.
2015-03-11 13:22:52 -04:00
..
access Add macros wrapping all usage of gcc's __attribute__. 2015-03-11 14:30:01 +01:00
bootstrap Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
catalog Fix crasher bugs in previous commit 2015-03-09 17:00:43 -03:00
commands Allow named parameters to be specified using => in addition to := 2015-03-10 11:09:41 -04:00
executor Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
foreign Update copyright for 2015 2015-01-06 11:43:47 -05:00
lib Fix a bug in pairing heap removal code. 2015-02-17 22:55:53 +02:00
libpq Use FLEXIBLE_ARRAY_MEMBER in a number of other places. 2015-02-21 16:12:14 -05:00
main Don't require users of src/port/gettimeofday.c to initialize it. 2015-02-21 12:17:04 -05:00
nodes Make operator precedence follow the SQL standard more closely. 2015-03-11 13:22:52 -04:00
optimizer Fix long-obsolete code for separating filter conditions in cost_index(). 2015-03-03 21:19:42 -05:00
parser Make operator precedence follow the SQL standard more closely. 2015-03-11 13:22:52 -04:00
po Translation updates 2015-02-01 23:23:40 -05:00
port Remove the option to service interrupts during PGSemaphoreLock(). 2015-02-03 23:25:00 +01:00
postmaster Add macros wrapping all usage of gcc's __attribute__. 2015-03-11 14:30:01 +01:00
regex Replace a bunch more uses of strncpy() with safer coding. 2015-01-24 13:05:42 -05:00
replication Add macros wrapping all usage of gcc's __attribute__. 2015-03-11 14:30:01 +01:00
rewrite Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
snowball Update copyright for 2015 2015-01-06 11:43:47 -05:00
storage Guard against spurious signals in LockBufferForCleanup. 2015-02-23 16:14:14 +01:00
tcop Code cleanup for REINDEX DATABASE/SCHEMA/SYSTEM. 2015-03-08 12:18:43 -04:00
tsearch Update copyright for 2015 2015-01-06 11:43:47 -05:00
utils Make operator precedence follow the SQL standard more closely. 2015-03-11 13:22:52 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Update copyright for 2015 2015-01-06 11:43:47 -05:00
nls.mk Translation updates 2015-02-01 23:23:40 -05:00