From 19f5371787df8d65137b7cf2ceb6c2a6b764cdca Mon Sep 17 00:00:00 2001 From: yxjames Date: Thu, 21 Jul 2016 17:53:25 -0700 Subject: [PATCH] In subquery use alias to do 'order by' (#795) * in subqry add orderby metric to select * add comment --- caravel/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/caravel/models.py b/caravel/models.py index 557190f322..a4c88a79d7 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -728,6 +728,9 @@ class SqlaTable(Model, Queryable, AuditMixinNullable): qry = qry.limit(row_limit) if timeseries_limit and groupby: + # some sql dialects require for order by expressions + # to also be in the select clause + inner_select_exprs += [main_metric_expr] subq = select(inner_select_exprs) subq = subq.select_from(tbl) subq = subq.where(and_(*(where_clause_and + inner_time_filter)))