@@ -554,9 +554,9 @@ select_ = select . List
554554-- be subject to the elimination of duplicate rows using `selectDistinct`.
555555selectDistinct
556556 :: (SListI columns, columns ~ (col ': cols))
557− => Selection outer commons grp schemas params from columns
557+ => Selection outer commons 'Ungrouped schemas params from columns
558558 -- ^ selection
559− -> TableExpression outer commons grp schemas params from
559+ -> TableExpression outer commons 'Ungrouped schemas params from
560560 -- ^ intermediate virtual table
561561 -> Query outer commons schemas params columns
562562selectDistinct selection tabexpr = UnsafeQuery $
@@ -568,9 +568,9 @@ selectDistinct selection tabexpr = UnsafeQuery $
568568-- of a general `Selection`.
569569selectDistinct_
570570 :: (SListI columns, columns ~ (col ': cols))
571− => NP (Aliased (Expression outer commons grp schemas params from)) columns
571+ => NP (Aliased (Expression outer commons 'Ungrouped schemas params from)) columns
572572 -- ^ select list
573− -> TableExpression outer commons grp schemas params from
573+ -> TableExpression outer commons 'Ungrouped schemas params from
574574 -- ^ intermediate virtual table
575575 -> Query outer commons schemas params columns
576576selectDistinct_ = selectDistinct . List
@@ -580,21 +580,14 @@ selectDistinct_ = selectDistinct . List
580580the given expressions evaluate to equal. The DISTINCT ON expressions are
581581interpreted using the same rules as for ORDER BY. ORDER BY is used to
582582ensure that the desired row appears first.
583−
584−The DISTINCT ON expression(s) must match the leftmost ORDER BY expression(s).
585−The ORDER BY clause will normally contain additional expression(s) that
586−determine the desired precedence of rows within each DISTINCT ON group.
587−
588−In order to guarantee they match and reduce redundancy, this function
589−will prepend the The DISTINCT ON expressions to the ORDER BY clause.
590583-}
591584selectDistinctOn
592585 :: (SListI columns, columns ~ (col ': cols))
593− => [SortExpression outer commons grp schemas params from]
594− -- ^ DISTINCT ON expression(s) and prepended to ORDER BY clause
595− -> Selection outer commons grp schemas params from columns
586+ => [SortExpression outer commons 'Ungrouped schemas params from]
587+ -- ^ distinct on and return the first row in ordering
588+ -> Selection outer commons 'Ungrouped schemas params from columns
596589 -- ^ selection
597− -> TableExpression outer commons grp schemas params from
590+ -> TableExpression outer commons 'Ungrouped schemas params from
598591 -- ^ intermediate virtual table
599592 -> Query outer commons schemas params columns
600593selectDistinctOn distincts selection tab = UnsafeQuery $
@@ -615,11 +608,11 @@ selectDistinctOn distincts selection tab = UnsafeQuery $
615608-- of a general `Selection`.
616609selectDistinctOn_
617610 :: (SListI columns, columns ~ (col ': cols))
618− => [SortExpression outer commons grp schemas params from]
611+ => [SortExpression outer commons 'Ungrouped schemas params from]
619612 -- ^ distinct on and return the first row in ordering
620− -> NP (Aliased (Expression outer commons grp schemas params from)) columns
613+ -> NP (Aliased (Expression outer commons 'Ungrouped schemas params from)) columns
621614 -- ^ selection
622− -> TableExpression outer commons grp schemas params from
615+ -> TableExpression outer commons 'Ungrouped schemas params from
623616 -- ^ intermediate virtual table
624617 -> Query outer commons schemas params columns
625618selectDistinctOn_ distincts = selectDistinctOn distincts . List
@@ -757,7 +750,7 @@ instance RenderSQL (TableExpression outer commons grp schemas params from) where
757750from
758751 :: FromClause outer commons schemas params from -- ^ table reference
759752 -> TableExpression outer commons 'Ungrouped schemas params from
760−from tab = TableExpression tab [] noGroups NoHaving [] [] []
753+from tab = TableExpression tab [] NoGroups NoHaving [] [] []
761754
762755-- | A `where_` is an endomorphism of `TableExpression`s which adds a
763756-- search condition to the `whereClause`.
@@ -778,7 +771,7 @@ groupBy
778771groupBy bys rels = TableExpression
779772 { fromClause = fromClause rels
780773 , whereClause = whereClause rels
781− , groupByClause = group bys
774+ , groupByClause = Group bys
782775 , havingClause = Having []
783776 , orderByClause = []
784777 , limitClause = limitClause rels
@@ -992,20 +985,19 @@ instance (Has rel rels cols, Has col cols ty, bys ~ '[ '(rel, col)])
992985-- done on @NoGroups@ while all output `Expression`s must be aggregated
993986-- in @Group Nil@. In general, all output `Expression`s in the
994987-- complement of @bys@ must be aggregated in @Group bys@.
995−newtype GroupByClause grp from = UnsafeGroupByClause
996− { renderGroupByClause :: ByteString }
997− deriving (GHC.Generic,Show,Eq,Ord,NFData)
988+data GroupByClause grp from where
989+ NoGroups :: GroupByClause 'Ungrouped from
990+ Group
991+ :: SListI bys
992+ => NP (By from) bys
993+ -> GroupByClause ('Grouped bys) from
994+
995+-- | Renders a `GroupByClause`.
998996instance RenderSQL (GroupByClause grp from) where
999− renderSQL = renderGroupByClause
1000−noGroups :: GroupByClause 'Ungrouped from
1001−noGroups = UnsafeGroupByClause ""
1002−group
1003− :: SListI bys
1004− => NP (By from) bys
1005− -> GroupByClause ('Grouped bys) from
1006−group bys = UnsafeGroupByClause $ case bys of
1007− Nil -> ""
1008− bys' -> " GROUP BY" <+> renderCommaSeparated renderSQL bys'
997+ renderSQL = \case
998+ NoGroups -> ""
999+ Group Nil -> ""
1000+ Group bys -> " GROUP BY" <+> renderCommaSeparated renderSQL bys
10091001
10101002-- | A `HavingClause` is used to eliminate groups that are not of interest.
10111003-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`