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/default_comparator.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/default_comparator.py')
-rw-r--r-- | lib/sqlalchemy/sql/default_comparator.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py index 1bb1c344c..7630a9821 100644 --- a/lib/sqlalchemy/sql/default_comparator.py +++ b/lib/sqlalchemy/sql/default_comparator.py @@ -39,6 +39,12 @@ def _boolean_compare(expr, op, obj, negate=None, reverse=False, op, type_=result_type, negate=negate, modifiers=kwargs) + elif op in (operators.is_distinct_from, operators.isnot_distinct_from): + return BinaryExpression(expr, + _literal_as_text(obj), + op, + type_=result_type, + negate=negate, modifiers=kwargs) else: # all other None/True/False uses IS, IS NOT if op in (operators.eq, operators.is_): @@ -51,8 +57,9 @@ def _boolean_compare(expr, op, obj, negate=None, reverse=False, negate=operators.is_) else: raise exc.ArgumentError( - "Only '=', '!=', 'is_()', 'isnot()' operators can " - "be used with None/True/False") + "Only '=', '!=', 'is_()', 'isnot()', " + "'is_distinct_from()', 'isnot_distinct_from()' " + "operators can be used with None/True/False") else: obj = _check_literal(expr, op, obj) @@ -249,6 +256,8 @@ operator_lookup = { "gt": (_boolean_compare, operators.le), "ge": (_boolean_compare, operators.lt), "eq": (_boolean_compare, operators.ne), + "is_distinct_from": (_boolean_compare, operators.isnot_distinct_from), + "isnot_distinct_from": (_boolean_compare, operators.is_distinct_from), "like_op": (_boolean_compare, operators.notlike_op), "ilike_op": (_boolean_compare, operators.notilike_op), "notlike_op": (_boolean_compare, operators.like_op), |