@@ -196,13 +196,13 @@ supplied externally to a SQL statement.
196196separately from the SQL command string, in which case `param`s are used to
197197refer to the out-of-line data values.
198198-}
199−class (PGTyped (BaseType ty), KnownNat n)
199+class (PGTyped (PGTypeOf ty), KnownNat n)
200200 => HasParameter (n :: Nat) params ty | n params -> ty where
201201 param :: Expression tables grouping params ty
202202 param = UnsafeExpression $ parenthesized $
203203 "$" <> renderNat (Proxy @n) <+> "::"
204− <+> renderTypeExpression (pgtype @(BaseType ty))
205−instance {-# OVERLAPPING #-} PGTyped (BaseType ty1)
204+ <+> renderTypeExpression (pgtype @(PGTypeOf ty))
205+instance {-# OVERLAPPING #-} PGTyped (PGTypeOf ty1)
206206 => HasParameter 1 (ty1:tys) ty1
207207instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
208208 => HasParameter n (ty' : params) ty
@@ -221,7 +221,7 @@ class KnownSymbol column => HasColumn column columns ty
221221 -> Expression tables 'Ungrouped params ty
222222 getColumn column = UnsafeExpression $ renderAlias column
223223instance {-# OVERLAPPING #-} KnownSymbol column
224− => HasColumn column ((column ::: optionality ty) ': tys) ('Required ty)
224+ => HasColumn column ((column ::: optionality ty) ': tys) '( '[], ty)
225225instance {-# OVERLAPPABLE #-} (KnownSymbol column, HasColumn column table ty)
226226 => HasColumn column (ty' ': table) ty
227227
@@ -297,15 +297,18 @@ instance
297297
298298-- | >>> renderExpression def
299299-- "DEFAULT"
300−def :: Expression '[] 'Ungrouped params ('Optional (nullity ty))
300+def
301+ :: 'Default `In` constraints
302+ => Expression '[] 'Ungrouped params '(constraints, (nullity ty))
301303def = UnsafeExpression "DEFAULT"
302304
303305-- | >>> renderExpression $ unDef false
304306-- "FALSE"
305307unDef
306− :: Expression '[] 'Ungrouped params ('Required (nullity ty))
308+ :: 'Default `In` constraints
309+ => Expression '[] 'Ungrouped params '( '[], (nullity ty))
307310 -- ^ not @DEFAULT@
308− -> Expression '[] 'Ungrouped params ('Optional (nullity ty))
311+ -> Expression '[] 'Ungrouped params '(constraints, (nullity ty))
309312unDef = UnsafeExpression . renderExpression
310313
311314-- | analagous to `Nothing`
@@ -330,11 +333,11 @@ unNull = UnsafeExpression . renderExpression
330333-- >>> renderExpression $ coalesce [null_, unNull true] false
331334-- "COALESCE(NULL, TRUE, FALSE)"
332335coalesce
333− :: [Expression tables grouping params ('Required ('Null ty))]
336+ :: [Expression tables grouping params '( '[], ('Null ty))]
334337 -- ^ @NULL@s may be present
335− -> Expression tables grouping params ('Required ('NotNull ty))
338+ -> Expression tables grouping params '( '[], ('NotNull ty))
336339 -- ^ @NULL@ is absent
337− -> Expression tables grouping params ('Required ('NotNull ty))
340+ -> Expression tables grouping params '( '[], ('NotNull ty))
338341coalesce nullxs notNullx = UnsafeExpression $
339342 "COALESCE" <> parenthesized (commaSeparated
340343 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -344,16 +347,16 @@ coalesce nullxs notNullx = UnsafeExpression $
344347-- >>> renderExpression $ fromNull true null_
345348-- "COALESCE(NULL, TRUE)"
346349fromNull
347− :: Expression tables grouping params ('Required ('NotNull ty))
350+ :: Expression tables grouping params '( '[], ('NotNull ty))
348351 -- ^ what to convert @NULL@ to
349− -> Expression tables grouping params ('Required ('Null ty))
350− -> Expression tables grouping params ('Required ('NotNull ty))
352+ -> Expression tables grouping params '( '[], ('Null ty))
353+ -> Expression tables grouping params '( '[], ('NotNull ty))
351354fromNull notNullx nullx = coalesce [nullx] notNullx
352355
353356-- | >>> renderExpression $ null_ & isNull
354357-- "NULL IS NULL"
355358isNull
356− :: Expression tables grouping params ('Required ('Null ty))
359+ :: Expression tables grouping params '( '[], ('Null ty))
357360 -- ^ possibly @NULL@
358361 -> Condition tables grouping params
359362isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
@@ -361,7 +364,7 @@ isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
361364-- | >>> renderExpression $ null_ & isn'tNull
362365-- "NULL IS NOT NULL"
363366isn'tNull
364− :: Expression tables grouping params ('Required ('Null ty))
367+ :: Expression tables grouping params '( '[], ('Null ty))
365368 -- ^ possibly @NULL@
366369 -> Condition tables grouping params
367370isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
@@ -371,13 +374,13 @@ isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
371374-- >>> renderExpression $ matchNull true not_ null_
372375-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
373376matchNull
374− :: Expression tables grouping params ('Required nullty)
377+ :: Expression tables grouping params '( '[], nullty)
375378 -- ^ what to convert @NULL@ to
376− -> ( Expression tables grouping params ('Required ('NotNull ty))
377− -> Expression tables grouping params ('Required nullty) )
379+ -> ( Expression tables grouping params '( '[], ('NotNull ty))
380+ -> Expression tables grouping params '( '[], nullty) )
378381 -- ^ function to perform when @NULL@ is absent
379− -> Expression tables grouping params ('Required ('Null ty))
380− -> Expression tables grouping params ('Required nullty)
382+ -> Expression tables grouping params '( '[], ('Null ty))
383+ -> Expression tables grouping params '( '[], nullty)
381384matchNull y f x = ifThenElse (isNull x) y
382385 (f (UnsafeExpression (renderExpression x)))
383386
@@ -388,33 +391,33 @@ matchNull y f x = ifThenElse (isNull x) y
388391-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
389392-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
390393nullIf
391− :: Expression tables grouping params ('Required ('NotNull ty))
394+ :: Expression tables grouping params '( '[], ('NotNull ty))
392395 -- ^ @NULL@ is absent
393− -> Expression tables grouping params ('Required ('NotNull ty))
396+ -> Expression tables grouping params '( '[], ('NotNull ty))
394397 -- ^ @NULL@ is absent
395− -> Expression tables grouping params ('Required ('Null ty))
398+ -> Expression tables grouping params '( '[], ('Null ty))
396399nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
397400 (renderExpression x <> ", " <> renderExpression y)
398401
399402-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
400403-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
401404greatest
402− :: Expression tables grouping params ('Required nullty)
405+ :: Expression tables grouping params '( '[], nullty)
403406 -- ^ needs at least 1 argument
404− -> [Expression tables grouping params ('Required nullty)]
407+ -> [Expression tables grouping params '( '[], nullty)]
405408 -- ^ or more
406− -> Expression tables grouping params ('Required nullty)
409+ -> Expression tables grouping params '( '[], nullty)
407410greatest x xs = UnsafeExpression $ "GREATEST("
408411 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
409412
410413-- | >>> renderExpression $ least currentTimestamp [null_]
411414-- "LEAST(CURRENT_TIMESTAMP, NULL)"
412415least
413− :: Expression tables grouping params ('Required nullty)
416+ :: Expression tables grouping params '( '[], nullty)
414417 -- ^ needs at least 1 argument
415− -> [Expression tables grouping params ('Required nullty)]
418+ -> [Expression tables grouping params '( '[], nullty)]
416419 -- ^ or more
417− -> Expression tables grouping params ('Required nullty)
420+ -> Expression tables grouping params '( '[], nullty)
418421least x xs = UnsafeExpression $ "LEAST("
419422 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
420423
@@ -423,9 +426,9 @@ least x xs = UnsafeExpression $ "LEAST("
423426unsafeBinaryOp
424427 :: ByteString
425428 -- ^ operator
426− -> Expression tables grouping params ('Required ty0)
427− -> Expression tables grouping params ('Required ty1)
428− -> Expression tables grouping params ('Required ty2)
429+ -> Expression tables grouping params '( '[], ty0)
430+ -> Expression tables grouping params '( '[], ty1)
431+ -> Expression tables grouping params '( '[], ty2)
429432unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
430433 renderExpression x <+> op <+> renderExpression y
431434
@@ -434,8 +437,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
434437unsafeUnaryOp
435438 :: ByteString
436439 -- ^ operator
437− -> Expression tables grouping params ('Required ty0)
438− -> Expression tables grouping params ('Required ty1)
440+ -> Expression tables grouping params '( '[], ty0)
441+ -> Expression tables grouping params '( '[], ty1)
439442unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
440443 op <+> renderExpression x
441444
@@ -444,13 +447,13 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
444447unsafeFunction
445448 :: ByteString
446449 -- ^ function
447− -> Expression tables grouping params ('Required xty)
448− -> Expression tables grouping params ('Required yty)
450+ -> Expression tables grouping params '( '[], xty)
451+ -> Expression tables grouping params '( '[], yty)
449452unsafeFunction fun x = UnsafeExpression $
450453 fun <> parenthesized (renderExpression x)
451454
452455instance PGNum ty
453− => Num (Expression tables grouping params ('Required (nullity ty))) where
456+ => Num (Expression tables grouping params '( '[], (nullity ty))) where
454457 (+) = unsafeBinaryOp "+"
455458 (-) = unsafeBinaryOp "-"
456459 (*) = unsafeBinaryOp "*"
@@ -462,12 +465,12 @@ instance PGNum ty
462465 . show
463466
464467instance (PGNum ty, PGFloating ty) => Fractional
465− (Expression tables grouping params ('Required (nullity ty))) where
468+ (Expression tables grouping params '( '[], (nullity ty))) where
466469 (/) = unsafeBinaryOp "/"
467470 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
468471
469472instance (PGNum ty, PGFloating ty) => Floating
470− (Expression tables grouping params ('Required (nullity ty))) where
473+ (Expression tables grouping params '( '[], (nullity ty))) where
471474 pi = UnsafeExpression "pi()"
472475 exp = unsafeFunction "exp"
473476 log = unsafeFunction "ln"
@@ -492,11 +495,11 @@ instance (PGNum ty, PGFloating ty) => Floating
492495-- "atan2(pi(), 2)"
493496atan2_
494497 :: PGFloating float
495− => Expression tables grouping params ('Required (nullity float))
498+ => Expression tables grouping params '( '[], (nullity float))
496499 -- ^ numerator
497− -> Expression tables grouping params ('Required (nullity float))
500+ -> Expression tables grouping params '( '[], (nullity float))
498501 -- ^ denominator
499− -> Expression tables grouping params ('Required (nullity float))
502+ -> Expression tables grouping params '( '[], (nullity float))
500503atan2_ y x = UnsafeExpression $
501504 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
502505
@@ -507,11 +510,11 @@ atan2_ y x = UnsafeExpression $
507510-- | >>> renderExpression $ true & cast int4
508511-- "(TRUE :: int4)"
509512cast
510− :: TypeExpression ('Required ('Null ty1))
513+ :: TypeExpression '( '[], ('Null ty1))
511514 -- ^ type to cast as
512− -> Expression tables grouping params ('Required (nullity ty0))
515+ -> Expression tables grouping params '( '[], (nullity ty0))
513516 -- ^ value to convert
514− -> Expression tables grouping params ('Required (nullity ty1))
517+ -> Expression tables grouping params '( '[], (nullity ty1))
515518cast ty x = UnsafeExpression $ parenthesized $
516519 renderExpression x <+> "::" <+> renderTypeExpression ty
517520
@@ -521,11 +524,11 @@ cast ty x = UnsafeExpression $ parenthesized $
521524-- "(5 / 2)"
522525quot_
523526 :: PGIntegral int
524− => Expression tables grouping params ('Required (nullity int))
527+ => Expression tables grouping params '( '[], (nullity int))
525528 -- ^ numerator
526− -> Expression tables grouping params ('Required (nullity int))
529+ -> Expression tables grouping params '( '[], (nullity int))
527530 -- ^ denominator
528− -> Expression tables grouping params ('Required (nullity int))
531+ -> Expression tables grouping params '( '[], (nullity int))
529532quot_ = unsafeBinaryOp "/"
530533
531534-- | remainder upon integer division
@@ -534,38 +537,38 @@ quot_ = unsafeBinaryOp "/"
534537-- "(5 % 2)"
535538rem_
536539 :: PGIntegral int
537− => Expression tables grouping params ('Required (nullity int))
540+ => Expression tables grouping params '( '[], (nullity int))
538541 -- ^ numerator
539− -> Expression tables grouping params ('Required (nullity int))
542+ -> Expression tables grouping params '( '[], (nullity int))
540543 -- ^ denominator
541− -> Expression tables grouping params ('Required (nullity int))
544+ -> Expression tables grouping params '( '[], (nullity int))
542545rem_ = unsafeBinaryOp "%"
543546
544547-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ trunc pi
545548-- "trunc(pi())"
546549trunc
547550 :: PGFloating frac
548− => Expression tables grouping params ('Required (nullity frac))
551+ => Expression tables grouping params '( '[], (nullity frac))
549552 -- ^ fractional number
550− -> Expression tables grouping params ('Required (nullity frac))
553+ -> Expression tables grouping params '( '[], (nullity frac))
551554trunc = unsafeFunction "trunc"
552555
553556-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ round_ pi
554557-- "round(pi())"
555558round_
556559 :: PGFloating frac
557− => Expression tables grouping params ('Required (nullity frac))
560+ => Expression tables grouping params '( '[], (nullity frac))
558561 -- ^ fractional number
559− -> Expression tables grouping params ('Required (nullity frac))
562+ -> Expression tables grouping params '( '[], (nullity frac))
560563round_ = unsafeFunction "round"
561564
562565-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ ceiling_ pi
563566-- "ceiling(pi())"
564567ceiling_
565568 :: PGFloating frac
566− => Expression tables grouping params ('Required (nullity frac))
569+ => Expression tables grouping params '( '[], (nullity frac))
567570 -- ^ fractional number
568− -> Expression tables grouping params ('Required (nullity frac))
571+ -> Expression tables grouping params '( '[], (nullity frac))
569572ceiling_ = unsafeFunction "ceiling"
570573
571574-- | A `Condition` is a boolean valued `Expression`. While SQL allows
@@ -573,7 +576,7 @@ ceiling_ = unsafeFunction "ceiling"
573576-- forcing one to handle the case of @NULL@ explicitly to produce
574577-- a `Condition`.
575578type Condition tables grouping params =
576− Expression tables grouping params ('Required ('NotNull 'PGbool))
579+ Expression tables grouping params '( '[], ('NotNull 'PGbool))
577580
578581-- | >>> renderExpression true
579582-- "TRUE"
@@ -612,10 +615,10 @@ not_ = unsafeUnaryOp "NOT"
612615-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
613616caseWhenThenElse
614617 :: [ ( Condition tables grouping params
615− , Expression tables grouping params ('Required ty)
618+ , Expression tables grouping params '( '[], ty)
616619 ) ]
617− -> Expression tables grouping params ('Required ty)
618− -> Expression tables grouping params ('Required ty)
620+ -> Expression tables grouping params '( '[], ty)
621+ -> Expression tables grouping params '( '[], ty)
619622caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
620623 [ "CASE"
621624 , mconcat
@@ -633,9 +636,9 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
633636-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
634637ifThenElse
635638 :: Condition tables grouping params
636− -> Expression tables grouping params ('Required ty)
637− -> Expression tables grouping params ('Required ty)
638− -> Expression tables grouping params ('Required ty)
639+ -> Expression tables grouping params '( '[], ty)
640+ -> Expression tables grouping params '( '[], ty)
641+ -> Expression tables grouping params '( '[], ty)
639642ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
640643
641644-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -644,85 +647,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
644647-- >>> renderExpression $ unNull true .== null_
645648-- "(TRUE = NULL)"
646649(.==)
647− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
648− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
649− -> Expression tables grouping params ('Required (nullity 'PGbool))
650+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
651+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
652+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
650653(.==) = unsafeBinaryOp "="
651654infix 4 .==
652655
653656-- | >>> renderExpression $ unNull true ./= null_
654657-- "(TRUE <> NULL)"
655658(./=)
656− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
657− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
658− -> Expression tables grouping params ('Required (nullity 'PGbool))
659+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
660+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
661+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
659662(./=) = unsafeBinaryOp "<>"
660663infix 4 ./=
661664
662665-- | >>> renderExpression $ unNull true .>= null_
663666-- "(TRUE >= NULL)"
664667(.>=)
665− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
666− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
667− -> Expression tables grouping params ('Required (nullity 'PGbool))
668+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
669+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
670+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
668671(.>=) = unsafeBinaryOp ">="
669672infix 4 .>=
670673
671674-- | >>> renderExpression $ unNull true .< null_
672675-- "(TRUE < NULL)"
673676(.<)
674− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
675− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
676− -> Expression tables grouping params ('Required (nullity 'PGbool))
677+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
678+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
679+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
677680(.<) = unsafeBinaryOp "<"
678681infix 4 .<
679682
680683-- | >>> renderExpression $ unNull true .<= null_
681684-- "(TRUE <= NULL)"
682685(.<=)
683− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
684− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
685− -> Expression tables grouping params ('Required (nullity 'PGbool))
686+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
687+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
688+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
686689(.<=) = unsafeBinaryOp "<="
687690infix 4 .<=
688691
689692-- | >>> renderExpression $ unNull true .> null_
690693-- "(TRUE > NULL)"
691694(.>)
692− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
693− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
694− -> Expression tables grouping params ('Required (nullity 'PGbool))
695+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
696+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
697+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
695698(.>) = unsafeBinaryOp ">"
696699infix 4 .>
697700
698701-- | >>> renderExpression $ currentDate
699702-- "CURRENT_DATE"
700703currentDate
701− :: Expression tables grouping params ('Required (nullity 'PGdate))
704+ :: Expression tables grouping params '( '[], (nullity 'PGdate))
702705currentDate = UnsafeExpression "CURRENT_DATE"
703706
704707-- | >>> renderExpression $ currentTime
705708-- "CURRENT_TIME"
706709currentTime
707− :: Expression tables grouping params ('Required (nullity 'PGtimetz))
710+ :: Expression tables grouping params '( '[], (nullity 'PGtimetz))
708711currentTime = UnsafeExpression "CURRENT_TIME"
709712
710713-- | >>> renderExpression $ currentTimestamp
711714-- "CURRENT_TIMESTAMP"
712715currentTimestamp
713− :: Expression tables grouping params ('Required (nullity 'PGtimestamptz))
716+ :: Expression tables grouping params '( '[], (nullity 'PGtimestamptz))
714717currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
715718
716719-- | >>> renderExpression $ localTime
717720-- "LOCALTIME"
718721localTime
719− :: Expression tables grouping params ('Required (nullity 'PGtime))
722+ :: Expression tables grouping params '( '[], (nullity 'PGtime))
720723localTime = UnsafeExpression "LOCALTIME"
721724
722725-- | >>> renderExpression $ localTimestamp
723726-- "LOCALTIMESTAMP"
724727localTimestamp
725− :: Expression tables grouping params ('Required (nullity 'PGtimestamp))
728+ :: Expression tables grouping params '( '[], (nullity 'PGtimestamp))
726729localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
727730
728731{-----------------------------------------
@@ -730,7 +733,7 @@ text
730733-----------------------------------------}
731734
732735instance IsString
733− (Expression tables grouping params ('Required (nullity 'PGtext))) where
736+ (Expression tables grouping params '( '[], (nullity 'PGtext))) where
734737 fromString str = UnsafeExpression $
735738 "E\'" <> fromString (escape =<< str) <> "\'"
736739 where
@@ -746,32 +749,32 @@ instance IsString
746749 c -> [c]
747750
748751instance Monoid
749− (Expression tables grouping params ('Required (nullity 'PGtext))) where
752+ (Expression tables grouping params '( '[], (nullity 'PGtext))) where
750753 mempty = fromString ""
751754 mappend = unsafeBinaryOp "||"
752755
753756-- | >>> renderExpression $ lower "ARRRGGG"
754757-- "lower(E'ARRRGGG')"
755758lower
756− :: Expression tables grouping params ('Required (nullity 'PGtext))
759+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
757760 -- ^ string to lower case
758− -> Expression tables grouping params ('Required (nullity 'PGtext))
761+ -> Expression tables grouping params '( '[], (nullity 'PGtext))
759762lower = unsafeFunction "lower"
760763
761764-- | >>> renderExpression $ upper "eeee"
762765-- "upper(E'eeee')"
763766upper
764− :: Expression tables grouping params ('Required (nullity 'PGtext))
767+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
765768 -- ^ string to upper case
766− -> Expression tables grouping params ('Required (nullity 'PGtext))
769+ -> Expression tables grouping params '( '[], (nullity 'PGtext))
767770upper = unsafeFunction "upper"
768771
769772-- | >>> renderExpression $ charLength "four"
770773-- "char_length(E'four')"
771774charLength
772− :: Expression tables grouping params ('Required (nullity 'PGtext))
775+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
773776 -- ^ string to measure
774− -> Expression tables grouping params ('Required (nullity 'PGint4))
777+ -> Expression tables grouping params '( '[], (nullity 'PGint4))
775778charLength = unsafeFunction "char_length"
776779
777780-- | The `like` expression returns true if the @string@ matches
@@ -784,11 +787,11 @@ charLength = unsafeFunction "char_length"
784787-- >>> renderExpression $ "abc" `like` "a%"
785788-- "(E'abc' LIKE E'a%')"
786789like
787− :: Expression tables grouping params ('Required (nullity 'PGtext))
790+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
788791 -- ^ string
789− -> Expression tables grouping params ('Required (nullity 'PGtext))
792+ -> Expression tables grouping params '( '[], (nullity 'PGtext))
790793 -- ^ pattern
791− -> Expression tables grouping params ('Required (nullity 'PGbool))
794+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
792795like = unsafeBinaryOp "LIKE"
793796
794797{-----------------------------------------
@@ -798,16 +801,16 @@ aggregation
798801-- | escape hatch to define aggregate functions
799802unsafeAggregate
800803 :: ByteString -- ^ aggregate function
801− -> Expression tables 'Ungrouped params ('Required xty)
802− -> Expression tables ('Grouped bys) params ('Required yty)
804+ -> Expression tables 'Ungrouped params '( '[], xty)
805+ -> Expression tables ('Grouped bys) params '( '[], yty)
803806unsafeAggregate fun x = UnsafeExpression $ mconcat
804807 [fun, "(", renderExpression x, ")"]
805808
806809-- | escape hatch to define aggregate functions over distinct values
807810unsafeAggregateDistinct
808811 :: ByteString -- ^ aggregate function
809− -> Expression tables 'Ungrouped params ('Required xty)
810− -> Expression tables ('Grouped bys) params ('Required yty)
812+ -> Expression tables 'Ungrouped params '( '[], xty)
813+ -> Expression tables ('Grouped bys) params '( '[], yty)
811814unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
812815 [fun, "(DISTINCT ", renderExpression x, ")"]
813816
@@ -815,27 +818,27 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
815818-- "sum(col)"
816819sum_
817820 :: PGNum ty
818− => Expression tables 'Ungrouped params ('Required (nullity ty))
821+ => Expression tables 'Ungrouped params '( '[], (nullity ty))
819822 -- ^ what to sum
820− -> Expression tables ('Grouped bys) params ('Required (nullity ty))
823+ -> Expression tables ('Grouped bys) params '( '[], (nullity ty))
821824sum_ = unsafeAggregate "sum"
822825
823826-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGnumeric)]] $ sumDistinct #col
824827-- "sum(DISTINCT col)"
825828sumDistinct
826829 :: PGNum ty
827− => Expression tables 'Ungrouped params ('Required (nullity ty))
830+ => Expression tables 'Ungrouped params '( '[], (nullity ty))
828831 -- ^ what to sum
829− -> Expression tables ('Grouped bys) params ('Required (nullity ty))
832+ -> Expression tables ('Grouped bys) params '( '[], (nullity ty))
830833sumDistinct = unsafeAggregateDistinct "sum"
831834
832835-- | A constraint for `PGType`s that you can take averages of and the resulting
833836-- `PGType`.
834837class PGAvg ty avg | ty -> avg where
835838 avg, avgDistinct
836− :: Expression tables 'Ungrouped params ('Required (nullity ty))
839+ :: Expression tables 'Ungrouped params '( '[], (nullity ty))
837840 -- ^ what to average
838− -> Expression tables ('Grouped bys) params ('Required (nullity avg))
841+ -> Expression tables ('Grouped bys) params '( '[], (nullity avg))
839842 avg = unsafeAggregate "avg"
840843 avgDistinct = unsafeAggregateDistinct "avg"
841844instance PGAvg 'PGint2 'PGnumeric
@@ -850,68 +853,68 @@ instance PGAvg 'PGinterval 'PGinterval
850853-- "bit_and(col)"
851854bitAnd
852855 :: PGIntegral int
853− => Expression tables 'Ungrouped params ('Required (nullity int))
856+ => Expression tables 'Ungrouped params '( '[], (nullity int))
854857 -- ^ what to aggregate
855− -> Expression tables ('Grouped bys) params ('Required (nullity int))
858+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
856859bitAnd = unsafeAggregate "bit_and"
857860
858861-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitOr #col
859862-- "bit_or(col)"
860863bitOr
861864 :: PGIntegral int
862− => Expression tables 'Ungrouped params ('Required (nullity int))
865+ => Expression tables 'Ungrouped params '( '[], (nullity int))
863866 -- ^ what to aggregate
864− -> Expression tables ('Grouped bys) params ('Required (nullity int))
867+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
865868bitOr = unsafeAggregate "bit_or"
866869
867870-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitAndDistinct #col
868871-- "bit_and(DISTINCT col)"
869872bitAndDistinct
870873 :: PGIntegral int
871− => Expression tables 'Ungrouped params ('Required (nullity int))
874+ => Expression tables 'Ungrouped params '( '[], (nullity int))
872875 -- ^ what to aggregate
873− -> Expression tables ('Grouped bys) params ('Required (nullity int))
876+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
874877bitAndDistinct = unsafeAggregateDistinct "bit_and"
875878
876879-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitOrDistinct #col
877880-- "bit_or(DISTINCT col)"
878881bitOrDistinct
879882 :: PGIntegral int
880− => Expression tables 'Ungrouped params ('Required (nullity int))
883+ => Expression tables 'Ungrouped params '( '[], (nullity int))
881884 -- ^ what to aggregate
882− -> Expression tables ('Grouped bys) params ('Required (nullity int))
885+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
883886bitOrDistinct = unsafeAggregateDistinct "bit_or"
884887
885888-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolAnd #col
886889-- "bool_and(col)"
887890boolAnd
888− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
891+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
889892 -- ^ what to aggregate
890− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
893+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
891894boolAnd = unsafeAggregate "bool_and"
892895
893896-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolOr #col
894897-- "bool_or(col)"
895898boolOr
896− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
899+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
897900 -- ^ what to aggregate
898− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
901+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
899902boolOr = unsafeAggregate "bool_or"
900903
901904-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolAndDistinct #col
902905-- "bool_and(DISTINCT col)"
903906boolAndDistinct
904− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
907+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
905908 -- ^ what to aggregate
906− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
909+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
907910boolAndDistinct = unsafeAggregateDistinct "bool_and"
908911
909912-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolOrDistinct #col
910913-- "bool_or(DISTINCT col)"
911914boolOrDistinct
912− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
915+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
913916 -- ^ what to aggregate
914− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
917+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
915918boolOrDistinct = unsafeAggregateDistinct "bool_or"
916919
917920-- | A special aggregation that does not require an input
@@ -919,23 +922,23 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
919922-- >>> renderExpression countStar
920923-- "count(*)"
921924countStar
922− :: Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
925+ :: Expression tables ('Grouped bys) params '( '[], ('NotNull 'PGint8))
923926countStar = UnsafeExpression $ "count(*)"
924927
925928-- | >>> renderExpression @'[_ ::: '["col" ::: 'Optional _]] $ count #col
926929-- "count(col)"
927930count
928− :: Expression tables 'Ungrouped params ('Required ty)
931+ :: Expression tables 'Ungrouped params '( '[], ty)
929932 -- ^ what to count
930− -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
933+ -> Expression tables ('Grouped bys) params '( '[], ('NotNull 'PGint8))
931934count = unsafeAggregate "count"
932935
933936-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required _]] $ countDistinct #col
934937-- "count(DISTINCT col)"
935938countDistinct
936− :: Expression tables 'Ungrouped params ('Required ty)
939+ :: Expression tables 'Ungrouped params '( '[], ty)
937940 -- ^ what to count
938− -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
941+ -> Expression tables ('Grouped bys) params '( '[], ('NotNull 'PGint8))
939942countDistinct = unsafeAggregateDistinct "count"
940943
941944-- | synonym for `boolAnd`
@@ -943,9 +946,9 @@ countDistinct = unsafeAggregateDistinct "count"
943946-- >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ every #col
944947-- "every(col)"
945948every
946− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
949+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
947950 -- ^ what to aggregate
948− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
951+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
949952every = unsafeAggregate "every"
950953
951954-- | synonym for `boolAndDistinct`
@@ -953,16 +956,16 @@ every = unsafeAggregate "every"
953956-- >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ everyDistinct #col
954957-- "every(DISTINCT col)"
955958everyDistinct
956− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
959+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
957960 -- ^ what to aggregate
958− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
961+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
959962everyDistinct = unsafeAggregateDistinct "every"
960963
961964-- | minimum and maximum aggregation
962965max_, min_, maxDistinct, minDistinct
963− :: Expression tables 'Ungrouped params ('Required (nullity ty))
966+ :: Expression tables 'Ungrouped params '( '[], (nullity ty))
964967 -- ^ what to aggregate
965− -> Expression tables ('Grouped bys) params ('Required (nullity ty))
968+ -> Expression tables ('Grouped bys) params '( '[], (nullity ty))
966969max_ = unsafeAggregate "max"
967970min_ = unsafeAggregate "min"
968971maxDistinct = unsafeAggregateDistinct "max"
@@ -1005,97 +1008,97 @@ newtype TypeExpression (ty :: ColumnType)
10051008 deriving (GHC.Generic,Show,Eq,Ord,NFData)
10061009
10071010-- | logical Boolean (true/false)
1008−bool :: TypeExpression ('Required ('Null 'PGbool))
1011+bool :: TypeExpression '( '[], ('Null 'PGbool))
10091012bool = UnsafeTypeExpression "bool"
10101013-- | signed two-byte integer
1011−int2, smallint :: TypeExpression ('Required ('Null 'PGint2))
1014+int2, smallint :: TypeExpression '( '[], ('Null 'PGint2))
10121015int2 = UnsafeTypeExpression "int2"
10131016smallint = UnsafeTypeExpression "smallint"
10141017-- | signed four-byte integer
1015−int4, int, integer :: TypeExpression ('Required ('Null 'PGint4))
1018+int4, int, integer :: TypeExpression '( '[], ('Null 'PGint4))
10161019int4 = UnsafeTypeExpression "int4"
10171020int = UnsafeTypeExpression "int"
10181021integer = UnsafeTypeExpression "integer"
10191022-- | signed eight-byte integer
1020−int8, bigint :: TypeExpression ('Required ('Null 'PGint8))
1023+int8, bigint :: TypeExpression '( '[], ('Null 'PGint8))
10211024int8 = UnsafeTypeExpression "int8"
10221025bigint = UnsafeTypeExpression "bigint"
10231026-- | arbitrary precision numeric type
1024−numeric :: TypeExpression ('Required ('Null 'PGnumeric))
1027+numeric :: TypeExpression '( '[], ('Null 'PGnumeric))
10251028numeric = UnsafeTypeExpression "numeric"
10261029-- | single precision floating-point number (4 bytes)
1027−float4, real :: TypeExpression ('Required ('Null 'PGfloat4))
1030+float4, real :: TypeExpression '( '[], ('Null 'PGfloat4))
10281031float4 = UnsafeTypeExpression "float4"
10291032real = UnsafeTypeExpression "real"
10301033-- | double precision floating-point number (8 bytes)
1031−float8, doublePrecision :: TypeExpression ('Required ('Null 'PGfloat8))
1034+float8, doublePrecision :: TypeExpression '( '[], ('Null 'PGfloat8))
10321035float8 = UnsafeTypeExpression "float8"
10331036doublePrecision = UnsafeTypeExpression "double precision"
10341037-- | not a true type, but merely a notational convenience for creating
10351038-- unique identifier columns with type `'PGint2`
1036−serial2, smallserial :: TypeExpression ('Optional ('NotNull 'PGint2))
1039+serial2, smallserial :: TypeExpression '(constraints, ('NotNull 'PGint2))
10371040serial2 = UnsafeTypeExpression "serial2"
10381041smallserial = UnsafeTypeExpression "smallserial"
10391042-- | not a true type, but merely a notational convenience for creating
10401043-- unique identifier columns with type `'PGint4`
1041−serial4, serial :: TypeExpression ('Optional ('NotNull 'PGint4))
1044+serial4, serial :: TypeExpression '(constraints, ('NotNull 'PGint4))
10421045serial4 = UnsafeTypeExpression "serial4"
10431046serial = UnsafeTypeExpression "serial"
10441047-- | not a true type, but merely a notational convenience for creating
10451048-- unique identifier columns with type `'PGint8`
1046−serial8, bigserial :: TypeExpression ('Optional ('NotNull 'PGint8))
1049+serial8, bigserial :: TypeExpression '(constraints, ('NotNull 'PGint8))
10471050serial8 = UnsafeTypeExpression "serial8"
10481051bigserial = UnsafeTypeExpression "bigserial"
10491052-- | variable-length character string
1050−text :: TypeExpression ('Required ('Null 'PGtext))
1053+text :: TypeExpression '( '[], ('Null 'PGtext))
10511054text = UnsafeTypeExpression "text"
10521055-- | fixed-length character string
10531056char, character
10541057 :: (KnownNat n, 1 <= n)
10551058 => proxy n
1056− -> TypeExpression ('Required ('Null ('PGchar n)))
1059+ -> TypeExpression '( '[], ('Null ('PGchar n)))
10571060char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
10581061character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
10591062-- | variable-length character string
10601063varchar, characterVarying
10611064 :: (KnownNat n, 1 <= n)
10621065 => proxy n
1063− -> TypeExpression ('Required ('Null ('PGvarchar n)))
1066+ -> TypeExpression '( '[], ('Null ('PGvarchar n)))
10641067varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
10651068characterVarying p = UnsafeTypeExpression $
10661069 "character varying(" <> renderNat p <> ")"
10671070-- | binary data ("byte array")
1068−bytea :: TypeExpression ('Required ('Null 'PGbytea))
1071+bytea :: TypeExpression '( '[], ('Null 'PGbytea))
10691072bytea = UnsafeTypeExpression "bytea"
10701073-- | date and time (no time zone)
1071−timestamp :: TypeExpression ('Required ('Null 'PGtimestamp))
1074+timestamp :: TypeExpression '( '[], ('Null 'PGtimestamp))
10721075timestamp = UnsafeTypeExpression "timestamp"
10731076-- | date and time, including time zone
1074−timestampWithTimeZone :: TypeExpression ('Required ('Null 'PGtimestamptz))
1077+timestampWithTimeZone :: TypeExpression '( '[], ('Null 'PGtimestamptz))
10751078timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
10761079-- | calendar date (year, month, day)
1077−date :: TypeExpression ('Required ('Null 'PGdate))
1080+date :: TypeExpression '( '[], ('Null 'PGdate))
10781081date = UnsafeTypeExpression "date"
10791082-- | time of day (no time zone)
1080−time :: TypeExpression ('Required ('Null 'PGtime))
1083+time :: TypeExpression '( '[], ('Null 'PGtime))
10811084time = UnsafeTypeExpression "time"
10821085-- | time of day, including time zone
1083−timeWithTimeZone :: TypeExpression ('Required ('Null 'PGtimetz))
1086+timeWithTimeZone :: TypeExpression '( '[], ('Null 'PGtimetz))
10841087timeWithTimeZone = UnsafeTypeExpression "time with time zone"
10851088-- | time span
1086−interval :: TypeExpression ('Required ('Null 'PGinterval))
1089+interval :: TypeExpression '( '[], ('Null 'PGinterval))
10871090interval = UnsafeTypeExpression "interval"
10881091-- | universally unique identifier
1089−uuid :: TypeExpression ('Required ('Null 'PGuuid))
1092+uuid :: TypeExpression '( '[], ('Null 'PGuuid))
10901093uuid = UnsafeTypeExpression "uuid"
10911094-- | IPv4 or IPv6 host address
1092−inet :: TypeExpression ('Required ('Null 'PGinet))
1095+inet :: TypeExpression '( '[], ('Null 'PGinet))
10931096inet = UnsafeTypeExpression "inet"
10941097-- | textual JSON data
1095−json :: TypeExpression ('Required ('Null 'PGjson))
1098+json :: TypeExpression '( '[], ('Null 'PGjson))
10961099json = UnsafeTypeExpression "json"
10971100-- | binary JSON data, decomposed
1098−jsonb :: TypeExpression ('Required ('Null 'PGjsonb))
1101+jsonb :: TypeExpression '( '[], ('Null 'PGjsonb))
10991102jsonb = UnsafeTypeExpression "jsonb"
11001103
11011104-- | used in `createTable` commands as a column constraint to ensure
@@ -1107,15 +1110,15 @@ notNull ty = UnsafeTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
11071110
11081111-- | used in `createTable` commands as a column constraint to give a default
11091112default_
1110− :: Expression '[] 'Ungrouped '[] ('Required ty)
1111− -> TypeExpression ('Required ty)
1112− -> TypeExpression ('Optional ty)
1113+ :: Expression '[] 'Ungrouped '[] '( '[], ty)
1114+ -> TypeExpression '( '[], ty)
1115+ -> TypeExpression '(constraints, ty)
11131116default_ x ty = UnsafeTypeExpression $
11141117 renderTypeExpression ty <+> "DEFAULT" <+> renderExpression x
11151118
11161119-- | `pgtype` is a demoted version of a `PGType`
11171120class PGTyped (ty :: PGType) where
1118− pgtype :: TypeExpression ('Required ('Null ty))
1121+ pgtype :: TypeExpression '( '[], ('Null ty))
11191122instance PGTyped 'PGbool where pgtype = bool
11201123instance PGTyped 'PGint2 where pgtype = int2
11211124instance PGTyped 'PGint4 where pgtype = int4