From 0883d8213bcfbeb5e0ae6dd1cbcf70494eb06dac Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 23 Mar 2017 15:11:03 -0400 Subject: Treat collation names as identifiers The expression used for COLLATE as rendered by the column-level :func:`.expression.collate` and :meth:`.ColumnOperators.collate` is now quoted as an identifier when the name is case sensitive, e.g. has uppercase characters. Note that this does not impact type-level collation, which is already quoted. Change-Id: I83d5d9cd1e66a4f20b96303bb84c5f360d5d6a1a Fixes: #3785 --- lib/sqlalchemy/sql/elements.py | 8 +++++++- lib/sqlalchemy/sql/operators.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index a450efaf0..1f8129382 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -41,12 +41,18 @@ def collate(expression, collation): mycolumn COLLATE utf8_bin + The collation expression is also quoted if it is a case sensitive + identifer, e.g. contains uppercase characters. + + .. versionchanged:: 1.2 quoting is automatically applied to COLLATE + expressions if they are case sensitive. + """ expr = _literal_as_binds(expression) return BinaryExpression( expr, - _literal_as_text(collation), + ColumnClause(collation), operators.collate, type_=expr.type) diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 8f697b27e..49642acdd 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -695,7 +695,13 @@ class ColumnOperators(Operators): def collate(self, collation): """Produce a :func:`~.expression.collate` clause against - the parent object, given the collation string.""" + the parent object, given the collation string. + + .. seealso:: + + :func:`~.expression.collate` + + """ return self.operate(collate, collation) def __radd__(self, other): -- cgit v1.2.1