Skip to content

Commit

Permalink
support COUNT_DISTINCT
Browse files Browse the repository at this point in the history
  • Loading branch information
Toru-Takagi committed Feb 12, 2024
1 parent 806dc78 commit 2afa561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions formatter/format_test.go
Expand Up @@ -241,6 +241,15 @@ SELECT
count(*)
FROM users u
GROUP BY u.name, u.age
`,
},
{
name: "SELECT_COUNT_DISTINCT",
sql: `select count(distinct user_name) from users`,
want: `
SELECT
count(DISTINCT user_name)
FROM users
`,
},
{
Expand Down
4 changes: 4 additions & 0 deletions formatter/node_formatter/format_funccall.go
Expand Up @@ -81,6 +81,10 @@ func FormatFuncCallArgs(ctx context.Context, funcCall *pg_query.Node_FuncCall, i
bu.WriteString("$")
bu.WriteString(fmt.Sprint(n.ParamRef.Number))
case *pg_query.Node_ColumnRef:
if funcCall.FuncCall.AggDistinct {
bu.WriteString("DISTINCT ")
}

field, err := FormatColumnRefFields(ctx, n)
if err != nil {
return "", err
Expand Down

0 comments on commit 2afa561

Please sign in to comment.