on dev help sign in
more functions
commit7d449835ed28d65935d3b72e915ff18c6c1a2afd authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateFri 15 Mar 2019, 18:01 (8 years ago) parentc25657e
2 files changed+318−387
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+314−387 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+314−387
@@ -55,7 +55,7 @@ module Squeal.PostgreSQL.Expression
5555 , field
5656 -- ** Functions
5757 , unsafeBinaryOp
58− , unsafeUnaryOp
58+ , unsafeUnaryOpL
5959 , unsafeFunction
6060 , unsafeVariadicFunction
6161 , atan2_
@@ -287,6 +287,10 @@ newtype Expression
287287instance RenderSQL (Expression outer grp commons schemas params from ty) where
288288 renderSQL = renderExpression
289289
290+type Expr x
291+ = forall outer grp commons schemas params from
292+ . Expression outer grp commons schemas params from x
293+
290294type Operator x1 x2 y
291295 = forall outer grp commons schemas params from
292296 . Expression outer grp commons schemas params from x1
@@ -303,6 +307,16 @@ type FunctionHet xs y
303307 . NP (Expression outer grp commons schemas params from) xs
304308 -> Expression outer grp commons schemas params from y
305309
310+type FunctionHom x y
311+ = forall outer grp commons schemas params from
312+ . [Expression outer grp commons schemas params from x]
313+ -> Expression outer grp commons schemas params from x
314+ -> Expression outer grp commons schemas params from y
315+
316+unsafeFunctionHom :: ByteString -> FunctionHom x y
317+unsafeFunctionHom fun xs x = UnsafeExpression $ fun <> parenthesized
318+ (commaSeparated (renderSQL <$> xs) <> ", " <> renderSQL x)
319+
306320{- | A `HasParameter` constraint is used to indicate a value that is
307321supplied externally to a SQL statement.
308322`Squeal.PostgreSQL.PQ.manipulateParams`,
@@ -443,16 +457,14 @@ instance
443457--
444458-- >>> printSQL null_
445459-- NULL
446−null_ :: Expression outer grp commons schemas params from ('Null ty)
460+null_ :: Expr ('Null ty)
447461null_ = UnsafeExpression "NULL"
448462
449463-- | analagous to `Just`
450464--
451465-- >>> printSQL $ notNull true
452466-- TRUE
453−notNull
454− :: Expression outer grp commons schemas params from ('NotNull ty)
455− -> Expression outer grp commons schemas params from ('Null ty)
467+notNull :: 'NotNull ty :--> 'Null ty
456468notNull = UnsafeExpression . renderSQL
457469
458470-- | return the leftmost value which is not NULL
@@ -533,26 +545,25 @@ nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
533545array
534546 :: [Expression outer grp commons schemas params from ty]
535547 -- ^ array elements
536− -> Expression outer grp commons schemas params from (nullity ('PGvararray ty))
548+ -> Expression outer grp commons schemas params from (null ('PGvararray ty))
537549array xs = UnsafeExpression $
538550 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
539551
540552-- | >>> printSQL $ cardinality (array [null_, false, true])
541553-- cardinality(ARRAY[NULL, FALSE, TRUE])
542−cardinality :: nullity ('PGvararray ty) :--> nullity 'PGint8
554+cardinality :: null ('PGvararray ty) :--> null 'PGint8
543555cardinality = unsafeFunction "cardinality"
544556
545557-- | >>> printSQL $ array [null_, false, true] & index 2
546558-- (ARRAY[NULL, FALSE, TRUE])[2]
547559index
548− :: Word64 -- ^ index
549− -> nullity ('PGvararray ty) -- ^ array
550− :--> NullifyType ty
560+ :: Word64 -- ^ index
561+ -> null ('PGvararray ty) :--> NullifyType ty
551562index n expr = UnsafeExpression $
552563 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
553564
554565instance (KnownSymbol label, label `In` labels) => IsPGlabel label
555− (Expression outer grp commons schemas params from (nullity ('PGenum labels))) where
566+ (Expression outer grp commons schemas params from (null ('PGenum labels))) where
556567 label = UnsafeExpression $ renderSQL (PGlabel @label)
557568
558569-- | A row constructor is an expression that builds a row value
@@ -571,7 +582,7 @@ row
571582 :: SListI row
572583 => NP (Aliased (Expression outer grp commons schemas params from)) row
573584 -- ^ zero or more expressions for the row field values
574− -> Expression outer grp commons schemas params from (nullity ('PGcomposite row))
585+ -> Expression outer grp commons schemas params from (null ('PGcomposite row))
575586row exprs = UnsafeExpression $ "ROW" <> parenthesized
576587 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
577588
@@ -598,51 +609,38 @@ field td fld expr = UnsafeExpression $
598609 <> "." <> renderSQL fld
599610
600611instance Semigroup
601− (Expression outer grp commons schemas params from (nullity ('PGvararray ty))) where
612+ (Expression outer grp commons schemas params from (null ('PGvararray ty))) where
602613 (<>) = unsafeBinaryOp "||"
603614
604615instance Monoid
605− (Expression outer grp commons schemas params from (nullity ('PGvararray ty))) where
616+ (Expression outer grp commons schemas params from (null ('PGvararray ty))) where
606617 mempty = array []
607618 mappend = (<>)
608619
609−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression outer grp commons schemas '[ 'NotNull 'PGtimestamptz] from ('NotNull 'PGtimestamptz)
620+-- | >>> let expr = greatest [param @1] currentTimestamp :: Expression outer grp commons schemas '[ 'NotNull 'PGtimestamptz] from ('NotNull 'PGtimestamptz)
610621-- >>> printSQL expr
611−-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
612−greatest
613− :: Expression outer grp commons schemas params from (nullty)
614− -- ^ needs at least 1 argument
615− -> [Expression outer grp commons schemas params from (nullty)]
616− -- ^ or more
617− -> Expression outer grp commons schemas params from (nullty)
618−greatest x xs = UnsafeExpression $ "GREATEST("
619− <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
622+-- GREATEST(($1 :: timestamp with time zone), CURRENT_TIMESTAMP)
623+greatest :: FunctionHom ty ty
624+greatest = unsafeFunctionHom "GREATEST"
620625
621−-- | >>> printSQL $ least currentTimestamp [null_]
622−-- LEAST(CURRENT_TIMESTAMP, NULL)
623−least
624− :: Expression outer grp commons schemas params from (nullty)
625− -- ^ needs at least 1 argument
626− -> [Expression outer grp commons schemas params from (nullty)]
627− -- ^ or more
628− -> Expression outer grp commons schemas params from (nullty)
629−least x xs = UnsafeExpression $ "LEAST("
630− <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
626+-- | >>> printSQL $ least [null_] currentTimestamp
627+-- LEAST(NULL, CURRENT_TIMESTAMP)
628+least :: FunctionHom ty ty
629+least = unsafeFunctionHom "LEAST"
631630
632631-- | >>> printSQL $ unsafeBinaryOp "OR" true false
633632-- (TRUE OR FALSE)
634−unsafeBinaryOp
635− :: ByteString
636− -- ^ operator
637− -> Operator ty0 ty1 ty2
633+unsafeBinaryOp :: ByteString {- ^ operator -} -> Operator ty0 ty1 ty2
638634unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
639635 renderSQL x <+> op <+> renderSQL y
640636
641−-- | >>> printSQL $ unsafeUnaryOp "NOT" true
637+-- | >>> printSQL $ unsafeUnaryOpL "NOT" true
642638-- (NOT TRUE)
643−unsafeUnaryOp :: ByteString {- ^ operator -} -> x :--> y
644−unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
645− op <+> renderSQL x
639+unsafeUnaryOpL :: ByteString {- ^ operator -} -> x :--> y
640+unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
641+
642+unsafeUnaryOpR :: ByteString {- ^ operator -} -> x :--> y
643+unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
646644
647645-- | >>> printSQL $ unsafeFunction "f" true
648646-- f(TRUE)
@@ -668,7 +666,7 @@ unsafeVariadicFunction fun x = UnsafeExpression $
668666 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
669667
670668instance ty `In` PGNum
671− => Num (Expression outer grp commons schemas params from (nullity ty)) where
669+ => Num (Expression outer grp commons schemas params from (null ty)) where
672670 (+) = unsafeBinaryOp "+"
673671 (-) = unsafeBinaryOp "-"
674672 (*) = unsafeBinaryOp "*"
@@ -680,7 +678,7 @@ instance ty `In` PGNum
680678 . show
681679
682680instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
683− (Expression outer grp commons schemas params from (nullity ty)) where
681+ (Expression outer grp commons schemas params from (null ty)) where
684682 (/) = unsafeBinaryOp "/"
685683 fromRational
686684 = UnsafeExpression
@@ -690,7 +688,7 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
690688 . fromRat @Double
691689
692690instance (ty `In` PGNum, ty `In` PGFloating) => Floating
693− (Expression outer grp commons schemas params from (nullity ty)) where
691+ (Expression outer grp commons schemas params from (null ty)) where
694692 pi = UnsafeExpression "pi()"
695693 exp = unsafeFunction "exp"
696694 log = unsafeFunction "ln"
@@ -713,20 +711,15 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
713711
714712-- | >>> :{
715713-- let
716−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
717−-- expression = atan2_ pi 2
714+-- expression :: Expr (null 'PGfloat4)
715+-- expression = atan2_ (pi *: 2)
718716-- in printSQL expression
719717-- :}
720718-- atan2(pi(), 2)
721719atan2_
722720 :: float `In` PGFloating
723− => Expression outer grp commons schemas params from (nullity float)
724− -- ^ numerator
725− -> Expression outer grp commons schemas params from (nullity float)
726− -- ^ denominator
727− -> Expression outer grp commons schemas params from (nullity float)
728−atan2_ y x = UnsafeExpression $
729− "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
721+ => FunctionHet '[ null float, null float] (null float)
722+atan2_ = unsafeFunctionHet "atan2"
730723
731724-- When a `cast` is applied to an `Expression` of a known type, it
732725-- represents a run-time type conversion. The cast will succeed only if a
@@ -747,58 +740,58 @@ cast ty x = UnsafeExpression $ parenthesized $
747740--
748741-- >>> :{
749742-- let
750−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
743+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
751744-- expression = 5 `quot_` 2
752745-- in printSQL expression
753746-- :}
754747-- (5 / 2)
755748quot_
756749 :: int `In` PGIntegral
757− => Operator (nullity int) (nullity int) (nullity int)
750+ => Operator (null int) (null int) (null int)
758751quot_ = unsafeBinaryOp "/"
759752
760753-- | remainder upon integer division
761754--
762755-- >>> :{
763756-- let
764−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
757+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
765758-- expression = 5 `rem_` 2
766759-- in printSQL expression
767760-- :}
768761-- (5 % 2)
769762rem_
770763 :: int `In` PGIntegral
771− => Operator (nullity int) (nullity int) (nullity int)
764+ => Operator (null int) (null int) (null int)
772765rem_ = unsafeBinaryOp "%"
773766
774767-- | >>> :{
775768-- let
776−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
769+-- expression :: Expression outer grp commons schemas params from (null 'PGfloat4)
777770-- expression = trunc pi
778771-- in printSQL expression
779772-- :}
780773-- trunc(pi())
781−trunc :: frac `In` PGFloating => nullity frac :--> nullity frac
774+trunc :: frac `In` PGFloating => null frac :--> null frac
782775trunc = unsafeFunction "trunc"
783776
784777-- | >>> :{
785778-- let
786−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
779+-- expression :: Expression outer grp commons schemas params from (null 'PGfloat4)
787780-- expression = round_ pi
788781-- in printSQL expression
789782-- :}
790783-- round(pi())
791−round_ :: frac `In` PGFloating => nullity frac :--> nullity frac
784+round_ :: frac `In` PGFloating => null frac :--> null frac
792785round_ = unsafeFunction "round"
793786
794787-- | >>> :{
795788-- let
796−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
789+-- expression :: Expression outer grp commons schemas params from (null 'PGfloat4)
797790-- expression = ceiling_ pi
798791-- in printSQL expression
799792-- :}
800793-- ceiling(pi())
801−ceiling_ :: frac `In` PGFloating => nullity frac :--> nullity frac
794+ceiling_ :: frac `In` PGFloating => null frac :--> null frac
802795ceiling_ = unsafeFunction "ceiling"
803796
804797-- | A `Condition` is an `Expression`, which can evaluate
@@ -809,34 +802,34 @@ type Condition outer grp commons schemas params from =
809802
810803-- | >>> printSQL true
811804-- TRUE
812−true :: Expression outer grp commons schemas params from (nullity 'PGbool)
805+true :: Expr (null 'PGbool)
813806true = UnsafeExpression "TRUE"
814807
815808-- | >>> printSQL false
816809-- FALSE
817−false :: Expression outer grp commons schemas params from (nullity 'PGbool)
810+false :: Expr (null 'PGbool)
818811false = UnsafeExpression "FALSE"
819812
820813-- | >>> printSQL $ not_ true
821814-- (NOT TRUE)
822−not_ :: nullity 'PGbool :--> nullity 'PGbool
823−not_ = unsafeUnaryOp "NOT"
815+not_ :: null 'PGbool :--> null 'PGbool
816+not_ = unsafeUnaryOpL "NOT"
824817
825818-- | >>> printSQL $ true .&& false
826819-- (TRUE AND FALSE)
827−(.&&) :: Operator (nullity 'PGbool) (nullity 'PGbool) (nullity 'PGbool)
820+(.&&) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
828821infixr 3 .&&
829822(.&&) = unsafeBinaryOp "AND"
830823
831824-- | >>> printSQL $ true .|| false
832825-- (TRUE OR FALSE)
833−(.||) :: Operator (nullity 'PGbool) (nullity 'PGbool) (nullity 'PGbool)
826+(.||) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
834827infixr 2 .||
835828(.||) = unsafeBinaryOp "OR"
836829
837830-- | >>> :{
838831-- let
839−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
832+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
840833-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
841834-- in printSQL expression
842835-- :}
@@ -864,7 +857,7 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
864857
865858-- | >>> :{
866859-- let
867−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
860+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
868861-- expression = ifThenElse true 1 0
869862-- in printSQL expression
870863-- :}
@@ -881,37 +874,37 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
881874--
882875-- >>> printSQL $ true .== null_
883876-- (TRUE = NULL)
884−(.==) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
877+(.==) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
885878(.==) = unsafeBinaryOp "="
886879infix 4 .==
887880
888881-- | >>> printSQL $ true ./= null_
889882-- (TRUE <> NULL)
890−(./=) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
883+(./=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
891884(./=) = unsafeBinaryOp "<>"
892885infix 4 ./=
893886
894887-- | >>> printSQL $ true .>= null_
895888-- (TRUE >= NULL)
896−(.>=) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
889+(.>=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
897890(.>=) = unsafeBinaryOp ">="
898891infix 4 .>=
899892
900893-- | >>> printSQL $ true .< null_
901894-- (TRUE < NULL)
902−(.<) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
895+(.<) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
903896(.<) = unsafeBinaryOp "<"
904897infix 4 .<
905898
906899-- | >>> printSQL $ true .<= null_
907900-- (TRUE <= NULL)
908−(.<=) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
901+(.<=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
909902(.<=) = unsafeBinaryOp "<="
910903infix 4 .<=
911904
912905-- | >>> printSQL $ true .> null_
913906-- (TRUE > NULL)
914−(.>) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
907+(.>) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
915908(.>) = unsafeBinaryOp ">"
916909infix 4 .>
917910
@@ -920,9 +913,9 @@ infix 4 .>
920913TRUE BETWEEN NULL AND FALSE
921914-}
922915between
923− :: Expression outer grp commons schemas params from (nullity ty)
924− -> ( Expression outer grp commons schemas params from (nullity ty)
925− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
916+ :: Expression outer grp commons schemas params from (null ty)
917+ -> ( Expression outer grp commons schemas params from (null ty)
918+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
926919 -> Condition outer grp commons schemas params from
927920between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
928921 <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -932,9 +925,9 @@ between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
932925TRUE NOT BETWEEN NULL AND FALSE
933926-}
934927notBetween
935− :: Expression outer grp commons schemas params from (nullity ty)
936− -> ( Expression outer grp commons schemas params from (nullity ty)
937− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
928+ :: Expression outer grp commons schemas params from (null ty)
929+ -> ( Expression outer grp commons schemas params from (null ty)
930+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
938931 -> Condition outer grp commons schemas params from
939932notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
940933 <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -944,9 +937,9 @@ notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
944937TRUE BETWEEN SYMMETRIC NULL AND FALSE
945938-}
946939betweenSymmetric
947− :: Expression outer grp commons schemas params from (nullity ty)
948− -> ( Expression outer grp commons schemas params from (nullity ty)
949− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
940+ :: Expression outer grp commons schemas params from (null ty)
941+ -> ( Expression outer grp commons schemas params from (null ty)
942+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
950943 -> Condition outer grp commons schemas params from
951944betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
952945 <+> "BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -956,9 +949,9 @@ betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
956949TRUE NOT BETWEEN SYMMETRIC NULL AND FALSE
957950-}
958951notBetweenSymmetric
959− :: Expression outer grp commons schemas params from (nullity ty)
960− -> ( Expression outer grp commons schemas params from (nullity ty)
961− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
952+ :: Expression outer grp commons schemas params from (null ty)
953+ -> ( Expression outer grp commons schemas params from (null ty)
954+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
962955 -> Condition outer grp commons schemas params from
963956notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
964957 <+> "NOT BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -967,98 +960,81 @@ notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
967960>>> printSQL $ true `isDistinctFrom` null_
968961(TRUE IS DISTINCT FROM NULL)
969962-}
970−isDistinctFrom :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
963+isDistinctFrom :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
971964isDistinctFrom = unsafeBinaryOp "IS DISTINCT FROM"
972965
973966{- | equal, treating null like an ordinary value
974967>>> printSQL $ true `isNotDistinctFrom` null_
975968(TRUE IS NOT DISTINCT FROM NULL)
976969-}
977−isNotDistinctFrom :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
970+isNotDistinctFrom :: Operator (null0 ty) (null1 ty) ('NotNull 'PGbool)
978971isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
979972
980973{- | is true
981974>>> printSQL $ true & isTrue
982−TRUE IS TRUE
975+(TRUE IS TRUE)
983976-}
984−isTrue
985− :: Expression outer grp commons schemas params from (nullity 'PGbool)
986− -> Condition outer grp commons schemas params from
987−isTrue b = UnsafeExpression $ renderSQL b <+> "IS TRUE"
977+isTrue :: null 'PGbool :--> 'NotNull 'PGbool
978+isTrue = unsafeUnaryOpR "IS TRUE"
988979
989980{- | is false or unknown
990981>>> printSQL $ true & isNotTrue
991−TRUE IS NOT TRUE
982+(TRUE IS NOT TRUE)
992983-}
993−isNotTrue
994− :: Expression outer grp commons schemas params from (nullity 'PGbool)
995− -> Condition outer grp commons schemas params from
996−isNotTrue b = UnsafeExpression $ renderSQL b <+> "IS NOT TRUE"
984+isNotTrue :: null 'PGbool :--> 'NotNull 'PGbool
985+isNotTrue = unsafeUnaryOpR "IS NOT TRUE"
997986
998987{- | is false
999988>>> printSQL $ true & isFalse
1000−TRUE IS FALSE
989+(TRUE IS FALSE)
1001990-}
1002−isFalse
1003− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1004− -> Condition outer grp commons schemas params from
1005−isFalse b = UnsafeExpression $ renderSQL b <+> "IS FALSE"
991+isFalse :: null 'PGbool :--> 'NotNull 'PGbool
992+isFalse = unsafeUnaryOpR "IS FALSE"
1006993
1007994{- | is true or unknown
1008995>>> printSQL $ true & isNotFalse
1009−TRUE IS NOT FALSE
996+(TRUE IS NOT FALSE)
1010997-}
1011−isNotFalse
1012− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1013− -> Condition outer grp commons schemas params from
1014−isNotFalse b = UnsafeExpression $ renderSQL b <+> "IS NOT FALSE"
998+isNotFalse :: null 'PGbool :--> 'NotNull 'PGbool
999+isNotFalse = unsafeUnaryOpR "IS NOT FALSE"
10151000
10161001{- | is unknown
10171002>>> printSQL $ true & isUnknown
1018−TRUE IS UNKNOWN
1003+(TRUE IS UNKNOWN)
10191004-}
1020−isUnknown
1021− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1022− -> Condition outer grp commons schemas params from
1023−isUnknown b = UnsafeExpression $ renderSQL b <+> "IS UNKNOWN"
1005+isUnknown :: null 'PGbool :--> 'NotNull 'PGbool
1006+isUnknown = unsafeUnaryOpR "IS UNKNOWN"
10241007
10251008{- | is true or false
10261009>>> printSQL $ true & isNotUnknown
1027−TRUE IS NOT UNKNOWN
1010+(TRUE IS NOT UNKNOWN)
10281011-}
1029−isNotUnknown
1030− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1031− -> Condition outer grp commons schemas params from
1032−isNotUnknown b = UnsafeExpression $ renderSQL b <+> "IS NOT UNKNOWN"
1012+isNotUnknown :: null 'PGbool :--> 'NotNull 'PGbool
1013+isNotUnknown = unsafeUnaryOpR "IS NOT UNKNOWN"
10331014
10341015-- | >>> printSQL currentDate
10351016-- CURRENT_DATE
1036−currentDate
1037− :: Expression outer grp commons schemas params from (nullity 'PGdate)
1017+currentDate :: Expr (null 'PGdate)
10381018currentDate = UnsafeExpression "CURRENT_DATE"
10391019
10401020-- | >>> printSQL currentTime
10411021-- CURRENT_TIME
1042−currentTime
1043− :: Expression outer grp commons schemas params from (nullity 'PGtimetz)
1022+currentTime :: Expr (null 'PGtimetz)
10441023currentTime = UnsafeExpression "CURRENT_TIME"
10451024
10461025-- | >>> printSQL currentTimestamp
10471026-- CURRENT_TIMESTAMP
1048−currentTimestamp
1049− :: Expression outer grp commons schemas params from (nullity 'PGtimestamptz)
1027+currentTimestamp :: Expr (null 'PGtimestamptz)
10501028currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
10511029
10521030-- | >>> printSQL localTime
10531031-- LOCALTIME
1054−localTime
1055− :: Expression outer grp commons schemas params from (nullity 'PGtime)
1032+localTime :: Expr (null 'PGtime)
10561033localTime = UnsafeExpression "LOCALTIME"
10571034
10581035-- | >>> printSQL localTimestamp
10591036-- LOCALTIMESTAMP
1060−localTimestamp
1061− :: Expression outer grp commons schemas params from (nullity 'PGtimestamp)
1037+localTimestamp :: Expr (null 'PGtimestamp)
10621038localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
10631039
10641040{-----------------------------------------
@@ -1078,56 +1054,47 @@ escape = \case
10781054 c -> [c]
10791055
10801056instance IsString
1081− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1057+ (Expression outer grp commons schemas params from (null 'PGtext)) where
10821058 fromString str = UnsafeExpression $
10831059 "E\'" <> fromString (escape =<< str) <> "\'"
10841060instance IsString
1085− (Expression outer grp commons schemas params from (nullity 'PGtsvector)) where
1061+ (Expression outer grp commons schemas params from (null 'PGtsvector)) where
10861062 fromString str = cast tsvector . UnsafeExpression $
10871063 "E\'" <> fromString (escape =<< str) <> "\'"
10881064instance IsString
1089− (Expression outer grp commons schemas params from (nullity 'PGtsquery)) where
1065+ (Expression outer grp commons schemas params from (null 'PGtsquery)) where
10901066 fromString str = cast tsquery . UnsafeExpression $
10911067 "E\'" <> fromString (escape =<< str) <> "\'"
10921068
10931069instance Semigroup
1094− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1070+ (Expression outer grp commons schemas params from (null 'PGtext)) where
10951071 (<>) = unsafeBinaryOp "||"
10961072instance Semigroup
1097− (Expression outer grp commons schemas params from (nullity 'PGtsvector)) where
1073+ (Expression outer grp commons schemas params from (null 'PGtsvector)) where
10981074 (<>) = unsafeBinaryOp "||"
10991075
11001076instance Monoid
1101− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1077+ (Expression outer grp commons schemas params from (null 'PGtext)) where
11021078 mempty = fromString ""
11031079 mappend = (<>)
11041080instance Monoid
1105− (Expression outer grp commons schemas params from (nullity 'PGtsvector)) where
1081+ (Expression outer grp commons schemas params from (null 'PGtsvector)) where
11061082 mempty = fromString ""
11071083 mappend = (<>)
11081084
11091085-- | >>> printSQL $ lower "ARRRGGG"
11101086-- lower(E'ARRRGGG')
1111−lower
1112− :: nullity 'PGtext
1113− -- ^ string to lower case
1114− :--> nullity 'PGtext
1087+lower :: null 'PGtext :--> null 'PGtext
11151088lower = unsafeFunction "lower"
11161089
11171090-- | >>> printSQL $ upper "eeee"
11181091-- upper(E'eeee')
1119−upper
1120− :: nullity 'PGtext
1121− -- ^ string to upper case
1122− :--> nullity 'PGtext
1092+upper :: null 'PGtext :--> null 'PGtext
11231093upper = unsafeFunction "upper"
11241094
11251095-- | >>> printSQL $ charLength "four"
11261096-- char_length(E'four')
1127−charLength
1128− :: nullity 'PGtext
1129− -- ^ string to measure
1130− :--> nullity 'PGint4
1097+charLength :: null 'PGtext :--> null 'PGint4
11311098charLength = unsafeFunction "char_length"
11321099
11331100-- | The `like` expression returns true if the @string@ matches
@@ -1139,7 +1106,7 @@ charLength = unsafeFunction "char_length"
11391106--
11401107-- >>> printSQL $ "abc" `like` "a%"
11411108-- (E'abc' LIKE E'a%')
1142−like :: Operator (nullity 'PGtext) (nullity 'PGtext) ('Null 'PGbool)
1109+like :: Operator (null 'PGtext) (null 'PGtext) ('Null 'PGbool)
11431110like = unsafeBinaryOp "LIKE"
11441111
11451112-- | The key word ILIKE can be used instead of LIKE to make the
@@ -1147,7 +1114,7 @@ like = unsafeBinaryOp "LIKE"
11471114--
11481115-- >>> printSQL $ "abc" `ilike` "a%"
11491116-- (E'abc' ILIKE E'a%')
1150−ilike :: Operator (nullity 'PGtext) (nullity 'PGtext) ('Null 'PGbool)
1117+ilike :: Operator (null 'PGtext) (null 'PGtext) ('Null 'PGbool)
11511118ilike = unsafeBinaryOp "ILIKE"
11521119
11531120{-----------------------------------------
@@ -1162,28 +1129,28 @@ Table 9.44: json and jsonb operators
11621129-- | Get JSON value (object field or array element) at a key.
11631130(.->)
11641131 :: (json `In` PGJsonType, key `In` PGJsonKey)
1165− => Operator (nullity json) (nullity key) ('Null json)
1132+ => Operator (null json) (null key) ('Null json)
11661133infixl 8 .->
11671134(.->) = unsafeBinaryOp "->"
11681135
11691136-- | Get JSON value (object field or array element) at a key, as text.
11701137(.->>)
11711138 :: (json `In` PGJsonType, key `In` PGJsonKey)
1172− => Operator (nullity json) (nullity key) ('Null 'PGtext)
1139+ => Operator (null json) (null key) ('Null 'PGtext)
11731140infixl 8 .->>
11741141(.->>) = unsafeBinaryOp "->>"
11751142
11761143-- | Get JSON value at a specified path.
11771144(.#>)
11781145 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1179− => Operator (nullity json) (nullity path) ('Null json)
1146+ => Operator (null json) (null path) ('Null json)
11801147infixl 8 .#>
11811148(.#>) = unsafeBinaryOp "#>"
11821149
11831150-- | Get JSON value at a specified path as text.
11841151(.#>>)
11851152 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1186− => Operator (nullity json) (nullity path) ('Null 'PGtext)
1153+ => Operator (null json) (null path) ('Null 'PGtext)
11871154infixl 8 .#>>
11881155(.#>>) = unsafeBinaryOp "#>>"
11891156
@@ -1192,40 +1159,40 @@ infixl 8 .#>>
11921159-- | Does the left JSON value contain the right JSON path/value entries at the
11931160-- top level?
11941161(.@>)
1195− :: Operator (nullity 'PGjsonb) (nullity 'PGjsonb) ('Null 'PGbool)
1162+ :: Operator (null 'PGjsonb) (null 'PGjsonb) ('Null 'PGbool)
11961163infixl 9 .@>
11971164(.@>) = unsafeBinaryOp "@>"
11981165
11991166-- | Are the left JSON path/value entries contained at the top level within the
12001167-- right JSON value?
1201−(.<@) :: Operator (nullity 'PGjsonb) (nullity 'PGjsonb) ('Null 'PGbool)
1168+(.<@) :: Operator (null 'PGjsonb) (null 'PGjsonb) ('Null 'PGbool)
12021169infixl 9 .<@
12031170(.<@) = unsafeBinaryOp "<@"
12041171
12051172-- | Does the string exist as a top-level key within the JSON value?
1206−(.?) :: Operator (nullity 'PGjsonb) (nullity 'PGtext) ('Null 'PGbool)
1173+(.?) :: Operator (null 'PGjsonb) (null 'PGtext) ('Null 'PGbool)
12071174infixl 9 .?
12081175(.?) = unsafeBinaryOp "?"
12091176
12101177-- | Do any of these array strings exist as top-level keys?
12111178(.?|) :: Operator
1212− (nullity 'PGjsonb)
1213− (nullity ('PGvararray ('NotNull 'PGtext)))
1179+ (null 'PGjsonb)
1180+ (null ('PGvararray ('NotNull 'PGtext)))
12141181 ('Null 'PGbool)
12151182infixl 9 .?|
12161183(.?|) = unsafeBinaryOp "?|"
12171184
12181185-- | Do all of these array strings exist as top-level keys?
12191186(.?&) :: Operator
1220− (nullity 'PGjsonb)
1221− (nullity ('PGvararray ('NotNull 'PGtext)))
1187+ (null 'PGjsonb)
1188+ (null ('PGvararray ('NotNull 'PGtext)))
12221189 ('Null 'PGbool)
12231190infixl 9 .?&
12241191(.?&) = unsafeBinaryOp "?&"
12251192
12261193-- | Concatenate two jsonb values into a new jsonb value.
12271194instance Semigroup
1228− (Expression outer grp commons schemas params from (nullity 'PGjsonb)) where
1195+ (Expression outer grp commons schemas params from (null 'PGjsonb)) where
12291196 (<>) = unsafeBinaryOp "||"
12301197
12311198-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1242,7 +1209,7 @@ instance Semigroup
12421209-- count from the end). Throws an error if top level container is not an array.
12431210(.-.)
12441211 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1245− => Operator (nullity 'PGjsonb) (nullity key) (nullity 'PGjsonb)
1212+ => Operator (null 'PGjsonb) (null key) (null 'PGjsonb)
12461213infixl 6 .-.
12471214(.-.) = unsafeBinaryOp "-"
12481215
@@ -1250,7 +1217,7 @@ infixl 6 .-.
12501217-- integers count from the end)
12511218(#-.)
12521219 :: PGTextArray "(#-.)" arrayty
1253− => Operator (nullity 'PGjsonb) (nullity arrayty)(nullity 'PGjsonb)
1220+ => Operator (null 'PGjsonb) (null arrayty)(null 'PGjsonb)
12541221infixl 6 #-.
12551222(#-.) = unsafeBinaryOp "#-"
12561223
@@ -1259,16 +1226,12 @@ Table 9.45: JSON creation functions
12591226-----------------------------------------}
12601227
12611228-- | Literal binary JSON
1262−jsonbLit
1263− :: JSON.ToJSON x
1264− => x -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1229+jsonbLit :: JSON.ToJSON x => x -> Expr (null 'PGjsonb)
12651230jsonbLit = cast jsonb . UnsafeExpression
12661231 . singleQuotedUtf8 . toStrict . JSON.encode
12671232
12681233-- | Literal JSON
1269−jsonLit
1270− :: JSON.ToJSON x
1271− => x -> Expression outer grp commons schemas params from (nullity 'PGjson)
1234+jsonLit :: JSON.ToJSON x => x -> Expr (null 'PGjson)
12721235jsonLit = cast json . UnsafeExpression
12731236 . singleQuotedUtf8 . toStrict . JSON.encode
12741237
@@ -1278,7 +1241,7 @@ jsonLit = cast json . UnsafeExpression
12781241-- otherwise, a scalar value is produced. For any scalar type other than a
12791242-- number, a Boolean, or a null value, the text representation will be used, in
12801243-- such a fashion that it is a valid json value.
1281−toJson :: nullity ty :--> nullity 'PGjson
1244+toJson :: null ty :--> null 'PGjson
12821245toJson = unsafeFunction "to_json"
12831246
12841247-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1287,18 +1250,18 @@ toJson = unsafeFunction "to_json"
12871250-- otherwise, a scalar value is produced. For any scalar type other than a
12881251-- number, a Boolean, or a null value, the text representation will be used, in
12891252-- such a fashion that it is a valid jsonb value.
1290−toJsonb :: nullity ty :--> nullity 'PGjsonb
1253+toJsonb :: null ty :--> null 'PGjsonb
12911254toJsonb = unsafeFunction "to_jsonb"
12921255
12931256-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
12941257-- becomes a JSON array of arrays.
12951258arrayToJson
12961259 :: PGArray "arrayToJson" arr
1297− => nullity arr :--> nullity 'PGjson
1260+ => null arr :--> null 'PGjson
12981261arrayToJson = unsafeFunction "array_to_json"
12991262
13001263-- | Returns the row as a JSON object.
1301−rowToJson :: nullity ('PGcomposite ty) :--> nullity 'PGjson
1264+rowToJson :: null ('PGcomposite ty) :--> null 'PGjson
13021265rowToJson = unsafeFunction "row_to_json"
13031266
13041267-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
@@ -1306,7 +1269,7 @@ rowToJson = unsafeFunction "row_to_json"
13061269jsonBuildArray
13071270 :: SListI elems
13081271 => NP (Expression outer grp commons schemas params from) elems
1309− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1272+ -> Expression outer grp commons schemas params from (null 'PGjson)
13101273jsonBuildArray = unsafeVariadicFunction "json_build_array"
13111274
13121275-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
@@ -1314,7 +1277,7 @@ jsonBuildArray = unsafeVariadicFunction "json_build_array"
13141277jsonbBuildArray
13151278 :: SListI elems
13161279 => NP (Expression outer grp commons schemas params from) elems
1317− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1280+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
13181281jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
13191282
13201283unsafeRowFunction
@@ -1335,7 +1298,7 @@ unsafeRowFunction =
13351298jsonBuildObject
13361299 :: SOP.SListI elems
13371300 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1338− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1301+ -> Expression outer grp commons schemas params from (null 'PGjson)
13391302jsonBuildObject
13401303 = unsafeFunction "json_build_object"
13411304 . UnsafeExpression
@@ -1348,7 +1311,7 @@ jsonBuildObject
13481311jsonbBuildObject
13491312 :: SOP.SListI elems
13501313 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1351− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1314+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
13521315jsonbBuildObject
13531316 = unsafeFunction "jsonb_build_object"
13541317 . UnsafeExpression
@@ -1361,7 +1324,7 @@ jsonbBuildObject
13611324-- array has exactly two elements, which are taken as a key/value pair.
13621325jsonObject
13631326 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1364− => nullity arr :--> nullity 'PGjson
1327+ => null arr :--> null 'PGjson
13651328jsonObject = unsafeFunction "json_object"
13661329
13671330-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1370,7 +1333,7 @@ jsonObject = unsafeFunction "json_object"
13701333-- array has exactly two elements, which are taken as a key/value pair.
13711334jsonbObject
13721335 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1373− => nullity arr :--> nullity 'PGjsonb
1336+ => null arr :--> null 'PGjsonb
13741337jsonbObject = unsafeFunction "jsonb_object"
13751338
13761339-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1378,9 +1341,9 @@ jsonbObject = unsafeFunction "jsonb_object"
13781341jsonZipObject
13791342 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
13801343 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1381− => Expression outer grp commons schemas params from (nullity keysArray)
1382− -> Expression outer grp commons schemas params from (nullity valuesArray)
1383− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1344+ => Expression outer grp commons schemas params from (null keysArray)
1345+ -> Expression outer grp commons schemas params from (null valuesArray)
1346+ -> Expression outer grp commons schemas params from (null 'PGjson)
13841347jsonZipObject ks vs =
13851348 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
13861349
@@ -1390,9 +1353,9 @@ jsonZipObject ks vs =
13901353jsonbZipObject
13911354 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
13921355 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1393− => Expression outer grp commons schemas params from (nullity keysArray)
1394− -> Expression outer grp commons schemas params from (nullity valuesArray)
1395− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1356+ => Expression outer grp commons schemas params from (null keysArray)
1357+ -> Expression outer grp commons schemas params from (null valuesArray)
1358+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
13961359jsonbZipObject ks vs =
13971360 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
13981361
@@ -1401,20 +1364,20 @@ Table 9.46: JSON processing functions
14011364-----------------------------------------}
14021365
14031366-- | Returns the number of elements in the outermost JSON array.
1404−jsonArrayLength :: nullity 'PGjson :--> nullity 'PGint4
1367+jsonArrayLength :: null 'PGjson :--> null 'PGint4
14051368jsonArrayLength = unsafeFunction "json_array_length"
14061369
14071370-- | Returns the number of elements in the outermost binary JSON array.
1408−jsonbArrayLength :: nullity 'PGjsonb :--> nullity 'PGint4
1371+jsonbArrayLength :: null 'PGjsonb :--> null 'PGint4
14091372jsonbArrayLength = unsafeFunction "jsonb_array_length"
14101373
14111374-- | Returns JSON value pointed to by the given path (equivalent to #>
14121375-- operator).
14131376jsonExtractPath
14141377 :: SListI elems
1415− => Expression outer grp commons schemas params from (nullity 'PGjson)
1378+ => Expression outer grp commons schemas params from (null 'PGjson)
14161379 -> NP (Expression outer grp commons schemas params from) elems
1417− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1380+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
14181381jsonExtractPath x xs =
14191382 unsafeVariadicFunction "json_extract_path" (x :* xs)
14201383
@@ -1422,9 +1385,9 @@ jsonExtractPath x xs =
14221385-- operator).
14231386jsonbExtractPath
14241387 :: SListI elems
1425− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1388+ => Expression outer grp commons schemas params from (null 'PGjsonb)
14261389 -> NP (Expression outer grp commons schemas params from) elems
1427− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1390+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
14281391jsonbExtractPath x xs =
14291392 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
14301393
@@ -1432,9 +1395,9 @@ jsonbExtractPath x xs =
14321395-- operator), as text.
14331396jsonExtractPathAsText
14341397 :: SListI elems
1435− => Expression outer grp commons schemas params from (nullity 'PGjson)
1398+ => Expression outer grp commons schemas params from (null 'PGjson)
14361399 -> NP (Expression outer grp commons schemas params from) elems
1437− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1400+ -> Expression outer grp commons schemas params from (null 'PGjson)
14381401jsonExtractPathAsText x xs =
14391402 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
14401403
@@ -1442,30 +1405,30 @@ jsonExtractPathAsText x xs =
14421405-- operator), as text.
14431406jsonbExtractPathAsText
14441407 :: SListI elems
1445− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1408+ => Expression outer grp commons schemas params from (null 'PGjsonb)
14461409 -> NP (Expression outer grp commons schemas params from) elems
1447− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1410+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
14481411jsonbExtractPathAsText x xs =
14491412 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
14501413
14511414-- | Returns the type of the outermost JSON value as a text string. Possible
14521415-- types are object, array, string, number, boolean, and null.
1453−jsonTypeof :: nullity 'PGjson :--> nullity 'PGtext
1416+jsonTypeof :: null 'PGjson :--> null 'PGtext
14541417jsonTypeof = unsafeFunction "json_typeof"
14551418
14561419-- | Returns the type of the outermost binary JSON value as a text string.
14571420-- Possible types are object, array, string, number, boolean, and null.
1458−jsonbTypeof :: nullity 'PGjsonb :--> nullity 'PGtext
1421+jsonbTypeof :: null 'PGjsonb :--> null 'PGtext
14591422jsonbTypeof = unsafeFunction "jsonb_typeof"
14601423
14611424-- | Returns its argument with all object fields that have null values omitted.
14621425-- Other null values are untouched.
1463−jsonStripNulls :: nullity 'PGjson :--> nullity 'PGjson
1426+jsonStripNulls :: null 'PGjson :--> null 'PGjson
14641427jsonStripNulls = unsafeFunction "json_strip_nulls"
14651428
14661429-- | Returns its argument with all object fields that have null values omitted.
14671430-- Other null values are untouched.
1468−jsonbStripNulls :: nullity 'PGjsonb :--> nullity 'PGjsonb
1431+jsonbStripNulls :: null 'PGjsonb :--> null 'PGjsonb
14691432jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
14701433
14711434-- | @ jsonbSet target path new_value create_missing @
@@ -1477,11 +1440,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
14771440-- arrays.
14781441jsonbSet
14791442 :: PGTextArray "jsonbSet" arr
1480− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1481− -> Expression outer grp commons schemas params from (nullity arr)
1482− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1483− -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1484− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1443+ => Expression outer grp commons schemas params from (null 'PGjsonb)
1444+ -> Expression outer grp commons schemas params from (null arr)
1445+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1446+ -> Maybe (Expression outer grp commons schemas params from (null 'PGbool))
1447+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
14851448jsonbSet tgt path val createMissing = case createMissing of
14861449 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
14871450 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1496,67 +1459,67 @@ jsonbSet tgt path val createMissing = case createMissing of
14961459-- in path count from the end of JSON arrays.
14971460jsonbInsert
14981461 :: PGTextArray "jsonbInsert" arr
1499− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1500− -> Expression outer grp commons schemas params from (nullity arr)
1501− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1502− -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1503− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1462+ => Expression outer grp commons schemas params from (null 'PGjsonb)
1463+ -> Expression outer grp commons schemas params from (null arr)
1464+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1465+ -> Maybe (Expression outer grp commons schemas params from (null 'PGbool))
1466+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
15041467jsonbInsert tgt path val insertAfter = case insertAfter of
15051468 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
15061469 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
15071470
15081471-- | Returns its argument as indented JSON text.
1509−jsonbPretty :: nullity 'PGjsonb :--> nullity 'PGtext
1472+jsonbPretty :: null 'PGjsonb :--> null 'PGtext
15101473jsonbPretty = unsafeFunction "jsonb_pretty"
15111474
1512−(@@) :: Operator (nullity 'PGtsvector) (nullity 'PGtsquery) ('Null 'PGbool)
1475+(@@) :: Operator (null 'PGtsvector) (null 'PGtsquery) ('Null 'PGbool)
15131476(@@) = unsafeBinaryOp "@@"
15141477
1515−(.&) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1478+(.&) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
15161479(.&) = unsafeBinaryOp "&&"
15171480
1518−(.|) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1481+(.|) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
15191482(.|) = unsafeBinaryOp "||"
15201483
1521−(.!) :: nullity 'PGtsquery :--> nullity 'PGtsquery
1522−(.!) = unsafeUnaryOp "!!"
1484+(.!) :: null 'PGtsquery :--> null 'PGtsquery
1485+(.!) = unsafeUnaryOpL "!!"
15231486
1524−(<->) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1487+(<->) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
15251488(<->) = unsafeBinaryOp "<->"
15261489
15271490arrayToTSvector
1528− :: nullity ('PGvararray ('NotNull 'PGtext))
1529− :--> nullity 'PGtsvector
1491+ :: null ('PGvararray ('NotNull 'PGtext))
1492+ :--> null 'PGtsvector
15301493arrayToTSvector = unsafeFunction "array_to_tsvector"
15311494
1532−tsvectorLength :: nullity 'PGtsvector :--> nullity 'PGint4
1495+tsvectorLength :: null 'PGtsvector :--> null 'PGint4
15331496tsvectorLength = unsafeFunction "length"
15341497
1535−numnode :: nullity 'PGtsquery :--> nullity 'PGint4
1498+numnode :: null 'PGtsquery :--> null 'PGint4
15361499numnode = unsafeFunction "numnode"
15371500
15381501plainToTSquery
1539− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1502+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
15401503plainToTSquery = unsafeFunctionHet "plainto_tsquery"
15411504
15421505phraseToTSquery
1543− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1506+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
15441507phraseToTSquery = unsafeFunctionHet "phraseto_tsquery"
15451508
15461509websearchToTSquery
1547− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1510+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
15481511websearchToTSquery = unsafeFunctionHet "websearch_to_tsquery"
15491512
1550−queryTree :: nullity 'PGtsquery :--> nullity 'PGtext
1513+queryTree :: null 'PGtsquery :--> null 'PGtext
15511514queryTree = unsafeFunction "query_tree"
15521515
15531516toTSquery
1554− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1517+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
15551518toTSquery = unsafeFunctionHet "to_tsquery"
15561519
15571520toTSvector
15581521 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1559− => FunctionHet '[nullity 'PGtext, nullity ty] (nullity 'PGtsquery)
1522+ => FunctionHet '[null 'PGtext, null ty] (null 'PGtsquery)
15601523toTSvector = unsafeFunctionHet "to_tsvector"
15611524
15621525{-----------------------------------------
@@ -1584,7 +1547,7 @@ class Aggregate expr1 expr2 aggr
15841547
15851548 -- | >>> :{
15861549 -- let
1587− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1550+ -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: null ty]] ('NotNull 'PGint8)
15881551 -- expression = count (All #col)
15891552 -- in printSQL expression
15901553 -- :}
@@ -1603,7 +1566,7 @@ class Aggregate expr1 expr2 aggr
16031566 -- sum(DISTINCT "col")
16041567 sum_
16051568 :: ty `In` PGNum
1606− => expr1 (nullity ty)
1569+ => expr1 (null ty)
16071570 -> aggr ('NotNull ty)
16081571
16091572 -- | input values, including nulls, concatenated into an array
@@ -1625,7 +1588,7 @@ class Aggregate expr1 expr2 aggr
16251588 the bitwise AND of all non-null input values, or null if none
16261589 >>> :{
16271590 let
1628− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] ('Null 'PGint4)
1591+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: null 'PGint4]] ('Null 'PGint4)
16291592 expression = bitAnd (Distinct #col)
16301593 in printSQL expression
16311594 :}
@@ -1633,7 +1596,7 @@ class Aggregate expr1 expr2 aggr
16331596 -}
16341597 bitAnd
16351598 :: int `In` PGIntegral
1636− => expr1 (nullity int)
1599+ => expr1 (null int)
16371600 -- ^ what to aggregate
16381601 -> aggr ('Null int)
16391602
@@ -1642,7 +1605,7 @@ class Aggregate expr1 expr2 aggr
16421605
16431606 >>> :{
16441607 let
1645− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] ('Null 'PGint4)
1608+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: null 'PGint4]] ('Null 'PGint4)
16461609 expression = bitOr (All #col)
16471610 in printSQL expression
16481611 :}
@@ -1650,7 +1613,7 @@ class Aggregate expr1 expr2 aggr
16501613 -}
16511614 bitOr
16521615 :: int `In` PGIntegral
1653− => expr1 (nullity int)
1616+ => expr1 (null int)
16541617 -- ^ what to aggregate
16551618 -> aggr ('Null int)
16561619
@@ -1659,14 +1622,14 @@ class Aggregate expr1 expr2 aggr
16591622
16601623 >>> :{
16611624 let
1662− winFun :: WindowFunction '[] 'Ungrouped commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1625+ winFun :: WindowFunction '[] 'Ungrouped commons schemas params '[tab ::: '["col" ::: null 'PGbool]] ('Null 'PGbool)
16631626 winFun = boolAnd #col
16641627 in printSQL winFun
16651628 :}
16661629 bool_and("col")
16671630 -}
16681631 boolAnd
1669− :: expr1 (nullity 'PGbool)
1632+ :: expr1 (null 'PGbool)
16701633 -- ^ what to aggregate
16711634 -> aggr ('Null 'PGbool)
16721635
@@ -1675,14 +1638,14 @@ class Aggregate expr1 expr2 aggr
16751638
16761639 >>> :{
16771640 let
1678− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1641+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: null 'PGbool]] ('Null 'PGbool)
16791642 expression = boolOr (All #col)
16801643 in printSQL expression
16811644 :}
16821645 bool_or(ALL "col")
16831646 -}
16841647 boolOr
1685− :: expr1(nullity 'PGbool)
1648+ :: expr1(null 'PGbool)
16861649 -- ^ what to aggregate
16871650 -> aggr ('Null 'PGbool)
16881651
@@ -1691,32 +1654,32 @@ class Aggregate expr1 expr2 aggr
16911654
16921655 >>> :{
16931656 let
1694− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1657+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: null 'PGbool]] ('Null 'PGbool)
16951658 expression = every (Distinct #col)
16961659 in printSQL expression
16971660 :}
16981661 every(DISTINCT "col")
16991662 -}
17001663 every
1701− :: expr1 (nullity 'PGbool)
1664+ :: expr1 (null 'PGbool)
17021665 -- ^ what to aggregate
17031666 -> aggr ('Null 'PGbool)
17041667
17051668 {- |maximum value of expression across all input values-}
17061669 max_
1707− :: expr1 (nullity ty)
1670+ :: expr1 (null ty)
17081671 -- ^ what to maximize
17091672 -> aggr ('Null ty)
17101673
17111674 -- | minimum value of expression across all input values
17121675 min_
1713− :: expr1 (nullity ty)
1676+ :: expr1 (null ty)
17141677 -- ^ what to minimize
17151678 -> aggr ('Null ty)
17161679
17171680 -- | the average (arithmetic mean) of all input values
17181681 avg
1719− :: expr1 (nullity ty)
1682+ :: expr1 (null ty)
17201683 -- ^ what to average
17211684 -> aggr ('Null (PGAvg ty))
17221685
@@ -1730,7 +1693,7 @@ class Aggregate expr1 expr2 aggr
17301693 corr(ALL "y", "x")
17311694 -}
17321695 corr
1733− :: expr2 (nullity 'PGfloat8)
1696+ :: expr2 (null 'PGfloat8)
17341697 -> aggr ('Null 'PGfloat8)
17351698
17361699 {- | population covariance
@@ -1743,7 +1706,7 @@ class Aggregate expr1 expr2 aggr
17431706 covar_pop(ALL "y", "x")
17441707 -}
17451708 covarPop
1746− :: expr2 (nullity 'PGfloat8)
1709+ :: expr2 (null 'PGfloat8)
17471710 -> aggr ('Null 'PGfloat8)
17481711
17491712 {- | sample covariance
@@ -1756,7 +1719,7 @@ class Aggregate expr1 expr2 aggr
17561719 covar_samp("y", "x")
17571720 -}
17581721 covarSamp
1759− :: expr2 (nullity 'PGfloat8)
1722+ :: expr2 (null 'PGfloat8)
17601723 -> aggr ('Null 'PGfloat8)
17611724
17621725 {- | average of the independent variable (sum(X)/N)
@@ -1769,7 +1732,7 @@ class Aggregate expr1 expr2 aggr
17691732 regr_avgx(ALL "y", "x")
17701733 -}
17711734 regrAvgX
1772− :: expr2 (nullity 'PGfloat8)
1735+ :: expr2 (null 'PGfloat8)
17731736 -> aggr ('Null 'PGfloat8)
17741737
17751738 {- | average of the dependent variable (sum(Y)/N)
@@ -1782,7 +1745,7 @@ class Aggregate expr1 expr2 aggr
17821745 regr_avgy("y", "x")
17831746 -}
17841747 regrAvgY
1785− :: expr2 (nullity 'PGfloat8)
1748+ :: expr2 (null 'PGfloat8)
17861749 -> aggr ('Null 'PGfloat8)
17871750
17881751 {- | number of input rows in which both expressions are nonnull
@@ -1795,7 +1758,7 @@ class Aggregate expr1 expr2 aggr
17951758 regr_count("y", "x")
17961759 -}
17971760 regrCount
1798− :: expr2 (nullity 'PGfloat8)
1761+ :: expr2 (null 'PGfloat8)
17991762 -> aggr ('Null 'PGint8)
18001763
18011764 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
@@ -1808,68 +1771,68 @@ class Aggregate expr1 expr2 aggr
18081771 regr_intercept(ALL "y", "x")
18091772 -}
18101773 regrIntercept
1811− :: expr2 (nullity 'PGfloat8)
1774+ :: expr2 (null 'PGfloat8)
18121775 -> aggr ('Null 'PGfloat8)
18131776
18141777 -- | @regr_r2(Y, X)@, square of the correlation coefficient
18151778 regrR2
1816− :: expr2 (nullity 'PGfloat8)
1779+ :: expr2 (null 'PGfloat8)
18171780 -> aggr ('Null 'PGfloat8)
18181781
18191782 -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
18201783 -- determined by the (X, Y) pairs
18211784 regrSlope
1822− :: expr2 (nullity 'PGfloat8)
1785+ :: expr2 (null 'PGfloat8)
18231786 -> aggr ('Null 'PGfloat8)
18241787
18251788 -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
18261789 -- (“sum of squares” of the independent variable)
18271790 regrSxx
1828− :: expr2 (nullity 'PGfloat8)
1791+ :: expr2 (null 'PGfloat8)
18291792 -> aggr ('Null 'PGfloat8)
18301793
18311794 -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
18321795 -- (“sum of products” of independent times dependent variable)
18331796 regrSxy
1834− :: expr2 (nullity 'PGfloat8)
1797+ :: expr2 (null 'PGfloat8)
18351798 -> aggr ('Null 'PGfloat8)
18361799
18371800 -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
18381801 -- (“sum of squares” of the dependent variable)
18391802 regrSyy
1840− :: expr2 (nullity 'PGfloat8)
1803+ :: expr2 (null 'PGfloat8)
18411804 -> aggr ('Null 'PGfloat8)
18421805
18431806 -- | historical alias for `stddevSamp`
18441807 stddev
1845− :: expr1 (nullity ty)
1808+ :: expr1 (null ty)
18461809 -> aggr ('Null (PGAvg ty))
18471810
18481811 -- | population standard deviation of the input values
18491812 stddevPop
1850− :: expr1 (nullity ty)
1813+ :: expr1 (null ty)
18511814 -> aggr ('Null (PGAvg ty))
18521815
18531816 -- | sample standard deviation of the input values
18541817 stddevSamp
1855− :: expr1 (nullity ty)
1818+ :: expr1 (null ty)
18561819 -> aggr ('Null (PGAvg ty))
18571820
18581821 -- | historical alias for `varSamp`
18591822 variance
1860− :: expr1 (nullity ty)
1823+ :: expr1 (null ty)
18611824 -> aggr ('Null (PGAvg ty))
18621825
18631826 -- | population variance of the input values
18641827 -- (square of the population standard deviation)
18651828 varPop
1866− :: expr1 (nullity ty)
1829+ :: expr1 (null ty)
18671830 -> aggr ('Null (PGAvg ty))
18681831
18691832 -- | sample variance of the input values
18701833 -- (square of the sample standard deviation)
18711834 varSamp
1872− :: expr1 (nullity ty)
1835+ :: expr1 (null ty)
18731836 -> aggr ('Null (PGAvg ty))
18741837
18751838{- |
@@ -2015,7 +1978,7 @@ instance RenderSQL (TypeExpression schemas ty) where
20151978typedef
20161979 :: (Has sch schemas schema, Has td schema ('Typedef ty))
20171980 => QualifiedAlias sch td
2018− -> TypeExpression schemas (nullity ty)
1981+ -> TypeExpression schemas (null ty)
20191982typedef = UnsafeTypeExpression . renderSQL
20201983
20211984-- | The composite type corresponding to a `Table` definition can be expressed
@@ -2023,7 +1986,7 @@ typedef = UnsafeTypeExpression . renderSQL
20231986typetable
20241987 :: (Has sch schemas schema, Has tab schema ('Table table))
20251988 => QualifiedAlias sch tab
2026− -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
1989+ -> TypeExpression schemas (null ('PGcomposite (TableToRow table)))
20271990typetable = UnsafeTypeExpression . renderSQL
20281991
20291992-- | The composite type corresponding to a `View` definition can be expressed
@@ -2031,101 +1994,101 @@ typetable = UnsafeTypeExpression . renderSQL
20311994typeview
20321995 :: (Has sch schemas schema, Has vw schema ('View view))
20331996 => QualifiedAlias sch vw
2034− -> TypeExpression schemas (nullity ('PGcomposite view))
1997+ -> TypeExpression schemas (null ('PGcomposite view))
20351998typeview = UnsafeTypeExpression . renderSQL
20361999
20372000-- | logical Boolean (true/false)
2038−bool :: TypeExpression schemas (nullity 'PGbool)
2001+bool :: TypeExpression schemas (null 'PGbool)
20392002bool = UnsafeTypeExpression "bool"
20402003-- | signed two-byte integer
2041−int2, smallint :: TypeExpression schemas (nullity 'PGint2)
2004+int2, smallint :: TypeExpression schemas (null 'PGint2)
20422005int2 = UnsafeTypeExpression "int2"
20432006smallint = UnsafeTypeExpression "smallint"
20442007-- | signed four-byte integer
2045−int4, int, integer :: TypeExpression schemas (nullity 'PGint4)
2008+int4, int, integer :: TypeExpression schemas (null 'PGint4)
20462009int4 = UnsafeTypeExpression "int4"
20472010int = UnsafeTypeExpression "int"
20482011integer = UnsafeTypeExpression "integer"
20492012-- | signed eight-byte integer
2050−int8, bigint :: TypeExpression schemas (nullity 'PGint8)
2013+int8, bigint :: TypeExpression schemas (null 'PGint8)
20512014int8 = UnsafeTypeExpression "int8"
20522015bigint = UnsafeTypeExpression "bigint"
20532016-- | arbitrary precision numeric type
2054−numeric :: TypeExpression schemas (nullity 'PGnumeric)
2017+numeric :: TypeExpression schemas (null 'PGnumeric)
20552018numeric = UnsafeTypeExpression "numeric"
20562019-- | single precision floating-point number (4 bytes)
2057−float4, real :: TypeExpression schemas (nullity 'PGfloat4)
2020+float4, real :: TypeExpression schemas (null 'PGfloat4)
20582021float4 = UnsafeTypeExpression "float4"
20592022real = UnsafeTypeExpression "real"
20602023-- | double precision floating-point number (8 bytes)
2061−float8, doublePrecision :: TypeExpression schemas (nullity 'PGfloat8)
2024+float8, doublePrecision :: TypeExpression schemas (null 'PGfloat8)
20622025float8 = UnsafeTypeExpression "float8"
20632026doublePrecision = UnsafeTypeExpression "double precision"
20642027-- | currency amount
2065−money :: TypeExpression schema (nullity 'PGmoney)
2028+money :: TypeExpression schema (null 'PGmoney)
20662029money = UnsafeTypeExpression "money"
20672030-- | variable-length character string
2068−text :: TypeExpression schemas (nullity 'PGtext)
2031+text :: TypeExpression schemas (null 'PGtext)
20692032text = UnsafeTypeExpression "text"
20702033-- | fixed-length character string
20712034char, character
2072− :: forall n schemas nullity. (KnownNat n, 1 <= n)
2073− => TypeExpression schemas (nullity ('PGchar n))
2035+ :: forall n schemas null. (KnownNat n, 1 <= n)
2036+ => TypeExpression schemas (null ('PGchar n))
20742037char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
20752038character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
20762039-- | variable-length character string
20772040varchar, characterVarying
2078− :: forall n schemas nullity. (KnownNat n, 1 <= n)
2079− => TypeExpression schemas (nullity ('PGvarchar n))
2041+ :: forall n schemas null. (KnownNat n, 1 <= n)
2042+ => TypeExpression schemas (null ('PGvarchar n))
20802043varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
20812044characterVarying = UnsafeTypeExpression $
20822045 "character varying(" <> renderNat @n <> ")"
20832046-- | binary data ("byte array")
2084−bytea :: TypeExpression schemas (nullity 'PGbytea)
2047+bytea :: TypeExpression schemas (null 'PGbytea)
20852048bytea = UnsafeTypeExpression "bytea"
20862049-- | date and time (no time zone)
2087−timestamp :: TypeExpression schemas (nullity 'PGtimestamp)
2050+timestamp :: TypeExpression schemas (null 'PGtimestamp)
20882051timestamp = UnsafeTypeExpression "timestamp"
20892052-- | date and time, including time zone
2090−timestampWithTimeZone :: TypeExpression schemas (nullity 'PGtimestamptz)
2053+timestampWithTimeZone :: TypeExpression schemas (null 'PGtimestamptz)
20912054timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
20922055-- | calendar date (year, month, day)
2093−date :: TypeExpression schemas (nullity 'PGdate)
2056+date :: TypeExpression schemas (null 'PGdate)
20942057date = UnsafeTypeExpression "date"
20952058-- | time of day (no time zone)
2096−time :: TypeExpression schemas (nullity 'PGtime)
2059+time :: TypeExpression schemas (null 'PGtime)
20972060time = UnsafeTypeExpression "time"
20982061-- | time of day, including time zone
2099−timeWithTimeZone :: TypeExpression schemas (nullity 'PGtimetz)
2062+timeWithTimeZone :: TypeExpression schemas (null 'PGtimetz)
21002063timeWithTimeZone = UnsafeTypeExpression "time with time zone"
21012064-- | time span
2102−interval :: TypeExpression schemas (nullity 'PGinterval)
2065+interval :: TypeExpression schemas (null 'PGinterval)
21032066interval = UnsafeTypeExpression "interval"
21042067-- | universally unique identifier
2105−uuid :: TypeExpression schemas (nullity 'PGuuid)
2068+uuid :: TypeExpression schemas (null 'PGuuid)
21062069uuid = UnsafeTypeExpression "uuid"
21072070-- | IPv4 or IPv6 host address
2108−inet :: TypeExpression schemas (nullity 'PGinet)
2071+inet :: TypeExpression schemas (null 'PGinet)
21092072inet = UnsafeTypeExpression "inet"
21102073-- | textual JSON data
2111−json :: TypeExpression schemas (nullity 'PGjson)
2074+json :: TypeExpression schemas (null 'PGjson)
21122075json = UnsafeTypeExpression "json"
21132076-- | binary JSON data, decomposed
2114−jsonb :: TypeExpression schemas (nullity 'PGjsonb)
2077+jsonb :: TypeExpression schemas (null 'PGjsonb)
21152078jsonb = UnsafeTypeExpression "jsonb"
21162079-- | variable length array
21172080vararray
21182081 :: TypeExpression schemas pg
2119− -> TypeExpression schemas (nullity ('PGvararray pg))
2082+ -> TypeExpression schemas (null ('PGvararray pg))
21202083vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
21212084-- | fixed length array
21222085--
21232086-- >>> renderSQL (fixarray @'[2] json)
21242087-- "json[2]"
21252088fixarray
2126− :: forall dims schemas nullity pg. SOP.All KnownNat dims
2089+ :: forall dims schemas null pg. SOP.All KnownNat dims
21272090 => TypeExpression schemas pg
2128− -> TypeExpression schemas (nullity ('PGfixarray dims pg))
2091+ -> TypeExpression schemas (null ('PGfixarray dims pg))
21292092fixarray ty = UnsafeTypeExpression $
21302093 renderSQL ty <> renderDims @dims
21312094 where
@@ -2138,45 +2101,45 @@ fixarray ty = UnsafeTypeExpression $
21382101 $ hcmap (SOP.Proxy @KnownNat)
21392102 (K . fromString . show . natVal)
21402103 (hpure SOP.Proxy :: NP SOP.Proxy ns)
2141−tsvector :: TypeExpression schemas (nullity 'PGtsvector)
2104+tsvector :: TypeExpression schemas (null 'PGtsvector)
21422105tsvector = UnsafeTypeExpression "tsvector"
2143−tsquery :: TypeExpression schemas (nullity 'PGtsquery)
2106+tsquery :: TypeExpression schemas (null 'PGtsquery)
21442107tsquery = UnsafeTypeExpression "tsquery"
21452108
21462109-- | `pgtype` is a demoted version of a `PGType`
21472110class PGTyped schemas (ty :: NullityType) where
21482111 pgtype :: TypeExpression schemas ty
2149−instance PGTyped schemas (nullity 'PGbool) where pgtype = bool
2150−instance PGTyped schemas (nullity 'PGint2) where pgtype = int2
2151−instance PGTyped schemas (nullity 'PGint4) where pgtype = int4
2152−instance PGTyped schemas (nullity 'PGint8) where pgtype = int8
2153−instance PGTyped schemas (nullity 'PGnumeric) where pgtype = numeric
2154−instance PGTyped schemas (nullity 'PGfloat4) where pgtype = float4
2155−instance PGTyped schemas (nullity 'PGfloat8) where pgtype = float8
2156−instance PGTyped schemas (nullity 'PGmoney) where pgtype = money
2157−instance PGTyped schemas (nullity 'PGtext) where pgtype = text
2112+instance PGTyped schemas (null 'PGbool) where pgtype = bool
2113+instance PGTyped schemas (null 'PGint2) where pgtype = int2
2114+instance PGTyped schemas (null 'PGint4) where pgtype = int4
2115+instance PGTyped schemas (null 'PGint8) where pgtype = int8
2116+instance PGTyped schemas (null 'PGnumeric) where pgtype = numeric
2117+instance PGTyped schemas (null 'PGfloat4) where pgtype = float4
2118+instance PGTyped schemas (null 'PGfloat8) where pgtype = float8
2119+instance PGTyped schemas (null 'PGmoney) where pgtype = money
2120+instance PGTyped schemas (null 'PGtext) where pgtype = text
21582121instance (KnownNat n, 1 <= n)
2159− => PGTyped schemas (nullity ('PGchar n)) where pgtype = char @n
2122+ => PGTyped schemas (null ('PGchar n)) where pgtype = char @n
21602123instance (KnownNat n, 1 <= n)
2161− => PGTyped schemas (nullity ('PGvarchar n)) where pgtype = varchar @n
2162−instance PGTyped schemas (nullity 'PGbytea) where pgtype = bytea
2163−instance PGTyped schemas (nullity 'PGtimestamp) where pgtype = timestamp
2164−instance PGTyped schemas (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
2165−instance PGTyped schemas (nullity 'PGdate) where pgtype = date
2166−instance PGTyped schemas (nullity 'PGtime) where pgtype = time
2167−instance PGTyped schemas (nullity 'PGtimetz) where pgtype = timeWithTimeZone
2168−instance PGTyped schemas (nullity 'PGinterval) where pgtype = interval
2169−instance PGTyped schemas (nullity 'PGuuid) where pgtype = uuid
2170−instance PGTyped schemas (nullity 'PGjson) where pgtype = json
2171−instance PGTyped schemas (nullity 'PGjsonb) where pgtype = jsonb
2124+ => PGTyped schemas (null ('PGvarchar n)) where pgtype = varchar @n
2125+instance PGTyped schemas (null 'PGbytea) where pgtype = bytea
2126+instance PGTyped schemas (null 'PGtimestamp) where pgtype = timestamp
2127+instance PGTyped schemas (null 'PGtimestamptz) where pgtype = timestampWithTimeZone
2128+instance PGTyped schemas (null 'PGdate) where pgtype = date
2129+instance PGTyped schemas (null 'PGtime) where pgtype = time
2130+instance PGTyped schemas (null 'PGtimetz) where pgtype = timeWithTimeZone
2131+instance PGTyped schemas (null 'PGinterval) where pgtype = interval
2132+instance PGTyped schemas (null 'PGuuid) where pgtype = uuid
2133+instance PGTyped schemas (null 'PGjson) where pgtype = json
2134+instance PGTyped schemas (null 'PGjsonb) where pgtype = jsonb
21722135instance PGTyped schemas ty
2173− => PGTyped schemas (nullity ('PGvararray ty)) where
2136+ => PGTyped schemas (null ('PGvararray ty)) where
21742137 pgtype = vararray (pgtype @schemas @ty)
21752138instance (SOP.All KnownNat dims, PGTyped schemas ty)
2176− => PGTyped schemas (nullity ('PGfixarray dims ty)) where
2139+ => PGTyped schemas (null ('PGfixarray dims ty)) where
21772140 pgtype = fixarray @dims (pgtype @schemas @ty)
2178−instance PGTyped schemas (nullity 'PGtsvector) where pgtype = tsvector
2179−instance PGTyped schemas (nullity 'PGtsquery) where pgtype = tsquery
2141+instance PGTyped schemas (null 'PGtsvector) where pgtype = tsvector
2142+instance PGTyped schemas (null 'PGtsquery) where pgtype = tsquery
21802143
21812144{-----------------------------------------
21822145Sorting
@@ -2417,7 +2380,7 @@ lastValue = unsafeWindowFunction1 "last_value"
24172380row of the window frame (counting from 1); null if no such row
24182381-}
24192382nthValue
2420− :: Expression outer grp commons schemas params from (nullity ty)
2383+ :: Expression outer grp commons schemas params from (null ty)
24212384 -- ^ value
24222385 -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
24232386 -- ^ nth
@@ -2428,114 +2391,78 @@ nthValue value nth = UnsafeWindowFunction $ "nth_value"
24282391{-|
24292392Create date from year, month and day fields
24302393
2431−>>> printSQL (makeDate 1984 7 3)
2394+>>> printSQL (makeDate (1984 :* 7 *: 3))
24322395make_date(1984, 7, 3)
24332396-}
2434−makeDate
2435− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2436− -- ^ year
2437− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2438− -- ^ month
2439− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2440− -- ^ day
2441− -> Expression outer grp commons schemas params from (nullity 'PGdate)
2442−makeDate y m d = UnsafeExpression $ "make_date" <>
2443− parenthesized (renderCommaSeparated renderSQL (y :* m :* d :* Nil))
2397+makeDate :: FunctionHet
2398+ '[ null 'PGint4, null 'PGint4, null 'PGint4 ]
2399+ ( null 'PGdate )
2400+makeDate = unsafeFunctionHet "make_date"
24442401
24452402{-|
24462403Create time from hour, minute and seconds fields
24472404
2448−>>> printSQL (makeTime 8 15 23.5)
2405+>>> printSQL (makeTime (8 :* 15 *: 23.5))
24492406make_time(8, 15, 23.5)
24502407-}
2451−makeTime
2452− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2453− -- ^ hour
2454− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2455− -- ^ min
2456− -> Expression outer grp commons schemas params from (nullity 'PGfloat8)
2457− -- ^ sec
2458− -> Expression outer grp commons schemas params from (nullity 'PGtime)
2459−makeTime h m s = UnsafeExpression $ "make_time" <>
2460− parenthesized (renderCommaSeparated renderSQL (h :* m :* s :* Nil))
2408+makeTime :: FunctionHet
2409+ '[ null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2410+ ( null 'PGtime )
2411+makeTime = unsafeFunctionHet "make_time"
24612412
24622413{-|
24632414Create timestamp from year, month, day, hour, minute and seconds fields
24642415
2465−>>> printSQL (makeTimestamp 2013 7 15 8 15 23.5)
2416+>>> printSQL (makeTimestamp (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
24662417make_timestamp(2013, 7, 15, 8, 15, 23.5)
24672418-}
2468−makeTimestamp
2469− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2470− -- ^ year
2471− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2472− -- ^ month
2473− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2474− -- ^ day
2475− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2476− -- ^ hour
2477− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2478− -- ^ min
2479− -> Expression outer grp commons schemas params from (nullity 'PGfloat8)
2480− -- ^ sec
2481− -> Expression outer grp commons schemas params from (nullity 'PGtimestamp)
2482−makeTimestamp y mon d h m s =
2483− UnsafeExpression $ "make_timestamp" <> parenthesized
2484− (renderCommaSeparated renderSQL (y :* mon :* d :* h :* m :* s :* Nil))
2419+makeTimestamp :: FunctionHet
2420+ '[ null 'PGint4, null 'PGint4, null 'PGint4
2421+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2422+ ( null 'PGtimestamp )
2423+makeTimestamp = unsafeFunctionHet "make_timestamp"
24852424
24862425{-|
24872426Create timestamp with time zone from
24882427year, month, day, hour, minute and seconds fields;
24892428the current time zone is used
24902429
2491−>>> printSQL (makeTimestamptz 2013 7 15 8 15 23.5)
2430+>>> printSQL (makeTimestamptz (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
24922431make_timestamptz(2013, 7, 15, 8, 15, 23.5)
24932432-}
2494−makeTimestamptz
2495− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2496− -- ^ year
2497− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2498− -- ^ month
2499− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2500− -- ^ day
2501− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2502− -- ^ hour
2503− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2504− -- ^ min
2505− -> Expression outer grp commons schemas params from (nullity 'PGfloat8)
2506− -- ^ sec
2507− -> Expression outer grp commons schemas params from (nullity 'PGtimestamptz)
2508−makeTimestamptz y mon d h m s =
2509− UnsafeExpression $ "make_timestamptz" <> parenthesized
2510− (renderCommaSeparated renderSQL (y :* mon :* d :* h :* m :* s :* Nil))
2433+makeTimestamptz :: FunctionHet
2434+ '[ null 'PGint4, null 'PGint4, null 'PGint4
2435+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2436+ ( null 'PGtimestamptz )
2437+makeTimestamptz = unsafeFunctionHet "make_timestamptz"
25112438
25122439{-|
25132440Affine space operations on time types.
25142441-}
25152442class TimeOp time diff | time -> diff where
25162443 {-|
2517− >>> printSQL (makeDate 1984 7 3 !+ 365)
2444+ >>> printSQL (makeDate (1984 :* 7 *: 3) !+ 365)
25182445 (make_date(1984, 7, 3) + 365)
25192446 -}
2520− (!+) :: Operator (nullity time) (nullity diff) (nullity time)
2447+ (!+) :: Operator (null time) (null diff) (null time)
25212448 (!+) = unsafeBinaryOp "+"
25222449 {-|
2523− >>> printSQL (365 +! makeDate 1984 7 3)
2450+ >>> printSQL (365 +! makeDate (1984 :* 7 *: 3))
25242451 (365 + make_date(1984, 7, 3))
25252452 -}
2526− (+!) :: Operator (nullity diff) (nullity time) (nullity time)
2453+ (+!) :: Operator (null diff) (null time) (null time)
25272454 (+!) = unsafeBinaryOp "+"
25282455 {-|
2529− >>> printSQL (makeDate 1984 7 3 !- 365)
2456+ >>> printSQL (makeDate (1984 :* 7 *: 3) !- 365)
25302457 (make_date(1984, 7, 3) - 365)
25312458 -}
2532− (!-) :: Operator (nullity time) (nullity diff) (nullity time)
2459+ (!-) :: Operator (null time) (null diff) (null time)
25332460 (!-) = unsafeBinaryOp "-"
25342461 {-|
2535− >>> printSQL (makeDate 1984 7 3 !-! currentDate)
2462+ >>> printSQL (makeDate (1984 :* 7 *: 3) !-! currentDate)
25362463 (make_date(1984, 7, 3) - CURRENT_DATE)
25372464 -}
2538− (!-!) :: Operator (nullity time) (nullity time) (nullity diff)
2465+ (!-!) :: Operator (null time) (null time) (null diff)
25392466 (!-!) = unsafeBinaryOp "-"
25402467instance TimeOp 'PGtimestamp 'PGinterval
25412468instance TimeOp 'PGtimestamptz 'PGinterval
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4
@@ -91,6 +91,7 @@ module Squeal.PostgreSQL.Schema
9191 , Elem
9292 , In
9393 , Length
94+ , (*:)
9495 -- * Type Classifications
9596 , HasOid (..)
9697 , PGNum
@@ -786,3 +787,6 @@ instance (forall t0 t1. RenderSQL (p t0 t1))
786787-- | A `single` step.
787788single :: p x0 x1 -> AlignedList p x0 x1
788789single step = step :>> Done
790+
791+(*:) :: f x -> f y -> NP f '[x,y]
792+x *: y = x :* y :* Nil