diff options
author | Sebastian Bank <sebastian.bank@uni-leipzig.de> | 2016-04-11 23:16:32 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-06 15:53:25 -0400 |
commit | 3351f5f93ca1968653becbed7f1ddef7afb96077 (patch) | |
tree | 0bc2a08dd5809522e23eed7a47b9f11bf95ad4b2 /lib/sqlalchemy/sql/operators.py | |
parent | a5f92314edd45a2e411b0f5b3c4d4bec0c7d92f8 (diff) | |
download | sqlalchemy-3351f5f93ca1968653becbed7f1ddef7afb96077.tar.gz |
Add IS (NOT) DISTINCT FROM operators
None / True / False render as literals.
For SQLite, "IS" is used as SQLite lacks
"IS DISTINCT FROM" but its "IS" operator acts
this way for NULL.
Doctext-author: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I9227b81f7207b42627a0349d14d40b46aa756cce
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/248
Diffstat (limited to 'lib/sqlalchemy/sql/operators.py')
-rw-r--r-- | lib/sqlalchemy/sql/operators.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 80f08a97c..bf470710d 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -311,6 +311,28 @@ class ColumnOperators(Operators): """ return self.operate(ne, other) + def is_distinct_from(self, other): + """Implement the ``IS DISTINCT FROM`` operator. + + Renders "a IS DISTINCT FROM b" on most platforms; + on some such as SQLite may render "a IS NOT b". + + .. versionadded:: 1.1 + + """ + return self.operate(is_distinct_from, other) + + def isnot_distinct_from(self, other): + """Implement the ``IS NOT DISTINCT FROM`` operator. + + Renders "a IS NOT DISTINCT FROM b" on most platforms; + on some such as SQLite may render "a IS b". + + .. versionadded:: 1.1 + + """ + return self.operate(isnot_distinct_from, other) + def __gt__(self, other): """Implement the ``>`` operator. @@ -722,6 +744,15 @@ def istrue(a): def isfalse(a): raise NotImplementedError() + +def is_distinct_from(a, b): + return a.is_distinct_from(b) + + +def isnot_distinct_from(a, b): + return a.isnot_distinct_from(b) + + def is_(a, b): return a.is_(b) @@ -931,6 +962,8 @@ _PRECEDENCE = { eq: 5, ne: 5, + is_distinct_from: 5, + isnot_distinct_from: 5, gt: 5, lt: 5, ge: 5, |