@@ -176,9 +176,9 @@ values from primitive expression using arithmetic, logical,
176176and other operations.
177177-}
178178newtype Expression
179− (params :: [ColumnType])
180179 (tables :: TablesType)
181180 (grouping :: Grouping)
181+ (params :: [ColumnType])
182182 (ty :: ColumnType)
183183 = UnsafeExpression { renderExpression :: ByteString }
184184 deriving (GHC.Generic,Show,Eq,Ord,Data,NFData)
@@ -193,7 +193,7 @@ refer to the out-of-line data values.
193193-}
194194class (PGTyped (BaseType ty), KnownNat n)
195195 => HasParameter (n :: Nat) params ty | n params -> ty where
196− param :: Expression params tables grouping ty
196+ param :: Expression tables grouping params ty
197197 param = UnsafeExpression $ parenthesized $
198198 "$" <> renderNat (Proxy @n) <+> "::"
199199 <+> renderTypeExpression (pgtype @(BaseType ty))
@@ -213,7 +213,7 @@ class KnownSymbol column => HasColumn column columns ty
213213 getColumn
214214 :: HasUnique table tables columns
215215 => Alias column
216− -> Expression params tables 'Ungrouped ty
216+ -> Expression tables 'Ungrouped params ty
217217 getColumn column = UnsafeExpression $ renderAlias column
218218instance {-# OVERLAPPING #-} KnownSymbol column
219219 => HasColumn column ((column ::: optionality ty) ': tys) ('Required ty)
@@ -221,11 +221,11 @@ instance {-# OVERLAPPABLE #-} (KnownSymbol column, HasColumn column table ty)
221221 => HasColumn column (ty' ': table) ty
222222
223223instance (HasColumn column columns ty, HasUnique table tables columns)
224− => IsLabel column (Expression params tables 'Ungrouped ty) where
224+ => IsLabel column (Expression tables 'Ungrouped params ty) where
225225 fromLabel = getColumn (Alias @column)
226226
227227instance (HasTable table tables columns, HasColumn column columns ty)
228− => IsTableColumn table column (Expression params tables 'Ungrouped ty) where
228+ => IsTableColumn table column (Expression tables 'Ungrouped params ty) where
229229 table ! column = UnsafeExpression $
230230 renderAlias table <> "." <> renderAlias column
231231
@@ -249,13 +249,13 @@ class (KnownSymbol table, KnownSymbol column)
249249 getGroup1
250250 :: (HasUnique table tables columns, HasColumn column columns ty)
251251 => Alias column
252− -> Expression params tables ('Grouped bys) ty
252+ -> Expression tables ('Grouped bys) params ty
253253 getGroup1 column = UnsafeExpression $ renderAlias column
254254 getGroup2
255255 :: (HasTable table tables columns, HasColumn column columns ty)
256256 => Alias table
257257 -> Alias column
258− -> Expression params tables ('Grouped bys) ty
258+ -> Expression tables ('Grouped bys) params ty
259259 getGroup2 table column = UnsafeExpression $
260260 renderAlias table <> "." <> renderAlias column
261261instance {-# OVERLAPPING #-} (KnownSymbol table, KnownSymbol column)
@@ -271,7 +271,7 @@ instance
271271 , HasColumn column columns ty
272272 , GroupedBy table column bys
273273 ) => IsLabel column
274− (Expression params tables ('Grouped bys) ty) where
274+ (Expression tables ('Grouped bys) params ty) where
275275 fromLabel = getGroup1 (Alias @column)
276276
277277instance
@@ -279,25 +279,25 @@ instance
279279 , HasColumn column columns ty
280280 , GroupedBy table column bys
281281 ) => IsTableColumn table column
282− (Expression params tables ('Grouped bys) ty) where (!) = getGroup2
282+ (Expression tables ('Grouped bys) params ty) where (!) = getGroup2
283283
284284-- | >>> renderExpression def
285285-- "DEFAULT"
286−def :: Expression params '[] 'Ungrouped ('Optional (nullity ty))
286+def :: Expression '[] 'Ungrouped params ('Optional (nullity ty))
287287def = UnsafeExpression "DEFAULT"
288288
289289-- | >>> renderExpression $ unDef false
290290-- "FALSE"
291291unDef
292− :: Expression params '[] 'Ungrouped ('Required (nullity ty))
293− -> Expression params '[] 'Ungrouped ('Optional (nullity ty))
292+ :: Expression '[] 'Ungrouped params ('Required (nullity ty))
293+ -> Expression '[] 'Ungrouped params ('Optional (nullity ty))
294294unDef = UnsafeExpression . renderExpression
295295
296296-- | analagous to `Nothing`
297297--
298298-- >>> renderExpression $ null_
299299-- "NULL"
300−null_ :: Expression params tables grouping (optionality ('Null ty))
300+null_ :: Expression tables grouping params (optionality ('Null ty))
301301null_ = UnsafeExpression "NULL"
302302
303303-- | analagous to `Just`
@@ -305,8 +305,8 @@ null_ = UnsafeExpression "NULL"
305305-- >>> renderExpression $ unNull true
306306-- "TRUE"
307307unNull
308− :: Expression params tables grouping (optionality ('NotNull ty))
309− -> Expression params tables grouping (optionality ('Null ty))
308+ :: Expression tables grouping params (optionality ('NotNull ty))
309+ -> Expression tables grouping params (optionality ('Null ty))
310310unNull = UnsafeExpression . renderExpression
311311
312312-- | return the leftmost value which is not NULL
@@ -314,9 +314,9 @@ unNull = UnsafeExpression . renderExpression
314314-- >>> renderExpression $ coalesce [null_, unNull true] false
315315-- "COALESCE(NULL, TRUE, FALSE)"
316316coalesce
317− :: [Expression params tables grouping ('Required ('Null ty))]
318− -> Expression params tables grouping ('Required ('NotNull ty))
319− -> Expression params tables grouping ('Required ('NotNull ty))
317+ :: [Expression tables grouping params ('Required ('Null ty))]
318+ -> Expression tables grouping params ('Required ('NotNull ty))
319+ -> Expression tables grouping params ('Required ('NotNull ty))
320320coalesce nullxs notNullx = UnsafeExpression $
321321 "COALESCE" <> parenthesized (commaSeparated
322322 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -326,23 +326,23 @@ coalesce nullxs notNullx = UnsafeExpression $
326326-- >>> renderExpression $ fromNull true null_
327327-- "COALESCE(NULL, TRUE)"
328328fromNull
329− :: Expression params tables grouping ('Required ('NotNull ty))
330− -> Expression params tables grouping ('Required ('Null ty))
331− -> Expression params tables grouping ('Required ('NotNull ty))
329+ :: Expression tables grouping params ('Required ('NotNull ty))
330+ -> Expression tables grouping params ('Required ('Null ty))
331+ -> Expression tables grouping params ('Required ('NotNull ty))
332332fromNull notNullx nullx = coalesce [nullx] notNullx
333333
334334-- | >>> renderExpression $ null_ & isNull
335335-- "NULL IS NULL"
336336isNull
337− :: Expression params tables grouping ('Required ('Null ty))
338− -> Condition params tables grouping
337+ :: Expression tables grouping params ('Required ('Null ty))
338+ -> Condition tables grouping params
339339isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
340340
341341-- | >>> renderExpression $ null_ & isn'tNull
342342-- "NULL IS NOT NULL"
343343isn'tNull
344− :: Expression params tables grouping ('Required ('Null ty))
345− -> Condition params tables grouping
344+ :: Expression tables grouping params ('Required ('Null ty))
345+ -> Condition tables grouping params
346346isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
347347
348348-- | analagous to `maybe` using @IS NULL@
@@ -350,68 +350,68 @@ isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
350350-- >>> renderExpression $ matchNull true not_ null_
351351-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
352352matchNull
353− :: Expression params tables grouping ('Required nullty)
354− -> ( Expression params tables grouping ('Required ('NotNull ty))
355− -> Expression params tables grouping ('Required nullty) )
356− -> Expression params tables grouping ('Required ('Null ty))
357− -> Expression params tables grouping ('Required nullty)
353+ :: Expression tables grouping params ('Required nullty)
354+ -> ( Expression tables grouping params ('Required ('NotNull ty))
355+ -> Expression tables grouping params ('Required nullty) )
356+ -> Expression tables grouping params ('Required ('Null ty))
357+ -> Expression tables grouping params ('Required nullty)
358358matchNull y f x = ifThenElse (isNull x) y
359359 (f (UnsafeExpression (renderExpression x)))
360360
361361-- | right inverse to `fromNull`
362362--
363363-- >>> :set -XTypeApplications -XDataKinds
364−-- >>> renderExpression @'[_] $ fromNull false (nullIf false (param @1))
365−-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
364+-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
365+-- "COALESCE(NULL IF (FALSE, FALSE), FALSE)"
366366nullIf
367− :: Expression params tables grouping ('Required ('NotNull ty))
368− -> Expression params tables grouping ('Required ('NotNull ty))
369− -> Expression params tables grouping ('Required ('Null ty))
367+ :: Expression tables grouping params ('Required ('NotNull ty))
368+ -> Expression tables grouping params ('Required ('NotNull ty))
369+ -> Expression tables grouping params ('Required ('Null ty))
370370nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
371371 (renderExpression x <> ", " <> renderExpression y)
372372
373−-- | >>> renderExpression @'[_] $ greatest currentTimestamp [param @1]
373+-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
374374-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
375375greatest
376− :: Expression params tables grouping ('Required nullty)
377− -> [Expression params tables grouping ('Required nullty)]
378− -> Expression params table grouping ('Required nullty)
376+ :: Expression tables grouping params ('Required nullty)
377+ -> [Expression tables grouping params ('Required nullty)]
378+ -> Expression tables grouping params ('Required nullty)
379379greatest x xs = UnsafeExpression $ "GREATEST("
380380 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
381381
382382-- | >>> renderExpression $ least currentTimestamp [null_]
383383-- "LEAST(CURRENT_TIMESTAMP, NULL)"
384384least
385− :: Expression params tables grouping ('Required nullty)
386− -> [Expression params tables grouping ('Required nullty)]
387− -> Expression params table grouping ('Required nullty)
385+ :: Expression tables grouping params ('Required nullty)
386+ -> [Expression tables grouping params ('Required nullty)]
387+ -> Expression tables grouping params ('Required nullty)
388388least x xs = UnsafeExpression $ "LEAST("
389389 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
390390
391391unsafeBinaryOp
392392 :: ByteString
393− -> Expression params tables grouping ('Required ty0)
394− -> Expression params tables grouping ('Required ty1)
395− -> Expression params tables grouping ('Required ty2)
393+ -> Expression tables grouping params ('Required ty0)
394+ -> Expression tables grouping params ('Required ty1)
395+ -> Expression tables grouping params ('Required ty2)
396396unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
397397 renderExpression x <+> op <+> renderExpression y
398398
399399unsafeUnaryOp
400400 :: ByteString
401− -> Expression params tables grouping ('Required ty0)
402− -> Expression params tables grouping ('Required ty1)
401+ -> Expression tables grouping params ('Required ty0)
402+ -> Expression tables grouping params ('Required ty1)
403403unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
404404 op <+> renderExpression x
405405
406406unsafeFunction
407407 :: ByteString
408− -> Expression params tables grouping ('Required xty)
409− -> Expression params tables grouping ('Required yty)
408+ -> Expression tables grouping params ('Required xty)
409+ -> Expression tables grouping params ('Required yty)
410410unsafeFunction fun x = UnsafeExpression $
411411 fun <> parenthesized (renderExpression x)
412412
413413instance PGNum ty
414− => Num (Expression params tables grouping ('Required (nullity ty))) where
414+ => Num (Expression tables grouping params ('Required (nullity ty))) where
415415 (+) = unsafeBinaryOp "+"
416416 (-) = unsafeBinaryOp "-"
417417 (*) = unsafeBinaryOp "*"
@@ -423,12 +423,12 @@ instance PGNum ty
423423 . show
424424
425425instance (PGNum ty, PGFloating ty) => Fractional
426− (Expression params tables grouping ('Required (nullity ty))) where
426+ (Expression tables grouping params ('Required (nullity ty))) where
427427 (/) = unsafeBinaryOp "/"
428428 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
429429
430430instance (PGNum ty, PGFloating ty) => Floating
431− (Expression params tables grouping ('Required (nullity ty))) where
431+ (Expression tables grouping params ('Required (nullity ty))) where
432432 pi = UnsafeExpression "pi()"
433433 exp = unsafeFunction "exp"
434434 log = unsafeFunction "ln"
@@ -451,53 +451,53 @@ instance (PGNum ty, PGFloating ty) => Floating
451451
452452atan2_
453453 :: PGFloating float
454− => Expression params tables grouping ('Required (nullity float))
455− -> Expression params tables grouping ('Required (nullity float))
456− -> Expression params tables grouping ('Required (nullity float))
454+ => Expression tables grouping params ('Required (nullity float))
455+ -> Expression tables grouping params ('Required (nullity float))
456+ -> Expression tables grouping params ('Required (nullity float))
457457atan2_ y x = UnsafeExpression $
458458 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
459459
460460cast
461461 :: TypeExpression ('Required ('Null ty1))
462− -> Expression params tables grouping ('Required (nullity ty0))
463− -> Expression params tables grouping ('Required (nullity ty1))
462+ -> Expression tables grouping params ('Required (nullity ty0))
463+ -> Expression tables grouping params ('Required (nullity ty1))
464464cast ty x = UnsafeExpression $ parenthesized $
465465 renderExpression x <+> "::" <+> renderTypeExpression ty
466466
467467div_
468468 :: PGIntegral int
469− => Expression params tables grouping ('Required (nullity int))
470− -> Expression params tables grouping ('Required (nullity int))
471− -> Expression params tables grouping ('Required (nullity int))
469+ => Expression tables grouping params ('Required (nullity int))
470+ -> Expression tables grouping params ('Required (nullity int))
471+ -> Expression tables grouping params ('Required (nullity int))
472472div_ = unsafeBinaryOp "/"
473473
474474mod_
475475 :: PGIntegral int
476− => Expression params tables grouping ('Required (nullity int))
477− -> Expression params tables grouping ('Required (nullity int))
478− -> Expression params tables grouping ('Required (nullity int))
476+ => Expression tables grouping params ('Required (nullity int))
477+ -> Expression tables grouping params ('Required (nullity int))
478+ -> Expression tables grouping params ('Required (nullity int))
479479mod_ = unsafeBinaryOp "%"
480480
481481trunc
482482 :: PGFloating frac
483− => Expression params tables grouping ('Required (nullity frac))
484− -> Expression params tables grouping ('Required (nullity frac))
483+ => Expression tables grouping params ('Required (nullity frac))
484+ -> Expression tables grouping params ('Required (nullity frac))
485485trunc = unsafeFunction "trunc"
486486
487487round_
488488 :: PGFloating frac
489− => Expression params tables grouping ('Required (nullity frac))
490− -> Expression params tables grouping ('Required (nullity frac))
489+ => Expression tables grouping params ('Required (nullity frac))
490+ -> Expression tables grouping params ('Required (nullity frac))
491491round_ = unsafeFunction "round"
492492
493493ceiling_
494494 :: PGFloating frac
495− => Expression params tables grouping ('Required (nullity frac))
496− -> Expression params tables grouping ('Required (nullity frac))
495+ => Expression tables grouping params ('Required (nullity frac))
496+ -> Expression tables grouping params ('Required (nullity frac))
497497ceiling_ = unsafeFunction "ceiling"
498498
499499instance IsString
500− (Expression params tables grouping ('Required (nullity 'PGtext))) where
500+ (Expression tables grouping params ('Required (nullity 'PGtext))) where
501501 fromString str = UnsafeExpression $
502502 "E\'" <> fromString (escape =<< str) <> "\'"
503503 where
@@ -512,38 +512,38 @@ instance IsString
512512 '\\' -> "\\\\"
513513 c -> [c]
514514
515−type Condition params tables grouping =
516− Expression params tables grouping ('Required ('NotNull 'PGbool))
515+type Condition tables grouping params =
516+ Expression tables grouping params ('Required ('NotNull 'PGbool))
517517
518−true :: Condition params tables grouping
518+true :: Condition tables grouping params
519519true = UnsafeExpression "TRUE"
520520
521−false :: Condition params tables grouping
521+false :: Condition tables grouping params
522522false = UnsafeExpression "FALSE"
523523
524524not_
525− :: Condition params tables grouping
526− -> Condition params tables grouping
525+ :: Condition tables grouping params
526+ -> Condition tables grouping params
527527not_ = unsafeUnaryOp "NOT"
528528
529529(&&*)
530− :: Condition params tables grouping
531− -> Condition params tables grouping
532− -> Condition params tables grouping
530+ :: Condition tables grouping params
531+ -> Condition tables grouping params
532+ -> Condition tables grouping params
533533(&&*) = unsafeBinaryOp "AND"
534534
535535(||*)
536− :: Condition params tables grouping
537− -> Condition params tables grouping
538− -> Condition params tables grouping
536+ :: Condition tables grouping params
537+ -> Condition tables grouping params
538+ -> Condition tables grouping params
539539(||*) = unsafeBinaryOp "OR"
540540
541541caseWhenThenElse
542− :: [ ( Condition params tables grouping
543− , Expression params tables grouping ('Required ty)
542+ :: [ ( Condition tables grouping params
543+ , Expression tables grouping params ('Required ty)
544544 ) ]
545− -> Expression params tables grouping ('Required ty)
546− -> Expression params tables grouping ('Required ty)
545+ -> Expression tables grouping params ('Required ty)
546+ -> Expression tables grouping params ('Required ty)
547547caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
548548 [ "CASE"
549549 , mconcat
@@ -558,72 +558,72 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
558558 ]
559559
560560ifThenElse
561− :: Condition params tables grouping
562− -> Expression params tables grouping ('Required ty)
563− -> Expression params tables grouping ('Required ty)
564− -> Expression params tables grouping ('Required ty)
561+ :: Condition tables grouping params
562+ -> Expression tables grouping params ('Required ty)
563+ -> Expression tables grouping params ('Required ty)
564+ -> Expression tables grouping params ('Required ty)
565565ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
566566
567567(==*)
568− :: Expression params tables grouping ('Required (nullity ty))
569− -> Expression params tables grouping ('Required (nullity ty))
570− -> Expression params tables grouping ('Required (nullity 'PGbool))
568+ :: Expression tables grouping params ('Required (nullity ty))
569+ -> Expression tables grouping params ('Required (nullity ty))
570+ -> Expression tables grouping params ('Required (nullity 'PGbool))
571571(==*) = unsafeBinaryOp "="
572572infix 4 ==*
573573
574574(/=*)
575− :: Expression params tables grouping ('Required (nullity ty))
576− -> Expression params tables grouping ('Required (nullity ty))
577− -> Expression params tables grouping ('Required (nullity 'PGbool))
575+ :: Expression tables grouping params ('Required (nullity ty))
576+ -> Expression tables grouping params ('Required (nullity ty))
577+ -> Expression tables grouping params ('Required (nullity 'PGbool))
578578(/=*) = unsafeBinaryOp "<>"
579579infix 4 /=*
580580
581581(>=*)
582− :: Expression params tables grouping ('Required (nullity ty))
583− -> Expression params tables grouping ('Required (nullity ty))
584− -> Expression params tables grouping ('Required (nullity 'PGbool))
582+ :: Expression tables grouping params ('Required (nullity ty))
583+ -> Expression tables grouping params ('Required (nullity ty))
584+ -> Expression tables grouping params ('Required (nullity 'PGbool))
585585(>=*) = unsafeBinaryOp ">="
586586infix 4 >=*
587587
588588(*<)
589− :: Expression params tables grouping ('Required (nullity ty))
590− -> Expression params tables grouping ('Required (nullity ty))
591− -> Expression params tables grouping ('Required (nullity 'PGbool))
589+ :: Expression tables grouping params ('Required (nullity ty))
590+ -> Expression tables grouping params ('Required (nullity ty))
591+ -> Expression tables grouping params ('Required (nullity 'PGbool))
592592(*<) = unsafeBinaryOp "<"
593593infix 4 *<
594594
595595(*<=)
596− :: Expression params tables grouping ('Required (nullity ty))
597− -> Expression params tables grouping ('Required (nullity ty))
598− -> Expression params tables grouping ('Required (nullity 'PGbool))
596+ :: Expression tables grouping params ('Required (nullity ty))
597+ -> Expression tables grouping params ('Required (nullity ty))
598+ -> Expression tables grouping params ('Required (nullity 'PGbool))
599599(*<=) = unsafeBinaryOp "<="
600600infix 4 *<=
601601
602602(>*)
603− :: Expression params tables grouping ('Required (nullity ty))
604− -> Expression params tables grouping ('Required (nullity ty))
605− -> Expression params tables grouping ('Required (nullity 'PGbool))
603+ :: Expression tables grouping params ('Required (nullity ty))
604+ -> Expression tables grouping params ('Required (nullity ty))
605+ -> Expression tables grouping params ('Required (nullity 'PGbool))
606606(>*) = unsafeBinaryOp ">"
607607infix 4 >*
608608
609609currentDate
610− :: Expression params tables grouping ('Required (nullity 'PGdate))
610+ :: Expression tables grouping params ('Required (nullity 'PGdate))
611611currentDate = UnsafeExpression "CURRENT_DATE"
612612
613613currentTime
614− :: Expression params tables grouping ('Required (nullity 'PGtimetz))
614+ :: Expression tables grouping params ('Required (nullity 'PGtimetz))
615615currentTime = UnsafeExpression "CURRENT_TIME"
616616
617617currentTimestamp
618− :: Expression params tables grouping ('Required (nullity 'PGtimestamptz))
618+ :: Expression tables grouping params ('Required (nullity 'PGtimestamptz))
619619currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
620620
621621localTime
622− :: Expression params tables grouping ('Required (nullity 'PGtime))
622+ :: Expression tables grouping params ('Required (nullity 'PGtime))
623623localTime = UnsafeExpression "LOCALTIME"
624624
625625localTimestamp
626− :: Expression params tables grouping ('Required (nullity 'PGtimestamp))
626+ :: Expression tables grouping params ('Required (nullity 'PGtimestamp))
627627localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
628628
629629{-----------------------------------------
@@ -632,8 +632,8 @@ aggregation
632632
633633unsafeAggregate, unsafeAggregateDistinct
634634 :: ByteString
635− -> Expression params tables 'Ungrouped ('Required xty)
636− -> Expression params tables ('Grouped bys) ('Required yty)
635+ -> Expression tables 'Ungrouped params ('Required xty)
636+ -> Expression tables ('Grouped bys) params ('Required yty)
637637unsafeAggregate fun x = UnsafeExpression $ mconcat
638638 [fun, "(", renderExpression x, ")"]
639639unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
@@ -641,15 +641,15 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
641641
642642sum_, sumDistinct
643643 :: PGNum ty
644− => Expression params tables 'Ungrouped ('Required (nullity ty))
645− -> Expression params tables ('Grouped bys) ('Required (nullity ty))
644+ => Expression tables 'Ungrouped params ('Required (nullity ty))
645+ -> Expression tables ('Grouped bys) params ('Required (nullity ty))
646646sum_ = unsafeAggregate "sum"
647647sumDistinct = unsafeAggregateDistinct "sum"
648648
649649class PGAvg ty avg | ty -> avg where
650650 avg, avgDistinct
651− :: Expression params tables 'Ungrouped ('Required (nullity ty))
652− -> Expression params tables ('Grouped bys) ('Required (nullity avg))
651+ :: Expression tables 'Ungrouped params ('Required (nullity ty))
652+ -> Expression tables ('Grouped bys) params ('Required (nullity avg))
653653 avg = unsafeAggregate "avg"
654654 avgDistinct = unsafeAggregateDistinct "avg"
655655instance PGAvg 'PGint2 'PGnumeric
@@ -662,61 +662,61 @@ instance PGAvg 'PGinterval 'PGinterval
662662
663663bitAnd, bitOr
664664 :: PGIntegral int
665− => Expression params tables 'Ungrouped ('Required (nullity int))
666− -> Expression params tables ('Grouped bys) ('Required (nullity int))
665+ => Expression tables 'Ungrouped params ('Required (nullity int))
666+ -> Expression tables ('Grouped bys) params ('Required (nullity int))
667667bitAnd = unsafeAggregate "bit_and"
668668bitOr = unsafeAggregate "bit_or"
669669
670670boolAnd, boolOr
671− :: Expression params tables 'Ungrouped ('Required (nullity 'PGbool))
672− -> Expression params tables ('Grouped bys) ('Required (nullity 'PGbool))
671+ :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
672+ -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
673673boolAnd = unsafeAggregate "bool_and"
674674boolOr = unsafeAggregate "bool_or"
675675
676676countStar, countDistinctStar
677− :: Expression params table ('Grouped bys) ('Required ('NotNull 'PGint8))
677+ :: Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
678678countStar = UnsafeExpression $ "count(*)"
679679countDistinctStar = UnsafeExpression $ "count(DISTINCT *)"
680680
681681count
682− :: Expression params tables 'Ungrouped ('Required ty)
683− -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGint8))
682+ :: Expression tables 'Ungrouped params ('Required ty)
683+ -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
684684count = unsafeAggregate "count"
685685
686686every
687− :: Expression params tables 'Ungrouped ('Required (nullity 'PGbool))
688− -> Expression params tables ('Grouped bys) ('Required (nullity 'PGbool))
687+ :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
688+ -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
689689every = unsafeAggregate "every"
690690
691691jsonAgg
692− :: Expression params tables 'Ungrouped ('Required ty)
693− -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjson))
692+ :: Expression tables 'Ungrouped params ('Required ty)
693+ -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGjson))
694694jsonAgg = unsafeAggregate "json_agg"
695695
696696jsonbAgg
697− :: Expression params tables 'Ungrouped ('Required ty)
698− -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjsonb))
697+ :: Expression tables 'Ungrouped params ('Required ty)
698+ -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGjsonb))
699699jsonbAgg = unsafeAggregate "jsonb_agg"
700700
701701jsonObjectAgg
702− :: Expression params tables 'Ungrouped ('Required ('NotNull keyty))
703− -> Expression params tables 'Ungrouped ('Required valty)
704− -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjson))
702+ :: Expression tables 'Ungrouped params ('Required ('NotNull keyty))
703+ -> Expression tables 'Ungrouped params ('Required valty)
704+ -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGjson))
705705jsonObjectAgg k v = UnsafeExpression $
706706 "json_object_agg(" <> renderExpression k
707707 <> ", " <> renderExpression v <> ")"
708708
709709jsonbObjectAgg
710− :: Expression params tables 'Ungrouped ('Required ('NotNull keyty))
711− -> Expression params tables 'Ungrouped ('Required valty)
712− -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjsonb))
710+ :: Expression tables 'Ungrouped params ('Required ('NotNull keyty))
711+ -> Expression tables 'Ungrouped params ('Required valty)
712+ -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGjsonb))
713713jsonbObjectAgg k v = UnsafeExpression $
714714 "jsonb_object_agg("
715715 <> renderExpression k <> ", " <> renderExpression v <> ")"
716716
717717max_, min_
718− :: Expression params tables 'Ungrouped ('Required (nullity ty))
719− -> Expression params tables ('Grouped bys) ('Required (nullity ty))
718+ :: Expression tables 'Ungrouped params ('Required (nullity ty))
719+ -> Expression tables ('Grouped bys) params ('Required (nullity ty))
720720max_ = unsafeAggregate "max"
721721min_ = unsafeAggregate "min"
722722
@@ -839,7 +839,7 @@ notNull
839839 -> TypeExpression (optionality ('NotNull ty))
840840notNull ty = UnsafeTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
841841default_
842− :: Expression '[] '[] 'Ungrouped ('Required ty)
842+ :: Expression '[] 'Ungrouped '[] ('Required ty)
843843 -> TypeExpression ('Required ty)
844844 -> TypeExpression ('Optional ty)
845845default_ x ty = UnsafeTypeExpression $