Skip to content

[BUG] Multiple calls to Distinct() result in invalid SQL #281

@pwang96

Description

@pwang96

Calling query.Distinct().Distinct() results in the DISTINCT option being applied twice, which is invalid SQL.

See the playground snippet here: https://play.golang.org/p/9qwFGj1jRWx

builder := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)

q1 := builder.Select("foo").From("bar").Distinct()
sql, _, _ := q1.ToSql()
fmt.Println(sql)
// SELECT DISTINCT foo FROM bar

q2 := builder.Select("foo").From("bar").Distinct().Distinct()
sql, _, _ = q2.ToSql()
fmt.Println(sql)
// SELECT DISTINCT DISTINCT foo FROM bar

Duplicate options should be removed before SQL construction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions