From 0604116814a862d4d9dbc1a8866a2a3b0126caf1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 10 May 2016 12:49:56 -0400 Subject: Fix label referencing in SQL Server OFFSET logic Fixed bug where by ROW_NUMBER OVER clause applied for OFFSET selects in SQL Server would inappropriately substitute a plain column from the local statement that overlaps with a label name used by the ORDER BY criteria of the statement. Change-Id: Ic2500c886cbfc83a1ad5a2681783f008b9f23838 Fixes: #3711 --- lib/sqlalchemy/sql/util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 5f180646c..24c6f5441 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -176,6 +176,16 @@ def unwrap_order_by(clause): return result +def unwrap_label_reference(element): + def replace(elem): + if isinstance(elem, (_label_reference, _textual_label_reference)): + return elem.element + + return visitors.replacement_traverse( + element, {}, replace + ) + + def expand_column_list_from_order_by(collist, order_by): """Given the columns clause and ORDER BY of a selectable, return a list of column expressions that can be added to the collist -- cgit v1.2.1