merge operator precedence for all like / is / eq / comparison to 5

Issue #3999 resolved
Mike Bayer repo owner created an issue

e.g.:

--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -1091,18 +1091,19 @@ _PRECEDENCE = {
     sub: 7,

     concat_op: 6,
-    match_op: 6,
-    notmatch_op: 6,
-
-    ilike_op: 6,
-    notilike_op: 6,
-    like_op: 6,
-    notlike_op: 6,
-    in_op: 6,
-    notin_op: 6,
-
-    is_: 6,
-    isnot: 6,
+
+    match_op: 5,
+    notmatch_op: 5,
+
+    ilike_op: 5,
+    notilike_op: 5,
+    like_op: 5,
+    notlike_op: 5,
+    in_op: 5,
+    notin_op: 5,
+
+    is_: 5,
+    isnot: 5,

     eq: 5,
     ne: 5,

rationale: MySQL, Oracle and now Postgresql all have relatively flat precedences for these operators:

(mysql): https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/operator-precedence.html

(oracle):

https://docs.oracle.com/cd/B19306_01/server.102/b14200/conditions001.htm#i1034834

pg 9.4, less flat: https://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html#SQL-PRECEDENCE-TABLE

pg 9.5, now is more flat: https://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#SQL-PRECEDENCE-TABLE

making these all have the same precedence means we'll just have more parenthesis.

Comments (3)

  1. Mike Bayer reporter

    sort of on the fence about concat I think it should be higher precedence, experiments w/ some dbs confirms it has higher prec than comparison operators

  2. Mike Bayer reporter

    Flatten operator precedence for comparison operators

    The operator precedence for all comparison operators such as LIKE, IS, IN, MATCH, equals, greater than, less than, etc. has all been merged into one level, so that expressions which make use of these against each other will produce parentheses between them. This suits the stated operator precedence of databases like Oracle, MySQL and others which place all of these operators as equal precedence, as well as Postgresql as of 9.5 which has also flattened its operator precendence.

    Co-authored-by: Mike Bayer mike_mp@zzzcomputing.com Fixes: #3999 Change-Id: I3f3d5124a64af0d376361cdf15a97e2e703be56f Pull-request: https://github.com/zzzeek/sqlalchemy/pull/367

    → <<cset f8a3f14e4f86>>

  3. Log in to comment