[Postgres] Add support for DISTINCT ON clause.

This commit is contained in:
go-jet 2022-01-06 18:11:26 +01:00
parent 5cbf4aac86
commit 6fe9c26d30
3 changed files with 69 additions and 4 deletions

View file

@ -18,8 +18,9 @@ type ClauseWithProjections interface {
// ClauseSelect struct
type ClauseSelect struct {
Distinct bool
ProjectionList []Projection
Distinct bool
DistinctOnColumns []ColumnExpression
ProjectionList []Projection
}
// Projections returns list of projections for select clause
@ -36,6 +37,12 @@ func (s *ClauseSelect) Serialize(statementType StatementType, out *SQLBuilder, o
out.WriteString("DISTINCT")
}
if len(s.DistinctOnColumns) > 0 {
out.WriteString("ON (")
SerializeColumnExpressions(s.DistinctOnColumns, statementType, out)
out.WriteByte(')')
}
if len(s.ProjectionList) == 0 {
panic("jet: SELECT clause has to have at least one projection")
}