diff --git a/parser/ast_expr.go b/parser/ast_expr.go index 8b73632..a9dc367 100644 --- a/parser/ast_expr.go +++ b/parser/ast_expr.go @@ -215,7 +215,13 @@ func (f *FunctionExpr) Pos() Pos { } func (f *FunctionExpr) End() Pos { - return f.Params.RightParenPos + 1 + params := f.Params + // Bare EXCEPT col uses the column's bounds as its synthetic paren + // positions, so the right position is already exclusive. + if items := params.Items; items != nil && params.LeftParenPos == items.Pos() && params.RightParenPos == items.End() { + return params.RightParenPos + } + return params.RightParenPos + 1 } func (f *FunctionExpr) Accept(visitor ASTVisitor) error { diff --git a/parser/position_test.go b/parser/position_test.go index 6289975..4200bd5 100644 --- a/parser/position_test.go +++ b/parser/position_test.go @@ -135,6 +135,8 @@ func TestSourceSpansCoverReportedNodes(t *testing.T) { {"SELECT ?", "?", func(e Expr) Expr { return e.(*SelectQuery).SelectItems[0].Expr }}, {"SELECT 'abc'", "'abc'", func(e Expr) Expr { return e.(*SelectQuery).SelectItems[0].Expr }}, {"SELECT f(1)", "f(1)", func(e Expr) Expr { return e.(*SelectQuery).SelectItems[0].Expr }}, + {"SELECT t.* EXCEPT b, c FROM t", "EXCEPT b", func(e Expr) Expr { return e.(*SelectQuery).SelectItems[0].Modifiers[0] }}, + {"SELECT t.* EXCEPT (b), c FROM t", "EXCEPT (b)", func(e Expr) Expr { return e.(*SelectQuery).SelectItems[0].Modifiers[0] }}, } { t.Run(tc.sql, func(t *testing.T) { stmt := parseOneStmt(t, tc.sql)