Skip to content

Commit 2a03b97

Browse files
committed
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.
1 parent a6bcfc3 commit 2a03b97

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/stackql/parserutil/parser_util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ func inferColNameFromExpr(
638638
retVal.IsAggregateExpr = true
639639
retVal.Type = aggCol.getReturnType()
640640
}
641+
// Window functions (with OVER clause) are computed expressions
642+
// that don't need to be resolved from underlying tables/CTEs
643+
if expr.Over != nil {
644+
retVal.IsAggregateExpr = true
645+
}
641646
if len(funcNameLowered) >= 4 && funcNameLowered[0:4] == "json" {
642647
decoratedColumn := strings.ReplaceAll(retVal.Name, `\"`, `"`)
643648
retVal.DecoratedColumn = getDecoratedColRendition(decoratedColumn, alias)

0 commit comments

Comments
 (0)