diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-04-16 00:53:21 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-04-16 00:53:21 +0000 |
commit | 24797113708c0f19ef0d5d81e2950b33f8c1a425 (patch) | |
tree | 7e44582f775579cf40679112a2611e1bbab84d87 /lib/sqlalchemy/sql/expression.py | |
parent | f5126ab3a169b6f8a9171868fe32b2bd385f8b8f (diff) | |
download | sqlalchemy-24797113708c0f19ef0d5d81e2950b33f8c1a425.tar.gz |
- Support for COLLATE: collate(expr, col) and expr.collate(col)
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 648e74e7e..8c439ce2c 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -40,7 +40,7 @@ __all__ = [ 'Select', 'Selectable', 'TableClause', 'Update', 'alias', 'and_', 'asc', 'between', 'bindparam', 'case', 'cast', 'column', 'delete', 'desc', 'distinct', 'except_', 'except_all', 'exists', 'extract', 'func', - 'modifier', + 'modifier', 'collate', 'insert', 'intersect', 'intersect_all', 'join', 'literal', 'literal_column', 'not_', 'null', 'or_', 'outparam', 'outerjoin', 'select', 'subquery', 'table', 'text', 'union', 'union_all', 'update', ] @@ -493,6 +493,14 @@ def extract(field, expr): expr = _BinaryExpression(text(field), expr, operators.from_) return func.extract(expr) +def collate(expression, collation): + """Return the clause ``expression COLLATE collation``.""" + + expr = _literal_as_binds(expression) + return _CalculatedClause( + expr, expr, _literal_as_text(collation), + operator=operators.collate, group=False) + def exists(*args, **kwargs): """Return an ``EXISTS`` clause as applied to a [sqlalchemy.sql.expression#Select] object. @@ -1226,6 +1234,9 @@ class ColumnOperators(Operators): def asc(self): return self.operate(operators.asc_op) + def collate(self, collation): + return self.operate(operators.collate, collation) + def __radd__(self, other): return self.reverse_operate(operators.add, other) @@ -1390,6 +1401,13 @@ class _CompareMixin(ColumnOperators): return _BinaryExpression(self, ClauseList(self._check_literal(cleft), self._check_literal(cright), operator=operators.and_, group=False), operators.between_op) + def collate(self, collation): + """Produce a COLLATE clause, i.e. ``<column> COLLATE utf8_bin``""" + name = getattr(self, 'name', None) + return _CalculatedClause( + None, self, _literal_as_text(collation), + operator=operators.collate, group=False) + def op(self, operator): """produce a generic operator function. |