From 2a03b97cd61b3f1dc0d7aec471cd5b581731897e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 1 Dec 2025 23:21:15 +0000 Subject: [PATCH] fix: mark window functions as aggregate expressions for CTE compatibility Window functions (those with OVER clause) are computed expressions that should not be looked up in underlying tables or CTEs. By setting IsAggregateExpr = true for window functions, we allow them to bypass column resolution in indirect queries (CTEs, subqueries, views). This fixes "cannot find col" errors when using window functions like RANK(), ROW_NUMBER(), SUM() OVER, etc. in queries that reference CTEs. --- internal/stackql/parserutil/parser_util.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/stackql/parserutil/parser_util.go b/internal/stackql/parserutil/parser_util.go index 0ddf2f86..aac48f8a 100644 --- a/internal/stackql/parserutil/parser_util.go +++ b/internal/stackql/parserutil/parser_util.go @@ -638,6 +638,11 @@ func inferColNameFromExpr( retVal.IsAggregateExpr = true retVal.Type = aggCol.getReturnType() } + // Window functions (with OVER clause) are computed expressions + // that don't need to be resolved from underlying tables/CTEs + if expr.Over != nil { + retVal.IsAggregateExpr = true + } if len(funcNameLowered) >= 4 && funcNameLowered[0:4] == "json" { decoratedColumn := strings.ReplaceAll(retVal.Name, `\"`, `"`) retVal.DecoratedColumn = getDecoratedColRendition(decoratedColumn, alias)