summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-09-08 16:31:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-09-08 16:31:11 -0400
commit7904ebc62e0a75d1ea31e1a4ae67654c7681a737 (patch)
treea0e162ea74d3bb25390643b7db84bb288ca4e841 /lib/sqlalchemy/sql/elements.py
parente4996d4f5432657639798c1b286ee811a36e2a10 (diff)
downloadsqlalchemy-7904ebc62e0a75d1ea31e1a4ae67654c7681a737.tar.gz
- rework the previous "order by" system in terms of the new one,
unify everything. - create a new layer of separation between the "from order bys" and "column order bys", so that an OVER doesn't ORDER BY a label in the same columns clause - identify another issue with polymorphic for ref #3148, match on label keys rather than the objects
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index cf8de936d..8ec0aa700 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -2356,14 +2356,39 @@ class Extract(ColumnElement):
class _label_reference(ColumnElement):
+ """Wrap a column expression as it appears in a 'reference' context.
+
+ This expression is any that inclues an _order_by_label_element,
+ which is a Label, or a DESC / ASC construct wrapping a Label.
+
+ The production of _label_reference() should occur when an expression
+ is added to this context; this includes the ORDER BY or GROUP BY of a
+ SELECT statement, as well as a few other places, such as the ORDER BY
+ within an OVER clause.
+
+ """
__visit_name__ = 'label_reference'
- def __init__(self, text):
- self.text = self.key = text
+ def __init__(self, element):
+ self.element = element
+
+ def _copy_internals(self, clone=_clone, **kw):
+ self.element = clone(self.element, **kw)
+
+ @property
+ def _from_objects(self):
+ return ()
+
+
+class _textual_label_reference(ColumnElement):
+ __visit_name__ = 'textual_label_reference'
+
+ def __init__(self, element):
+ self.element = element
@util.memoized_property
def _text_clause(self):
- return TextClause._create_text(self.text)
+ return TextClause._create_text(self.element)
class UnaryExpression(ColumnElement):
@@ -3556,6 +3581,13 @@ def _clause_element_as_expr(element):
def _literal_as_label_reference(element):
if isinstance(element, util.string_types):
+ return _textual_label_reference(element)
+
+ elif hasattr(element, '__clause_element__'):
+ element = element.__clause_element__()
+
+ if isinstance(element, ColumnElement) and \
+ element._order_by_label_element is not None:
return _label_reference(element)
else:
return _literal_as_text(element)