Skip to content

Commit e755b7a

Browse files
committed
fix: only use astformat.String for window functions with OVER clause
The previous change broke json_extract and other multi-argument functions because astformat.String doesn't apply the same recursive processing to arguments that the manual construction does. Now only use astformat.String when expr.Over != nil (actual window functions), keeping the original fmt.Sprintf behavior for regular functions to maintain proper argument decoration.
1 parent 5b9e1aa commit e755b7a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

internal/stackql/parserutil/parser_util.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,14 @@ func inferColNameFromExpr(
676676
exprsDecorated = append(exprsDecorated, rv.DecoratedColumn)
677677
}
678678
}
679-
// Use astformat.String to include OVER clause for window functions
680-
decoratedColumn := astformat.String(expr, formatter)
679+
// Use astformat.String for window functions to include OVER clause,
680+
// otherwise use the manually constructed decorated column for proper arg handling
681+
var decoratedColumn string
682+
if expr.Over != nil {
683+
decoratedColumn = astformat.String(expr, formatter)
684+
} else {
685+
decoratedColumn = fmt.Sprintf("%s(%s)", funcNameLowered, strings.Join(exprsDecorated, ", "))
686+
}
681687
if retVal.Name != constants.SQLFuncJSONExtractPostgres {
682688
retVal.DecoratedColumn = getDecoratedColRendition(decoratedColumn, alias)
683689
}

0 commit comments

Comments
 (0)