summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/__init__.py2
-rw-r--r--lib/sqlalchemy/sql/compiler.py13
-rw-r--r--lib/sqlalchemy/sql/default_comparator.py7
-rw-r--r--lib/sqlalchemy/sql/elements.py9
-rw-r--r--lib/sqlalchemy/sql/operators.py16
5 files changed, 37 insertions, 10 deletions
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py
index 67155e0f2..8d77acc27 100644
--- a/lib/sqlalchemy/__init__.py
+++ b/lib/sqlalchemy/__init__.py
@@ -116,7 +116,7 @@ from .schema import (
from .inspection import inspect
from .engine import create_engine, engine_from_config
-__version__ = '0.9.4'
+__version__ = '0.9.5'
def __go(lcls):
global __all__
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 5165ee78f..af40b2537 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -93,7 +93,6 @@ OPERATORS = {
operators.ge: ' >= ',
operators.eq: ' = ',
operators.concat_op: ' || ',
- operators.between_op: ' BETWEEN ',
operators.match_op: ' MATCH ',
operators.in_op: ' IN ',
operators.notin_op: ' NOT IN ',
@@ -956,6 +955,18 @@ class SQLCompiler(Compiled):
if escape else ''
)
+ def visit_between_op_binary(self, binary, operator, **kw):
+ symmetric = binary.modifiers.get("symmetric", False)
+ return self._generate_generic_binary(
+ binary, " BETWEEN SYMMETRIC "
+ if symmetric else " BETWEEN ", **kw)
+
+ def visit_notbetween_op_binary(self, binary, operator, **kw):
+ symmetric = binary.modifiers.get("symmetric", False)
+ return self._generate_generic_binary(
+ binary, " NOT BETWEEN SYMMETRIC "
+ if symmetric else " NOT BETWEEN ", **kw)
+
def visit_bindparam(self, bindparam, within_columns_clause=False,
literal_binds=False,
skip_bind_expression=False,
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py
index 6d595450b..6bc7fb580 100644
--- a/lib/sqlalchemy/sql/default_comparator.py
+++ b/lib/sqlalchemy/sql/default_comparator.py
@@ -214,7 +214,11 @@ class _DefaultColumnComparator(operators.ColumnOperators):
self._check_literal(expr, operators.and_, cright),
operator=operators.and_,
group=False, group_contents=False),
- operators.between_op)
+ op,
+ negate=operators.notbetween_op
+ if op is operators.between_op
+ else operators.between_op,
+ modifiers=kw)
def _collate_impl(self, expr, op, other, **kw):
return collate(expr, other)
@@ -255,6 +259,7 @@ class _DefaultColumnComparator(operators.ColumnOperators):
"match_op": (_match_impl,),
"distinct_op": (_distinct_impl,),
"between_op": (_between_impl, ),
+ "notbetween_op": (_between_impl, ),
"neg": (_neg_impl,),
"getitem": (_unsupported_impl,),
"lshift": (_unsupported_impl,),
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index c230fb0d3..5ebc7478a 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -45,7 +45,7 @@ def collate(expression, collation):
_literal_as_text(collation),
operators.collate, type_=expr.type)
-def between(expr, lower_bound, upper_bound):
+def between(expr, lower_bound, upper_bound, symmetric=False):
"""Produce a ``BETWEEN`` predicate clause.
E.g.::
@@ -85,13 +85,18 @@ def between(expr, lower_bound, upper_bound):
:param upper_bound: a column or Python scalar expression serving as the
upper bound of the right side of the ``BETWEEN`` expression.
+ :param symmetric: if True, will render " BETWEEN SYMMETRIC ". Note
+ that not all databases support this syntax.
+
+ .. versionadded:: 0.9.5
+
.. seealso::
:meth:`.ColumnElement.between`
"""
expr = _literal_as_binds(expr)
- return expr.between(lower_bound, upper_bound)
+ return expr.between(lower_bound, upper_bound, symmetric=symmetric)
def literal(value, type_=None):
"""Return a literal clause, bound to a bind parameter.
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 91301c78c..bafe00979 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -584,10 +584,12 @@ class ColumnOperators(Operators):
"""
return self.reverse_operate(div, other)
- def between(self, cleft, cright):
+ def between(self, cleft, cright, symmetric=False):
"""Produce a :func:`~.expression.between` clause against
- the parent object, given the lower and upper range."""
- return self.operate(between_op, cleft, cright)
+ the parent object, given the lower and upper range.
+
+ """
+ return self.operate(between_op, cleft, cright, symmetric=symmetric)
def distinct(self):
"""Produce a :func:`~.expression.distinct` clause against the
@@ -707,8 +709,11 @@ def notilike_op(a, b, escape=None):
return a.notilike(b, escape=escape)
-def between_op(a, b, c):
- return a.between(b, c)
+def between_op(a, b, c, symmetric=False):
+ return a.between(b, c, symmetric=symmetric)
+
+def notbetween_op(a, b, c, symmetric=False):
+ return a.notbetween(b, c, symmetric=symmetric)
def in_op(a, b):
@@ -837,6 +842,7 @@ _PRECEDENCE = {
le: 5,
between_op: 5,
+ notbetween_op: 5,
distinct_op: 5,
inv: 5,
istrue: 5,