Skip to content

Commit a3930da

Browse files
With clause support.
1 parent fa869a8 commit a3930da

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

stringify.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package sqlparser
33
import (
44
"bytes"
55
"fmt"
6+
"strings"
7+
68
"github.com/viant/sqlparser/column"
79
del "github.com/viant/sqlparser/delete"
810
"github.com/viant/sqlparser/expr"
@@ -12,7 +14,6 @@ import (
1214
"github.com/viant/sqlparser/query"
1315
"github.com/viant/sqlparser/table"
1416
"github.com/viant/sqlparser/update"
15-
"strings"
1617
)
1718

1819
// Stringify stringifies node
@@ -30,6 +31,26 @@ func stringify(n node.Node, builder *bytes.Buffer) {
3031
case string:
3132
builder.WriteString(actual)
3233
case *query.Select:
34+
if len(actual.WithSelects) > 0 {
35+
builder.WriteString("WITH ")
36+
for i, withSel := range actual.WithSelects {
37+
if i > 0 {
38+
builder.WriteString(", ")
39+
}
40+
builder.WriteString(withSel.Alias)
41+
builder.WriteString(" AS ")
42+
if withSel.Raw != "" {
43+
builder.WriteString(withSel.Raw)
44+
} else if withSel.X != nil {
45+
builder.WriteString("(")
46+
stringify(withSel.X, builder)
47+
builder.WriteString(")")
48+
} else {
49+
builder.WriteString("()")
50+
}
51+
}
52+
builder.WriteString(" ")
53+
}
3354
builder.WriteString("SELECT ")
3455
stringify(actual.List, builder)
3556
builder.WriteString(" FROM ")

0 commit comments

Comments
 (0)