Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon May 25, 2017
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon May 25, 2017
Michael Bayer (@zzzeek) wrote:
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
sqlalchemy-bot commentedon May 25, 2017
Michael Bayer (@zzzeek) wrote:
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: zzzeek/sqlalchemy#367
→ f8a3f14
sqlalchemy-bot commentedon May 25, 2017
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon May 8, 2018
Michael Bayer (@zzzeek) wrote:
Issue #4248 was marked as a duplicate of this issue.
IS NULL
#4248