on dev help sign in
more functions
7d44983Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+314−387
@@ -55,7 +55,7 @@ module Squeal.PostgreSQL.Expression
55 , field
55 , field
56 -- ** Functions
56 -- ** Functions
57 , unsafeBinaryOp
57 , unsafeBinaryOp
58− , unsafeUnaryOp
58+ , unsafeUnaryOpL
59 , unsafeFunction
59 , unsafeFunction
60 , unsafeVariadicFunction
60 , unsafeVariadicFunction
61 , atan2_
61 , atan2_
@@ -287,6 +287,10 @@ newtype Expression
287instance RenderSQL (Expression outer grp commons schemas params from ty) where
287instance RenderSQL (Expression outer grp commons schemas params from ty) where
288 renderSQL = renderExpression
288 renderSQL = renderExpression
289
289
290+type Expr x
291+ = forall outer grp commons schemas params from
292+ . Expression outer grp commons schemas params from x
293+
290type Operator x1 x2 y
294type Operator x1 x2 y
291 = forall outer grp commons schemas params from
295 = forall outer grp commons schemas params from
292 . Expression outer grp commons schemas params from x1
296 . Expression outer grp commons schemas params from x1
@@ -303,6 +307,16 @@ type FunctionHet xs y
303 . NP (Expression outer grp commons schemas params from) xs
307 . NP (Expression outer grp commons schemas params from) xs
304 -> Expression outer grp commons schemas params from y
308 -> Expression outer grp commons schemas params from y
305
309
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+
306{- | A `HasParameter` constraint is used to indicate a value that is
320{- | A `HasParameter` constraint is used to indicate a value that is
307supplied externally to a SQL statement.
321supplied externally to a SQL statement.
308`Squeal.PostgreSQL.PQ.manipulateParams`,
322`Squeal.PostgreSQL.PQ.manipulateParams`,
@@ -443,16 +457,14 @@ instance
443--
457--
444-- >>> printSQL null_
458-- >>> printSQL null_
445-- NULL
459-- NULL
446−null_ :: Expression outer grp commons schemas params from ('Null ty)
460+null_ :: Expr ('Null ty)
447null_ = UnsafeExpression "NULL"
461null_ = UnsafeExpression "NULL"
448
462
449-- | analagous to `Just`
463-- | analagous to `Just`
450--
464--
451-- >>> printSQL $ notNull true
465-- >>> printSQL $ notNull true
452-- TRUE
466-- TRUE
453−notNull
467+notNull :: 'NotNull ty :--> 'Null ty
454− :: Expression outer grp commons schemas params from ('NotNull ty)
455− -> Expression outer grp commons schemas params from ('Null ty)
456notNull = UnsafeExpression . renderSQL
468notNull = UnsafeExpression . renderSQL
457
469
458-- | return the leftmost value which is not NULL
470-- | return the leftmost value which is not NULL
@@ -533,26 +545,25 @@ nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
533array
545array
534 :: [Expression outer grp commons schemas params from ty]
546 :: [Expression outer grp commons schemas params from ty]
535 -- ^ array elements
547 -- ^ array elements
536− -> Expression outer grp commons schemas params from (nullity ('PGvararray ty))
548+ -> Expression outer grp commons schemas params from (null ('PGvararray ty))
537array xs = UnsafeExpression $
549array xs = UnsafeExpression $
538 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
550 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
539
551
540-- | >>> printSQL $ cardinality (array [null_, false, true])
552-- | >>> printSQL $ cardinality (array [null_, false, true])
541-- cardinality(ARRAY[NULL, FALSE, TRUE])
553-- cardinality(ARRAY[NULL, FALSE, TRUE])
542−cardinality :: nullity ('PGvararray ty) :--> nullity 'PGint8
554+cardinality :: null ('PGvararray ty) :--> null 'PGint8
543cardinality = unsafeFunction "cardinality"
555cardinality = unsafeFunction "cardinality"
544
556
545-- | >>> printSQL $ array [null_, false, true] & index 2
557-- | >>> printSQL $ array [null_, false, true] & index 2
546-- (ARRAY[NULL, FALSE, TRUE])[2]
558-- (ARRAY[NULL, FALSE, TRUE])[2]
547index
559index
548− :: Word64 -- ^ index
560+ :: Word64 -- ^ index
549− -> nullity ('PGvararray ty) -- ^ array
550− :--> NullifyType ty
561+ -> null ('PGvararray ty) :--> NullifyType ty
551index n expr = UnsafeExpression $
562index n expr = UnsafeExpression $
552 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
563 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
553
564
554instance (KnownSymbol label, label `In` labels) => IsPGlabel label
565instance (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
556 label = UnsafeExpression $ renderSQL (PGlabel @label)
567 label = UnsafeExpression $ renderSQL (PGlabel @label)
557
568
558-- | A row constructor is an expression that builds a row value
569-- | A row constructor is an expression that builds a row value
@@ -571,7 +582,7 @@ row
571 :: SListI row
582 :: SListI row
572 => NP (Aliased (Expression outer grp commons schemas params from)) row
583 => NP (Aliased (Expression outer grp commons schemas params from)) row
573 -- ^ zero or more expressions for the row field values
584 -- ^ 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))
575row exprs = UnsafeExpression $ "ROW" <> parenthesized
586row exprs = UnsafeExpression $ "ROW" <> parenthesized
576 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
587 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
577
588
@@ -598,51 +609,38 @@ field td fld expr = UnsafeExpression $
598 <> "." <> renderSQL fld
609 <> "." <> renderSQL fld
599
610
600instance Semigroup
611instance 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
602 (<>) = unsafeBinaryOp "||"
613 (<>) = unsafeBinaryOp "||"
603
614
604instance Monoid
615instance 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
606 mempty = array []
617 mempty = array []
607 mappend = (<>)
618 mappend = (<>)
608
619
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)
610-- >>> printSQL expr
621-- >>> printSQL expr
611−-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
622+-- GREATEST(($1 :: timestamp with time zone), CURRENT_TIMESTAMP)
612−greatest
623+greatest :: FunctionHom ty ty
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("
624+greatest = unsafeFunctionHom "GREATEST"
619− <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
620
625
621−-- | >>> printSQL $ least currentTimestamp [null_]
626+-- | >>> printSQL $ least [null_] currentTimestamp
622−-- LEAST(CURRENT_TIMESTAMP, NULL)
627+-- LEAST(NULL, CURRENT_TIMESTAMP)
623−least
628+least :: FunctionHom ty ty
624− :: Expression outer grp commons schemas params from (nullty)
629+least = unsafeFunctionHom "LEAST"
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)) <> ")"
631
630
632-- | >>> printSQL $ unsafeBinaryOp "OR" true false
631-- | >>> printSQL $ unsafeBinaryOp "OR" true false
633-- (TRUE OR FALSE)
632-- (TRUE OR FALSE)
634−unsafeBinaryOp
635− :: ByteString
636− -- ^ operator
637− -> Operator ty0 ty1 ty2
633+unsafeBinaryOp :: ByteString {- ^ operator -} -> Operator ty0 ty1 ty2
638unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
634unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
639 renderSQL x <+> op <+> renderSQL y
635 renderSQL x <+> op <+> renderSQL y
640
636
641−-- | >>> printSQL $ unsafeUnaryOp "NOT" true
637+-- | >>> printSQL $ unsafeUnaryOpL "NOT" true
642-- (NOT TRUE)
638-- (NOT TRUE)
643−unsafeUnaryOp :: ByteString {- ^ operator -} -> x :--> y
639+unsafeUnaryOpL :: ByteString {- ^ operator -} -> x :--> y
644−unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
640+unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
645− op <+> renderSQL x
641+
642+unsafeUnaryOpR :: ByteString {- ^ operator -} -> x :--> y
643+unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
646
644
647-- | >>> printSQL $ unsafeFunction "f" true
645-- | >>> printSQL $ unsafeFunction "f" true
648-- f(TRUE)
646-- f(TRUE)
@@ -668,7 +666,7 @@ unsafeVariadicFunction fun x = UnsafeExpression $
668 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
666 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
669
667
670instance ty `In` PGNum
668instance 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
672 (+) = unsafeBinaryOp "+"
670 (+) = unsafeBinaryOp "+"
673 (-) = unsafeBinaryOp "-"
671 (-) = unsafeBinaryOp "-"
674 (*) = unsafeBinaryOp "*"
672 (*) = unsafeBinaryOp "*"
@@ -680,7 +678,7 @@ instance ty `In` PGNum
680 . show
678 . show
681
679
682instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
680instance (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
684 (/) = unsafeBinaryOp "/"
682 (/) = unsafeBinaryOp "/"
685 fromRational
683 fromRational
686 = UnsafeExpression
684 = UnsafeExpression
@@ -690,7 +688,7 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
690 . fromRat @Double
688 . fromRat @Double
691
689
692instance (ty `In` PGNum, ty `In` PGFloating) => Floating
690instance (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
694 pi = UnsafeExpression "pi()"
692 pi = UnsafeExpression "pi()"
695 exp = unsafeFunction "exp"
693 exp = unsafeFunction "exp"
696 log = unsafeFunction "ln"
694 log = unsafeFunction "ln"
@@ -713,20 +711,15 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
713
711
714-- | >>> :{
712-- | >>> :{
715-- let
713-- let
716−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
714+-- expression :: Expr (null 'PGfloat4)
717−-- expression = atan2_ pi 2
715+-- expression = atan2_ (pi *: 2)
718-- in printSQL expression
716-- in printSQL expression
719-- :}
717-- :}
720-- atan2(pi(), 2)
718-- atan2(pi(), 2)
721atan2_
719atan2_
722 :: float `In` PGFloating
720 :: float `In` PGFloating
723− => Expression outer grp commons schemas params from (nullity float)
721+ => FunctionHet '[ null float, null float] (null float)
724− -- ^ numerator
722+atan2_ = unsafeFunctionHet "atan2"
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 <> ")"
730
723
731-- When a `cast` is applied to an `Expression` of a known type, it
724-- When a `cast` is applied to an `Expression` of a known type, it
732-- represents a run-time type conversion. The cast will succeed only if a
725-- represents a run-time type conversion. The cast will succeed only if a
@@ -747,58 +740,58 @@ cast ty x = UnsafeExpression $ parenthesized $
747--
740--
748-- >>> :{
741-- >>> :{
749-- let
742-- let
750−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
743+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
751-- expression = 5 `quot_` 2
744-- expression = 5 `quot_` 2
752-- in printSQL expression
745-- in printSQL expression
753-- :}
746-- :}
754-- (5 / 2)
747-- (5 / 2)
755quot_
748quot_
756 :: int `In` PGIntegral
749 :: int `In` PGIntegral
757− => Operator (nullity int) (nullity int) (nullity int)
750+ => Operator (null int) (null int) (null int)
758quot_ = unsafeBinaryOp "/"
751quot_ = unsafeBinaryOp "/"
759
752
760-- | remainder upon integer division
753-- | remainder upon integer division
761--
754--
762-- >>> :{
755-- >>> :{
763-- let
756-- let
764−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
757+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
765-- expression = 5 `rem_` 2
758-- expression = 5 `rem_` 2
766-- in printSQL expression
759-- in printSQL expression
767-- :}
760-- :}
768-- (5 % 2)
761-- (5 % 2)
769rem_
762rem_
770 :: int `In` PGIntegral
763 :: int `In` PGIntegral
771− => Operator (nullity int) (nullity int) (nullity int)
764+ => Operator (null int) (null int) (null int)
772rem_ = unsafeBinaryOp "%"
765rem_ = unsafeBinaryOp "%"
773
766
774-- | >>> :{
767-- | >>> :{
775-- let
768-- let
776−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
769+-- expression :: Expression outer grp commons schemas params from (null 'PGfloat4)
777-- expression = trunc pi
770-- expression = trunc pi
778-- in printSQL expression
771-- in printSQL expression
779-- :}
772-- :}
780-- trunc(pi())
773-- trunc(pi())
781−trunc :: frac `In` PGFloating => nullity frac :--> nullity frac
774+trunc :: frac `In` PGFloating => null frac :--> null frac
782trunc = unsafeFunction "trunc"
775trunc = unsafeFunction "trunc"
783
776
784-- | >>> :{
777-- | >>> :{
785-- let
778-- let
786−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
779+-- expression :: Expression outer grp commons schemas params from (null 'PGfloat4)
787-- expression = round_ pi
780-- expression = round_ pi
788-- in printSQL expression
781-- in printSQL expression
789-- :}
782-- :}
790-- round(pi())
783-- round(pi())
791−round_ :: frac `In` PGFloating => nullity frac :--> nullity frac
784+round_ :: frac `In` PGFloating => null frac :--> null frac
792round_ = unsafeFunction "round"
785round_ = unsafeFunction "round"
793
786
794-- | >>> :{
787-- | >>> :{
795-- let
788-- let
796−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
789+-- expression :: Expression outer grp commons schemas params from (null 'PGfloat4)
797-- expression = ceiling_ pi
790-- expression = ceiling_ pi
798-- in printSQL expression
791-- in printSQL expression
799-- :}
792-- :}
800-- ceiling(pi())
793-- ceiling(pi())
801−ceiling_ :: frac `In` PGFloating => nullity frac :--> nullity frac
794+ceiling_ :: frac `In` PGFloating => null frac :--> null frac
802ceiling_ = unsafeFunction "ceiling"
795ceiling_ = unsafeFunction "ceiling"
803
796
804-- | A `Condition` is an `Expression`, which can evaluate
797-- | A `Condition` is an `Expression`, which can evaluate
@@ -809,34 +802,34 @@ type Condition outer grp commons schemas params from =
809
802
810-- | >>> printSQL true
803-- | >>> printSQL true
811-- TRUE
804-- TRUE
812−true :: Expression outer grp commons schemas params from (nullity 'PGbool)
805+true :: Expr (null 'PGbool)
813true = UnsafeExpression "TRUE"
806true = UnsafeExpression "TRUE"
814
807
815-- | >>> printSQL false
808-- | >>> printSQL false
816-- FALSE
809-- FALSE
817−false :: Expression outer grp commons schemas params from (nullity 'PGbool)
810+false :: Expr (null 'PGbool)
818false = UnsafeExpression "FALSE"
811false = UnsafeExpression "FALSE"
819
812
820-- | >>> printSQL $ not_ true
813-- | >>> printSQL $ not_ true
821-- (NOT TRUE)
814-- (NOT TRUE)
822−not_ :: nullity 'PGbool :--> nullity 'PGbool
815+not_ :: null 'PGbool :--> null 'PGbool
823−not_ = unsafeUnaryOp "NOT"
816+not_ = unsafeUnaryOpL "NOT"
824
817
825-- | >>> printSQL $ true .&& false
818-- | >>> printSQL $ true .&& false
826-- (TRUE AND FALSE)
819-- (TRUE AND FALSE)
827−(.&&) :: Operator (nullity 'PGbool) (nullity 'PGbool) (nullity 'PGbool)
820+(.&&) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
828infixr 3 .&&
821infixr 3 .&&
829(.&&) = unsafeBinaryOp "AND"
822(.&&) = unsafeBinaryOp "AND"
830
823
831-- | >>> printSQL $ true .|| false
824-- | >>> printSQL $ true .|| false
832-- (TRUE OR FALSE)
825-- (TRUE OR FALSE)
833−(.||) :: Operator (nullity 'PGbool) (nullity 'PGbool) (nullity 'PGbool)
826+(.||) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
834infixr 2 .||
827infixr 2 .||
835(.||) = unsafeBinaryOp "OR"
828(.||) = unsafeBinaryOp "OR"
836
829
837-- | >>> :{
830-- | >>> :{
838-- let
831-- let
839−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
832+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
840-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
833-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
841-- in printSQL expression
834-- in printSQL expression
842-- :}
835-- :}
@@ -864,7 +857,7 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
864
857
865-- | >>> :{
858-- | >>> :{
866-- let
859-- let
867−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
860+-- expression :: Expression outer grp commons schemas params from (null 'PGint2)
868-- expression = ifThenElse true 1 0
861-- expression = ifThenElse true 1 0
869-- in printSQL expression
862-- in printSQL expression
870-- :}
863-- :}
@@ -881,37 +874,37 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
881--
874--
882-- >>> printSQL $ true .== null_
875-- >>> printSQL $ true .== null_
883-- (TRUE = NULL)
876-- (TRUE = NULL)
884−(.==) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
877+(.==) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
885(.==) = unsafeBinaryOp "="
878(.==) = unsafeBinaryOp "="
886infix 4 .==
879infix 4 .==
887
880
888-- | >>> printSQL $ true ./= null_
881-- | >>> printSQL $ true ./= null_
889-- (TRUE <> NULL)
882-- (TRUE <> NULL)
890−(./=) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
883+(./=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
891(./=) = unsafeBinaryOp "<>"
884(./=) = unsafeBinaryOp "<>"
892infix 4 ./=
885infix 4 ./=
893
886
894-- | >>> printSQL $ true .>= null_
887-- | >>> printSQL $ true .>= null_
895-- (TRUE >= NULL)
888-- (TRUE >= NULL)
896−(.>=) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
889+(.>=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
897(.>=) = unsafeBinaryOp ">="
890(.>=) = unsafeBinaryOp ">="
898infix 4 .>=
891infix 4 .>=
899
892
900-- | >>> printSQL $ true .< null_
893-- | >>> printSQL $ true .< null_
901-- (TRUE < NULL)
894-- (TRUE < NULL)
902−(.<) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
895+(.<) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
903(.<) = unsafeBinaryOp "<"
896(.<) = unsafeBinaryOp "<"
904infix 4 .<
897infix 4 .<
905
898
906-- | >>> printSQL $ true .<= null_
899-- | >>> printSQL $ true .<= null_
907-- (TRUE <= NULL)
900-- (TRUE <= NULL)
908−(.<=) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
901+(.<=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
909(.<=) = unsafeBinaryOp "<="
902(.<=) = unsafeBinaryOp "<="
910infix 4 .<=
903infix 4 .<=
911
904
912-- | >>> printSQL $ true .> null_
905-- | >>> printSQL $ true .> null_
913-- (TRUE > NULL)
906-- (TRUE > NULL)
914−(.>) :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
907+(.>) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
915(.>) = unsafeBinaryOp ">"
908(.>) = unsafeBinaryOp ">"
916infix 4 .>
909infix 4 .>
917
910
@@ -920,9 +913,9 @@ infix 4 .>
920TRUE BETWEEN NULL AND FALSE
913TRUE BETWEEN NULL AND FALSE
921-}
914-}
922between
915between
923− :: Expression outer grp commons schemas params from (nullity ty)
916+ :: Expression outer grp commons schemas params from (null ty)
924− -> ( Expression outer grp commons schemas params from (nullity ty)
917+ -> ( Expression outer grp commons schemas params from (null ty)
925− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
918+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
926 -> Condition outer grp commons schemas params from
919 -> Condition outer grp commons schemas params from
927between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
920between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
928 <+> renderSQL x <+> "AND" <+> renderSQL y
921 <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -932,9 +925,9 @@ between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
932TRUE NOT BETWEEN NULL AND FALSE
925TRUE NOT BETWEEN NULL AND FALSE
933-}
926-}
934notBetween
927notBetween
935− :: Expression outer grp commons schemas params from (nullity ty)
928+ :: Expression outer grp commons schemas params from (null ty)
936− -> ( Expression outer grp commons schemas params from (nullity ty)
929+ -> ( Expression outer grp commons schemas params from (null ty)
937− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
930+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
938 -> Condition outer grp commons schemas params from
931 -> Condition outer grp commons schemas params from
939notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
932notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
940 <+> renderSQL x <+> "AND" <+> renderSQL y
933 <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -944,9 +937,9 @@ notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
944TRUE BETWEEN SYMMETRIC NULL AND FALSE
937TRUE BETWEEN SYMMETRIC NULL AND FALSE
945-}
938-}
946betweenSymmetric
939betweenSymmetric
947− :: Expression outer grp commons schemas params from (nullity ty)
940+ :: Expression outer grp commons schemas params from (null ty)
948− -> ( Expression outer grp commons schemas params from (nullity ty)
941+ -> ( Expression outer grp commons schemas params from (null ty)
949− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
942+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
950 -> Condition outer grp commons schemas params from
943 -> Condition outer grp commons schemas params from
951betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
944betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
952 <+> "BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
945 <+> "BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -956,9 +949,9 @@ betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
956TRUE NOT BETWEEN SYMMETRIC NULL AND FALSE
949TRUE NOT BETWEEN SYMMETRIC NULL AND FALSE
957-}
950-}
958notBetweenSymmetric
951notBetweenSymmetric
959− :: Expression outer grp commons schemas params from (nullity ty)
952+ :: Expression outer grp commons schemas params from (null ty)
960− -> ( Expression outer grp commons schemas params from (nullity ty)
953+ -> ( Expression outer grp commons schemas params from (null ty)
961− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
954+ , Expression outer grp commons schemas params from (null ty) ) -- ^ bounds
962 -> Condition outer grp commons schemas params from
955 -> Condition outer grp commons schemas params from
963notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
956notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
964 <+> "NOT BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
957 <+> "NOT BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
@@ -967,98 +960,81 @@ notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
967>>> printSQL $ true `isDistinctFrom` null_
960>>> printSQL $ true `isDistinctFrom` null_
968(TRUE IS DISTINCT FROM NULL)
961(TRUE IS DISTINCT FROM NULL)
969-}
962-}
970−isDistinctFrom :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
963+isDistinctFrom :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
971isDistinctFrom = unsafeBinaryOp "IS DISTINCT FROM"
964isDistinctFrom = unsafeBinaryOp "IS DISTINCT FROM"
972
965
973{- | equal, treating null like an ordinary value
966{- | equal, treating null like an ordinary value
974>>> printSQL $ true `isNotDistinctFrom` null_
967>>> printSQL $ true `isNotDistinctFrom` null_
975(TRUE IS NOT DISTINCT FROM NULL)
968(TRUE IS NOT DISTINCT FROM NULL)
976-}
969-}
977−isNotDistinctFrom :: Operator (nullity0 ty) (nullity1 ty) ('Null 'PGbool)
970+isNotDistinctFrom :: Operator (null0 ty) (null1 ty) ('NotNull 'PGbool)
978isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
971isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
979
972
980{- | is true
973{- | is true
981>>> printSQL $ true & isTrue
974>>> printSQL $ true & isTrue
982−TRUE IS TRUE
975+(TRUE IS TRUE)
983-}
976-}
984−isTrue
977+isTrue :: null 'PGbool :--> 'NotNull 'PGbool
985− :: Expression outer grp commons schemas params from (nullity 'PGbool)
978+isTrue = unsafeUnaryOpR "IS TRUE"
986− -> Condition outer grp commons schemas params from
987−isTrue b = UnsafeExpression $ renderSQL b <+> "IS TRUE"
988
979
989{- | is false or unknown
980{- | is false or unknown
990>>> printSQL $ true & isNotTrue
981>>> printSQL $ true & isNotTrue
991−TRUE IS NOT TRUE
982+(TRUE IS NOT TRUE)
992-}
983-}
993−isNotTrue
984+isNotTrue :: null 'PGbool :--> 'NotNull 'PGbool
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"
985+isNotTrue = unsafeUnaryOpR "IS NOT TRUE"
997
986
998{- | is false
987{- | is false
999>>> printSQL $ true & isFalse
988>>> printSQL $ true & isFalse
1000−TRUE IS FALSE
989+(TRUE IS FALSE)
1001-}
990-}
1002−isFalse
991+isFalse :: null 'PGbool :--> 'NotNull 'PGbool
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"
992+isFalse = unsafeUnaryOpR "IS FALSE"
1006
993
1007{- | is true or unknown
994{- | is true or unknown
1008>>> printSQL $ true & isNotFalse
995>>> printSQL $ true & isNotFalse
1009−TRUE IS NOT FALSE
996+(TRUE IS NOT FALSE)
1010-}
997-}
1011−isNotFalse
998+isNotFalse :: null 'PGbool :--> 'NotNull 'PGbool
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"
999+isNotFalse = unsafeUnaryOpR "IS NOT FALSE"
1015
1000
1016{- | is unknown
1001{- | is unknown
1017>>> printSQL $ true & isUnknown
1002>>> printSQL $ true & isUnknown
1018−TRUE IS UNKNOWN
1003+(TRUE IS UNKNOWN)
1019-}
1004-}
1020−isUnknown
1005+isUnknown :: null 'PGbool :--> 'NotNull 'PGbool
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"
1006+isUnknown = unsafeUnaryOpR "IS UNKNOWN"
1024
1007
1025{- | is true or false
1008{- | is true or false
1026>>> printSQL $ true & isNotUnknown
1009>>> printSQL $ true & isNotUnknown
1027−TRUE IS NOT UNKNOWN
1010+(TRUE IS NOT UNKNOWN)
1028-}
1011-}
1029−isNotUnknown
1012+isNotUnknown :: null 'PGbool :--> 'NotNull 'PGbool
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"
1013+isNotUnknown = unsafeUnaryOpR "IS NOT UNKNOWN"
1033
1014
1034-- | >>> printSQL currentDate
1015-- | >>> printSQL currentDate
1035-- CURRENT_DATE
1016-- CURRENT_DATE
1036−currentDate
1017+currentDate :: Expr (null 'PGdate)
1037− :: Expression outer grp commons schemas params from (nullity 'PGdate)
1038currentDate = UnsafeExpression "CURRENT_DATE"
1018currentDate = UnsafeExpression "CURRENT_DATE"
1039
1019
1040-- | >>> printSQL currentTime
1020-- | >>> printSQL currentTime
1041-- CURRENT_TIME
1021-- CURRENT_TIME
1042−currentTime
1022+currentTime :: Expr (null 'PGtimetz)
1043− :: Expression outer grp commons schemas params from (nullity 'PGtimetz)
1044currentTime = UnsafeExpression "CURRENT_TIME"
1023currentTime = UnsafeExpression "CURRENT_TIME"
1045
1024
1046-- | >>> printSQL currentTimestamp
1025-- | >>> printSQL currentTimestamp
1047-- CURRENT_TIMESTAMP
1026-- CURRENT_TIMESTAMP
1048−currentTimestamp
1027+currentTimestamp :: Expr (null 'PGtimestamptz)
1049− :: Expression outer grp commons schemas params from (nullity 'PGtimestamptz)
1050currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
1028currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
1051
1029
1052-- | >>> printSQL localTime
1030-- | >>> printSQL localTime
1053-- LOCALTIME
1031-- LOCALTIME
1054−localTime
1032+localTime :: Expr (null 'PGtime)
1055− :: Expression outer grp commons schemas params from (nullity 'PGtime)
1056localTime = UnsafeExpression "LOCALTIME"
1033localTime = UnsafeExpression "LOCALTIME"
1057
1034
1058-- | >>> printSQL localTimestamp
1035-- | >>> printSQL localTimestamp
1059-- LOCALTIMESTAMP
1036-- LOCALTIMESTAMP
1060−localTimestamp
1037+localTimestamp :: Expr (null 'PGtimestamp)
1061− :: Expression outer grp commons schemas params from (nullity 'PGtimestamp)
1062localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
1038localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
1063
1039
1064{-----------------------------------------
1040{-----------------------------------------
@@ -1078,56 +1054,47 @@ escape = \case
1078 c -> [c]
1054 c -> [c]
1079
1055
1080instance IsString
1056instance IsString
1081− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1057+ (Expression outer grp commons schemas params from (null 'PGtext)) where
1082 fromString str = UnsafeExpression $
1058 fromString str = UnsafeExpression $
1083 "E\'" <> fromString (escape =<< str) <> "\'"
1059 "E\'" <> fromString (escape =<< str) <> "\'"
1084instance IsString
1060instance IsString
1085− (Expression outer grp commons schemas params from (nullity 'PGtsvector)) where
1061+ (Expression outer grp commons schemas params from (null 'PGtsvector)) where
1086 fromString str = cast tsvector . UnsafeExpression $
1062 fromString str = cast tsvector . UnsafeExpression $
1087 "E\'" <> fromString (escape =<< str) <> "\'"
1063 "E\'" <> fromString (escape =<< str) <> "\'"
1088instance IsString
1064instance IsString
1089− (Expression outer grp commons schemas params from (nullity 'PGtsquery)) where
1065+ (Expression outer grp commons schemas params from (null 'PGtsquery)) where
1090 fromString str = cast tsquery . UnsafeExpression $
1066 fromString str = cast tsquery . UnsafeExpression $
1091 "E\'" <> fromString (escape =<< str) <> "\'"
1067 "E\'" <> fromString (escape =<< str) <> "\'"
1092
1068
1093instance Semigroup
1069instance Semigroup
1094− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1070+ (Expression outer grp commons schemas params from (null 'PGtext)) where
1095 (<>) = unsafeBinaryOp "||"
1071 (<>) = unsafeBinaryOp "||"
1096instance Semigroup
1072instance Semigroup
1097− (Expression outer grp commons schemas params from (nullity 'PGtsvector)) where
1073+ (Expression outer grp commons schemas params from (null 'PGtsvector)) where
1098 (<>) = unsafeBinaryOp "||"
1074 (<>) = unsafeBinaryOp "||"
1099
1075
1100instance Monoid
1076instance Monoid
1101− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1077+ (Expression outer grp commons schemas params from (null 'PGtext)) where
1102 mempty = fromString ""
1078 mempty = fromString ""
1103 mappend = (<>)
1079 mappend = (<>)
1104instance Monoid
1080instance Monoid
1105− (Expression outer grp commons schemas params from (nullity 'PGtsvector)) where
1081+ (Expression outer grp commons schemas params from (null 'PGtsvector)) where
1106 mempty = fromString ""
1082 mempty = fromString ""
1107 mappend = (<>)
1083 mappend = (<>)
1108
1084
1109-- | >>> printSQL $ lower "ARRRGGG"
1085-- | >>> printSQL $ lower "ARRRGGG"
1110-- lower(E'ARRRGGG')
1086-- lower(E'ARRRGGG')
1111−lower
1087+lower :: null 'PGtext :--> null 'PGtext
1112− :: nullity 'PGtext
1113− -- ^ string to lower case
1114− :--> nullity 'PGtext
1115lower = unsafeFunction "lower"
1088lower = unsafeFunction "lower"
1116
1089
1117-- | >>> printSQL $ upper "eeee"
1090-- | >>> printSQL $ upper "eeee"
1118-- upper(E'eeee')
1091-- upper(E'eeee')
1119−upper
1092+upper :: null 'PGtext :--> null 'PGtext
1120− :: nullity 'PGtext
1121− -- ^ string to upper case
1122− :--> nullity 'PGtext
1123upper = unsafeFunction "upper"
1093upper = unsafeFunction "upper"
1124
1094
1125-- | >>> printSQL $ charLength "four"
1095-- | >>> printSQL $ charLength "four"
1126-- char_length(E'four')
1096-- char_length(E'four')
1127−charLength
1097+charLength :: null 'PGtext :--> null 'PGint4
1128− :: nullity 'PGtext
1129− -- ^ string to measure
1130− :--> nullity 'PGint4
1131charLength = unsafeFunction "char_length"
1098charLength = unsafeFunction "char_length"
1132
1099
1133-- | The `like` expression returns true if the @string@ matches
1100-- | The `like` expression returns true if the @string@ matches
@@ -1139,7 +1106,7 @@ charLength = unsafeFunction "char_length"
1139--
1106--
1140-- >>> printSQL $ "abc" `like` "a%"
1107-- >>> printSQL $ "abc" `like` "a%"
1141-- (E'abc' LIKE E'a%')
1108-- (E'abc' LIKE E'a%')
1142−like :: Operator (nullity 'PGtext) (nullity 'PGtext) ('Null 'PGbool)
1109+like :: Operator (null 'PGtext) (null 'PGtext) ('Null 'PGbool)
1143like = unsafeBinaryOp "LIKE"
1110like = unsafeBinaryOp "LIKE"
1144
1111
1145-- | The key word ILIKE can be used instead of LIKE to make the
1112-- | The key word ILIKE can be used instead of LIKE to make the
@@ -1147,7 +1114,7 @@ like = unsafeBinaryOp "LIKE"
1147--
1114--
1148-- >>> printSQL $ "abc" `ilike` "a%"
1115-- >>> printSQL $ "abc" `ilike` "a%"
1149-- (E'abc' ILIKE E'a%')
1116-- (E'abc' ILIKE E'a%')
1150−ilike :: Operator (nullity 'PGtext) (nullity 'PGtext) ('Null 'PGbool)
1117+ilike :: Operator (null 'PGtext) (null 'PGtext) ('Null 'PGbool)
1151ilike = unsafeBinaryOp "ILIKE"
1118ilike = unsafeBinaryOp "ILIKE"
1152
1119
1153{-----------------------------------------
1120{-----------------------------------------
@@ -1162,28 +1129,28 @@ Table 9.44: json and jsonb operators
1162-- | Get JSON value (object field or array element) at a key.
1129-- | Get JSON value (object field or array element) at a key.
1163(.->)
1130(.->)
1164 :: (json `In` PGJsonType, key `In` PGJsonKey)
1131 :: (json `In` PGJsonType, key `In` PGJsonKey)
1165− => Operator (nullity json) (nullity key) ('Null json)
1132+ => Operator (null json) (null key) ('Null json)
1166infixl 8 .->
1133infixl 8 .->
1167(.->) = unsafeBinaryOp "->"
1134(.->) = unsafeBinaryOp "->"
1168
1135
1169-- | Get JSON value (object field or array element) at a key, as text.
1136-- | Get JSON value (object field or array element) at a key, as text.
1170(.->>)
1137(.->>)
1171 :: (json `In` PGJsonType, key `In` PGJsonKey)
1138 :: (json `In` PGJsonType, key `In` PGJsonKey)
1172− => Operator (nullity json) (nullity key) ('Null 'PGtext)
1139+ => Operator (null json) (null key) ('Null 'PGtext)
1173infixl 8 .->>
1140infixl 8 .->>
1174(.->>) = unsafeBinaryOp "->>"
1141(.->>) = unsafeBinaryOp "->>"
1175
1142
1176-- | Get JSON value at a specified path.
1143-- | Get JSON value at a specified path.
1177(.#>)
1144(.#>)
1178 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1145 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1179− => Operator (nullity json) (nullity path) ('Null json)
1146+ => Operator (null json) (null path) ('Null json)
1180infixl 8 .#>
1147infixl 8 .#>
1181(.#>) = unsafeBinaryOp "#>"
1148(.#>) = unsafeBinaryOp "#>"
1182
1149
1183-- | Get JSON value at a specified path as text.
1150-- | Get JSON value at a specified path as text.
1184(.#>>)
1151(.#>>)
1185 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1152 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1186− => Operator (nullity json) (nullity path) ('Null 'PGtext)
1153+ => Operator (null json) (null path) ('Null 'PGtext)
1187infixl 8 .#>>
1154infixl 8 .#>>
1188(.#>>) = unsafeBinaryOp "#>>"
1155(.#>>) = unsafeBinaryOp "#>>"
1189
1156
@@ -1192,40 +1159,40 @@ infixl 8 .#>>
1192-- | Does the left JSON value contain the right JSON path/value entries at the
1159-- | Does the left JSON value contain the right JSON path/value entries at the
1193-- top level?
1160-- top level?
1194(.@>)
1161(.@>)
1195− :: Operator (nullity 'PGjsonb) (nullity 'PGjsonb) ('Null 'PGbool)
1162+ :: Operator (null 'PGjsonb) (null 'PGjsonb) ('Null 'PGbool)
1196infixl 9 .@>
1163infixl 9 .@>
1197(.@>) = unsafeBinaryOp "@>"
1164(.@>) = unsafeBinaryOp "@>"
1198
1165
1199-- | Are the left JSON path/value entries contained at the top level within the
1166-- | Are the left JSON path/value entries contained at the top level within the
1200-- right JSON value?
1167-- right JSON value?
1201−(.<@) :: Operator (nullity 'PGjsonb) (nullity 'PGjsonb) ('Null 'PGbool)
1168+(.<@) :: Operator (null 'PGjsonb) (null 'PGjsonb) ('Null 'PGbool)
1202infixl 9 .<@
1169infixl 9 .<@
1203(.<@) = unsafeBinaryOp "<@"
1170(.<@) = unsafeBinaryOp "<@"
1204
1171
1205-- | Does the string exist as a top-level key within the JSON value?
1172-- | 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)
1207infixl 9 .?
1174infixl 9 .?
1208(.?) = unsafeBinaryOp "?"
1175(.?) = unsafeBinaryOp "?"
1209
1176
1210-- | Do any of these array strings exist as top-level keys?
1177-- | Do any of these array strings exist as top-level keys?
1211(.?|) :: Operator
1178(.?|) :: Operator
1212− (nullity 'PGjsonb)
1179+ (null 'PGjsonb)
1213− (nullity ('PGvararray ('NotNull 'PGtext)))
1180+ (null ('PGvararray ('NotNull 'PGtext)))
1214 ('Null 'PGbool)
1181 ('Null 'PGbool)
1215infixl 9 .?|
1182infixl 9 .?|
1216(.?|) = unsafeBinaryOp "?|"
1183(.?|) = unsafeBinaryOp "?|"
1217
1184
1218-- | Do all of these array strings exist as top-level keys?
1185-- | Do all of these array strings exist as top-level keys?
1219(.?&) :: Operator
1186(.?&) :: Operator
1220− (nullity 'PGjsonb)
1187+ (null 'PGjsonb)
1221− (nullity ('PGvararray ('NotNull 'PGtext)))
1188+ (null ('PGvararray ('NotNull 'PGtext)))
1222 ('Null 'PGbool)
1189 ('Null 'PGbool)
1223infixl 9 .?&
1190infixl 9 .?&
1224(.?&) = unsafeBinaryOp "?&"
1191(.?&) = unsafeBinaryOp "?&"
1225
1192
1226-- | Concatenate two jsonb values into a new jsonb value.
1193-- | Concatenate two jsonb values into a new jsonb value.
1227instance Semigroup
1194instance Semigroup
1228− (Expression outer grp commons schemas params from (nullity 'PGjsonb)) where
1195+ (Expression outer grp commons schemas params from (null 'PGjsonb)) where
1229 (<>) = unsafeBinaryOp "||"
1196 (<>) = unsafeBinaryOp "||"
1230
1197
1231-- | Delete a key or keys from a JSON object, or remove an array element.
1198-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1242,7 +1209,7 @@ instance Semigroup
1242-- count from the end). Throws an error if top level container is not an array.
1209-- count from the end). Throws an error if top level container is not an array.
1243(.-.)
1210(.-.)
1244 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1211 :: (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)
1246infixl 6 .-.
1213infixl 6 .-.
1247(.-.) = unsafeBinaryOp "-"
1214(.-.) = unsafeBinaryOp "-"
1248
1215
@@ -1250,7 +1217,7 @@ infixl 6 .-.
1250-- integers count from the end)
1217-- integers count from the end)
1251(#-.)
1218(#-.)
1252 :: PGTextArray "(#-.)" arrayty
1219 :: PGTextArray "(#-.)" arrayty
1253− => Operator (nullity 'PGjsonb) (nullity arrayty)(nullity 'PGjsonb)
1220+ => Operator (null 'PGjsonb) (null arrayty)(null 'PGjsonb)
1254infixl 6 #-.
1221infixl 6 #-.
1255(#-.) = unsafeBinaryOp "#-"
1222(#-.) = unsafeBinaryOp "#-"
1256
1223
@@ -1259,16 +1226,12 @@ Table 9.45: JSON creation functions
1259-----------------------------------------}
1226-----------------------------------------}
1260
1227
1261-- | Literal binary JSON
1228-- | Literal binary JSON
1262−jsonbLit
1263− :: JSON.ToJSON x
1229+jsonbLit :: JSON.ToJSON x => x -> Expr (null 'PGjsonb)
1264− => x -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1265jsonbLit = cast jsonb . UnsafeExpression
1230jsonbLit = cast jsonb . UnsafeExpression
1266 . singleQuotedUtf8 . toStrict . JSON.encode
1231 . singleQuotedUtf8 . toStrict . JSON.encode
1267
1232
1268-- | Literal JSON
1233-- | Literal JSON
1269−jsonLit
1270− :: JSON.ToJSON x
1234+jsonLit :: JSON.ToJSON x => x -> Expr (null 'PGjson)
1271− => x -> Expression outer grp commons schemas params from (nullity 'PGjson)
1272jsonLit = cast json . UnsafeExpression
1235jsonLit = cast json . UnsafeExpression
1273 . singleQuotedUtf8 . toStrict . JSON.encode
1236 . singleQuotedUtf8 . toStrict . JSON.encode
1274
1237
@@ -1278,7 +1241,7 @@ jsonLit = cast json . UnsafeExpression
1278-- otherwise, a scalar value is produced. For any scalar type other than a
1241-- otherwise, a scalar value is produced. For any scalar type other than a
1279-- number, a Boolean, or a null value, the text representation will be used, in
1242-- number, a Boolean, or a null value, the text representation will be used, in
1280-- such a fashion that it is a valid json value.
1243-- such a fashion that it is a valid json value.
1281−toJson :: nullity ty :--> nullity 'PGjson
1244+toJson :: null ty :--> null 'PGjson
1282toJson = unsafeFunction "to_json"
1245toJson = unsafeFunction "to_json"
1283
1246
1284-- | Returns the value as jsonb. Arrays and composites are converted
1247-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1287,18 +1250,18 @@ toJson = unsafeFunction "to_json"
1287-- otherwise, a scalar value is produced. For any scalar type other than a
1250-- otherwise, a scalar value is produced. For any scalar type other than a
1288-- number, a Boolean, or a null value, the text representation will be used, in
1251-- number, a Boolean, or a null value, the text representation will be used, in
1289-- such a fashion that it is a valid jsonb value.
1252-- such a fashion that it is a valid jsonb value.
1290−toJsonb :: nullity ty :--> nullity 'PGjsonb
1253+toJsonb :: null ty :--> null 'PGjsonb
1291toJsonb = unsafeFunction "to_jsonb"
1254toJsonb = unsafeFunction "to_jsonb"
1292
1255
1293-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1256-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1294-- becomes a JSON array of arrays.
1257-- becomes a JSON array of arrays.
1295arrayToJson
1258arrayToJson
1296 :: PGArray "arrayToJson" arr
1259 :: PGArray "arrayToJson" arr
1297− => nullity arr :--> nullity 'PGjson
1260+ => null arr :--> null 'PGjson
1298arrayToJson = unsafeFunction "array_to_json"
1261arrayToJson = unsafeFunction "array_to_json"
1299
1262
1300-- | Returns the row as a JSON object.
1263-- | Returns the row as a JSON object.
1301−rowToJson :: nullity ('PGcomposite ty) :--> nullity 'PGjson
1264+rowToJson :: null ('PGcomposite ty) :--> null 'PGjson
1302rowToJson = unsafeFunction "row_to_json"
1265rowToJson = unsafeFunction "row_to_json"
1303
1266
1304-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1267-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
@@ -1306,7 +1269,7 @@ rowToJson = unsafeFunction "row_to_json"
1306jsonBuildArray
1269jsonBuildArray
1307 :: SListI elems
1270 :: SListI elems
1308 => NP (Expression outer grp commons schemas params from) elems
1271 => 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)
1310jsonBuildArray = unsafeVariadicFunction "json_build_array"
1273jsonBuildArray = unsafeVariadicFunction "json_build_array"
1311
1274
1312-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1275-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
@@ -1314,7 +1277,7 @@ jsonBuildArray = unsafeVariadicFunction "json_build_array"
1314jsonbBuildArray
1277jsonbBuildArray
1315 :: SListI elems
1278 :: SListI elems
1316 => NP (Expression outer grp commons schemas params from) elems
1279 => 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)
1318jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1281jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1319
1282
1320unsafeRowFunction
1283unsafeRowFunction
@@ -1335,7 +1298,7 @@ unsafeRowFunction =
1335jsonBuildObject
1298jsonBuildObject
1336 :: SOP.SListI elems
1299 :: SOP.SListI elems
1337 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1300 => 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)
1339jsonBuildObject
1302jsonBuildObject
1340 = unsafeFunction "json_build_object"
1303 = unsafeFunction "json_build_object"
1341 . UnsafeExpression
1304 . UnsafeExpression
@@ -1348,7 +1311,7 @@ jsonBuildObject
1348jsonbBuildObject
1311jsonbBuildObject
1349 :: SOP.SListI elems
1312 :: SOP.SListI elems
1350 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1313 => 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)
1352jsonbBuildObject
1315jsonbBuildObject
1353 = unsafeFunction "jsonb_build_object"
1316 = unsafeFunction "jsonb_build_object"
1354 . UnsafeExpression
1317 . UnsafeExpression
@@ -1361,7 +1324,7 @@ jsonbBuildObject
1361-- array has exactly two elements, which are taken as a key/value pair.
1324-- array has exactly two elements, which are taken as a key/value pair.
1362jsonObject
1325jsonObject
1363 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1326 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1364− => nullity arr :--> nullity 'PGjson
1327+ => null arr :--> null 'PGjson
1365jsonObject = unsafeFunction "json_object"
1328jsonObject = unsafeFunction "json_object"
1366
1329
1367-- | Builds a binary JSON object out of a text array. The array must have either
1330-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1370,7 +1333,7 @@ jsonObject = unsafeFunction "json_object"
1370-- array has exactly two elements, which are taken as a key/value pair.
1333-- array has exactly two elements, which are taken as a key/value pair.
1371jsonbObject
1334jsonbObject
1372 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1335 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1373− => nullity arr :--> nullity 'PGjsonb
1336+ => null arr :--> null 'PGjsonb
1374jsonbObject = unsafeFunction "jsonb_object"
1337jsonbObject = unsafeFunction "jsonb_object"
1375
1338
1376-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1339-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1378,9 +1341,9 @@ jsonbObject = unsafeFunction "jsonb_object"
1378jsonZipObject
1341jsonZipObject
1379 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1342 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1380 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1343 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1381− => Expression outer grp commons schemas params from (nullity keysArray)
1344+ => Expression outer grp commons schemas params from (null keysArray)
1382− -> Expression outer grp commons schemas params from (nullity valuesArray)
1345+ -> Expression outer grp commons schemas params from (null valuesArray)
1383− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1346+ -> Expression outer grp commons schemas params from (null 'PGjson)
1384jsonZipObject ks vs =
1347jsonZipObject ks vs =
1385 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1348 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1386
1349
@@ -1390,9 +1353,9 @@ jsonZipObject ks vs =
1390jsonbZipObject
1353jsonbZipObject
1391 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1354 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1392 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1355 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1393− => Expression outer grp commons schemas params from (nullity keysArray)
1356+ => Expression outer grp commons schemas params from (null keysArray)
1394− -> Expression outer grp commons schemas params from (nullity valuesArray)
1357+ -> Expression outer grp commons schemas params from (null valuesArray)
1395− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1358+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1396jsonbZipObject ks vs =
1359jsonbZipObject ks vs =
1397 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1360 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1398
1361
@@ -1401,20 +1364,20 @@ Table 9.46: JSON processing functions
1401-----------------------------------------}
1364-----------------------------------------}
1402
1365
1403-- | Returns the number of elements in the outermost JSON array.
1366-- | Returns the number of elements in the outermost JSON array.
1404−jsonArrayLength :: nullity 'PGjson :--> nullity 'PGint4
1367+jsonArrayLength :: null 'PGjson :--> null 'PGint4
1405jsonArrayLength = unsafeFunction "json_array_length"
1368jsonArrayLength = unsafeFunction "json_array_length"
1406
1369
1407-- | Returns the number of elements in the outermost binary JSON array.
1370-- | Returns the number of elements in the outermost binary JSON array.
1408−jsonbArrayLength :: nullity 'PGjsonb :--> nullity 'PGint4
1371+jsonbArrayLength :: null 'PGjsonb :--> null 'PGint4
1409jsonbArrayLength = unsafeFunction "jsonb_array_length"
1372jsonbArrayLength = unsafeFunction "jsonb_array_length"
1410
1373
1411-- | Returns JSON value pointed to by the given path (equivalent to #>
1374-- | Returns JSON value pointed to by the given path (equivalent to #>
1412-- operator).
1375-- operator).
1413jsonExtractPath
1376jsonExtractPath
1414 :: SListI elems
1377 :: SListI elems
1415− => Expression outer grp commons schemas params from (nullity 'PGjson)
1378+ => Expression outer grp commons schemas params from (null 'PGjson)
1416 -> NP (Expression outer grp commons schemas params from) elems
1379 -> 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)
1418jsonExtractPath x xs =
1381jsonExtractPath x xs =
1419 unsafeVariadicFunction "json_extract_path" (x :* xs)
1382 unsafeVariadicFunction "json_extract_path" (x :* xs)
1420
1383
@@ -1422,9 +1385,9 @@ jsonExtractPath x xs =
1422-- operator).
1385-- operator).
1423jsonbExtractPath
1386jsonbExtractPath
1424 :: SListI elems
1387 :: SListI elems
1425− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1388+ => Expression outer grp commons schemas params from (null 'PGjsonb)
1426 -> NP (Expression outer grp commons schemas params from) elems
1389 -> 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)
1428jsonbExtractPath x xs =
1391jsonbExtractPath x xs =
1429 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1392 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1430
1393
@@ -1432,9 +1395,9 @@ jsonbExtractPath x xs =
1432-- operator), as text.
1395-- operator), as text.
1433jsonExtractPathAsText
1396jsonExtractPathAsText
1434 :: SListI elems
1397 :: SListI elems
1435− => Expression outer grp commons schemas params from (nullity 'PGjson)
1398+ => Expression outer grp commons schemas params from (null 'PGjson)
1436 -> NP (Expression outer grp commons schemas params from) elems
1399 -> 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)
1438jsonExtractPathAsText x xs =
1401jsonExtractPathAsText x xs =
1439 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1402 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1440
1403
@@ -1442,30 +1405,30 @@ jsonExtractPathAsText x xs =
1442-- operator), as text.
1405-- operator), as text.
1443jsonbExtractPathAsText
1406jsonbExtractPathAsText
1444 :: SListI elems
1407 :: SListI elems
1445− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1408+ => Expression outer grp commons schemas params from (null 'PGjsonb)
1446 -> NP (Expression outer grp commons schemas params from) elems
1409 -> 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)
1448jsonbExtractPathAsText x xs =
1411jsonbExtractPathAsText x xs =
1449 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1412 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1450
1413
1451-- | Returns the type of the outermost JSON value as a text string. Possible
1414-- | Returns the type of the outermost JSON value as a text string. Possible
1452-- types are object, array, string, number, boolean, and null.
1415-- types are object, array, string, number, boolean, and null.
1453−jsonTypeof :: nullity 'PGjson :--> nullity 'PGtext
1416+jsonTypeof :: null 'PGjson :--> null 'PGtext
1454jsonTypeof = unsafeFunction "json_typeof"
1417jsonTypeof = unsafeFunction "json_typeof"
1455
1418
1456-- | Returns the type of the outermost binary JSON value as a text string.
1419-- | Returns the type of the outermost binary JSON value as a text string.
1457-- Possible types are object, array, string, number, boolean, and null.
1420-- Possible types are object, array, string, number, boolean, and null.
1458−jsonbTypeof :: nullity 'PGjsonb :--> nullity 'PGtext
1421+jsonbTypeof :: null 'PGjsonb :--> null 'PGtext
1459jsonbTypeof = unsafeFunction "jsonb_typeof"
1422jsonbTypeof = unsafeFunction "jsonb_typeof"
1460
1423
1461-- | Returns its argument with all object fields that have null values omitted.
1424-- | Returns its argument with all object fields that have null values omitted.
1462-- Other null values are untouched.
1425-- Other null values are untouched.
1463−jsonStripNulls :: nullity 'PGjson :--> nullity 'PGjson
1426+jsonStripNulls :: null 'PGjson :--> null 'PGjson
1464jsonStripNulls = unsafeFunction "json_strip_nulls"
1427jsonStripNulls = unsafeFunction "json_strip_nulls"
1465
1428
1466-- | Returns its argument with all object fields that have null values omitted.
1429-- | Returns its argument with all object fields that have null values omitted.
1467-- Other null values are untouched.
1430-- Other null values are untouched.
1468−jsonbStripNulls :: nullity 'PGjsonb :--> nullity 'PGjsonb
1431+jsonbStripNulls :: null 'PGjsonb :--> null 'PGjsonb
1469jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1432jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1470
1433
1471-- | @ jsonbSet target path new_value create_missing @
1434-- | @ jsonbSet target path new_value create_missing @
@@ -1477,11 +1440,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1477-- arrays.
1440-- arrays.
1478jsonbSet
1441jsonbSet
1479 :: PGTextArray "jsonbSet" arr
1442 :: PGTextArray "jsonbSet" arr
1480− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1443+ => Expression outer grp commons schemas params from (null 'PGjsonb)
1481− -> Expression outer grp commons schemas params from (nullity arr)
1444+ -> Expression outer grp commons schemas params from (null arr)
1482− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1445+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1483− -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1446+ -> Maybe (Expression outer grp commons schemas params from (null 'PGbool))
1484− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1447+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1485jsonbSet tgt path val createMissing = case createMissing of
1448jsonbSet tgt path val createMissing = case createMissing of
1486 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1449 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1487 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
1450 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1496,67 +1459,67 @@ jsonbSet tgt path val createMissing = case createMissing of
1496-- in path count from the end of JSON arrays.
1459-- in path count from the end of JSON arrays.
1497jsonbInsert
1460jsonbInsert
1498 :: PGTextArray "jsonbInsert" arr
1461 :: PGTextArray "jsonbInsert" arr
1499− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1462+ => Expression outer grp commons schemas params from (null 'PGjsonb)
1500− -> Expression outer grp commons schemas params from (nullity arr)
1463+ -> Expression outer grp commons schemas params from (null arr)
1501− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1464+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1502− -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1465+ -> Maybe (Expression outer grp commons schemas params from (null 'PGbool))
1503− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1466+ -> Expression outer grp commons schemas params from (null 'PGjsonb)
1504jsonbInsert tgt path val insertAfter = case insertAfter of
1467jsonbInsert tgt path val insertAfter = case insertAfter of
1505 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1468 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1506 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1469 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1507
1470
1508-- | Returns its argument as indented JSON text.
1471-- | Returns its argument as indented JSON text.
1509−jsonbPretty :: nullity 'PGjsonb :--> nullity 'PGtext
1472+jsonbPretty :: null 'PGjsonb :--> null 'PGtext
1510jsonbPretty = unsafeFunction "jsonb_pretty"
1473jsonbPretty = unsafeFunction "jsonb_pretty"
1511
1474
1512−(@@) :: Operator (nullity 'PGtsvector) (nullity 'PGtsquery) ('Null 'PGbool)
1475+(@@) :: Operator (null 'PGtsvector) (null 'PGtsquery) ('Null 'PGbool)
1513(@@) = unsafeBinaryOp "@@"
1476(@@) = unsafeBinaryOp "@@"
1514
1477
1515−(.&) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1478+(.&) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
1516(.&) = unsafeBinaryOp "&&"
1479(.&) = unsafeBinaryOp "&&"
1517
1480
1518−(.|) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1481+(.|) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
1519(.|) = unsafeBinaryOp "||"
1482(.|) = unsafeBinaryOp "||"
1520
1483
1521−(.!) :: nullity 'PGtsquery :--> nullity 'PGtsquery
1484+(.!) :: null 'PGtsquery :--> null 'PGtsquery
1522−(.!) = unsafeUnaryOp "!!"
1485+(.!) = unsafeUnaryOpL "!!"
1523
1486
1524−(<->) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1487+(<->) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
1525(<->) = unsafeBinaryOp "<->"
1488(<->) = unsafeBinaryOp "<->"
1526
1489
1527arrayToTSvector
1490arrayToTSvector
1528− :: nullity ('PGvararray ('NotNull 'PGtext))
1491+ :: null ('PGvararray ('NotNull 'PGtext))
1529− :--> nullity 'PGtsvector
1492+ :--> null 'PGtsvector
1530arrayToTSvector = unsafeFunction "array_to_tsvector"
1493arrayToTSvector = unsafeFunction "array_to_tsvector"
1531
1494
1532−tsvectorLength :: nullity 'PGtsvector :--> nullity 'PGint4
1495+tsvectorLength :: null 'PGtsvector :--> null 'PGint4
1533tsvectorLength = unsafeFunction "length"
1496tsvectorLength = unsafeFunction "length"
1534
1497
1535−numnode :: nullity 'PGtsquery :--> nullity 'PGint4
1498+numnode :: null 'PGtsquery :--> null 'PGint4
1536numnode = unsafeFunction "numnode"
1499numnode = unsafeFunction "numnode"
1537
1500
1538plainToTSquery
1501plainToTSquery
1539− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1502+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
1540plainToTSquery = unsafeFunctionHet "plainto_tsquery"
1503plainToTSquery = unsafeFunctionHet "plainto_tsquery"
1541
1504
1542phraseToTSquery
1505phraseToTSquery
1543− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1506+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
1544phraseToTSquery = unsafeFunctionHet "phraseto_tsquery"
1507phraseToTSquery = unsafeFunctionHet "phraseto_tsquery"
1545
1508
1546websearchToTSquery
1509websearchToTSquery
1547− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1510+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
1548websearchToTSquery = unsafeFunctionHet "websearch_to_tsquery"
1511websearchToTSquery = unsafeFunctionHet "websearch_to_tsquery"
1549
1512
1550−queryTree :: nullity 'PGtsquery :--> nullity 'PGtext
1513+queryTree :: null 'PGtsquery :--> null 'PGtext
1551queryTree = unsafeFunction "query_tree"
1514queryTree = unsafeFunction "query_tree"
1552
1515
1553toTSquery
1516toTSquery
1554− :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1517+ :: FunctionHet '[null 'PGtext, null 'PGtext] (null 'PGtsquery)
1555toTSquery = unsafeFunctionHet "to_tsquery"
1518toTSquery = unsafeFunctionHet "to_tsquery"
1556
1519
1557toTSvector
1520toTSvector
1558 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1521 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1559− => FunctionHet '[nullity 'PGtext, nullity ty] (nullity 'PGtsquery)
1522+ => FunctionHet '[null 'PGtext, null ty] (null 'PGtsquery)
1560toTSvector = unsafeFunctionHet "to_tsvector"
1523toTSvector = unsafeFunctionHet "to_tsvector"
1561
1524
1562{-----------------------------------------
1525{-----------------------------------------
@@ -1584,7 +1547,7 @@ class Aggregate expr1 expr2 aggr
1584
1547
1585 -- | >>> :{
1548 -- | >>> :{
1586 -- let
1549 -- 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)
1588 -- expression = count (All #col)
1551 -- expression = count (All #col)
1589 -- in printSQL expression
1552 -- in printSQL expression
1590 -- :}
1553 -- :}
@@ -1603,7 +1566,7 @@ class Aggregate expr1 expr2 aggr
1603 -- sum(DISTINCT "col")
1566 -- sum(DISTINCT "col")
1604 sum_
1567 sum_
1605 :: ty `In` PGNum
1568 :: ty `In` PGNum
1606− => expr1 (nullity ty)
1569+ => expr1 (null ty)
1607 -> aggr ('NotNull ty)
1570 -> aggr ('NotNull ty)
1608
1571
1609 -- | input values, including nulls, concatenated into an array
1572 -- | input values, including nulls, concatenated into an array
@@ -1625,7 +1588,7 @@ class Aggregate expr1 expr2 aggr
1625 the bitwise AND of all non-null input values, or null if none
1588 the bitwise AND of all non-null input values, or null if none
1626 >>> :{
1589 >>> :{
1627 let
1590 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)
1629 expression = bitAnd (Distinct #col)
1592 expression = bitAnd (Distinct #col)
1630 in printSQL expression
1593 in printSQL expression
1631 :}
1594 :}
@@ -1633,7 +1596,7 @@ class Aggregate expr1 expr2 aggr
1633 -}
1596 -}
1634 bitAnd
1597 bitAnd
1635 :: int `In` PGIntegral
1598 :: int `In` PGIntegral
1636− => expr1 (nullity int)
1599+ => expr1 (null int)
1637 -- ^ what to aggregate
1600 -- ^ what to aggregate
1638 -> aggr ('Null int)
1601 -> aggr ('Null int)
1639
1602
@@ -1642,7 +1605,7 @@ class Aggregate expr1 expr2 aggr
1642
1605
1643 >>> :{
1606 >>> :{
1644 let
1607 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)
1646 expression = bitOr (All #col)
1609 expression = bitOr (All #col)
1647 in printSQL expression
1610 in printSQL expression
1648 :}
1611 :}
@@ -1650,7 +1613,7 @@ class Aggregate expr1 expr2 aggr
1650 -}
1613 -}
1651 bitOr
1614 bitOr
1652 :: int `In` PGIntegral
1615 :: int `In` PGIntegral
1653− => expr1 (nullity int)
1616+ => expr1 (null int)
1654 -- ^ what to aggregate
1617 -- ^ what to aggregate
1655 -> aggr ('Null int)
1618 -> aggr ('Null int)
1656
1619
@@ -1659,14 +1622,14 @@ class Aggregate expr1 expr2 aggr
1659
1622
1660 >>> :{
1623 >>> :{
1661 let
1624 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)
1663 winFun = boolAnd #col
1626 winFun = boolAnd #col
1664 in printSQL winFun
1627 in printSQL winFun
1665 :}
1628 :}
1666 bool_and("col")
1629 bool_and("col")
1667 -}
1630 -}
1668 boolAnd
1631 boolAnd
1669− :: expr1 (nullity 'PGbool)
1632+ :: expr1 (null 'PGbool)
1670 -- ^ what to aggregate
1633 -- ^ what to aggregate
1671 -> aggr ('Null 'PGbool)
1634 -> aggr ('Null 'PGbool)
1672
1635
@@ -1675,14 +1638,14 @@ class Aggregate expr1 expr2 aggr
1675
1638
1676 >>> :{
1639 >>> :{
1677 let
1640 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)
1679 expression = boolOr (All #col)
1642 expression = boolOr (All #col)
1680 in printSQL expression
1643 in printSQL expression
1681 :}
1644 :}
1682 bool_or(ALL "col")
1645 bool_or(ALL "col")
1683 -}
1646 -}
1684 boolOr
1647 boolOr
1685− :: expr1(nullity 'PGbool)
1648+ :: expr1(null 'PGbool)
1686 -- ^ what to aggregate
1649 -- ^ what to aggregate
1687 -> aggr ('Null 'PGbool)
1650 -> aggr ('Null 'PGbool)
1688
1651
@@ -1691,32 +1654,32 @@ class Aggregate expr1 expr2 aggr
1691
1654
1692 >>> :{
1655 >>> :{
1693 let
1656 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)
1695 expression = every (Distinct #col)
1658 expression = every (Distinct #col)
1696 in printSQL expression
1659 in printSQL expression
1697 :}
1660 :}
1698 every(DISTINCT "col")
1661 every(DISTINCT "col")
1699 -}
1662 -}
1700 every
1663 every
1701− :: expr1 (nullity 'PGbool)
1664+ :: expr1 (null 'PGbool)
1702 -- ^ what to aggregate
1665 -- ^ what to aggregate
1703 -> aggr ('Null 'PGbool)
1666 -> aggr ('Null 'PGbool)
1704
1667
1705 {- |maximum value of expression across all input values-}
1668 {- |maximum value of expression across all input values-}
1706 max_
1669 max_
1707− :: expr1 (nullity ty)
1670+ :: expr1 (null ty)
1708 -- ^ what to maximize
1671 -- ^ what to maximize
1709 -> aggr ('Null ty)
1672 -> aggr ('Null ty)
1710
1673
1711 -- | minimum value of expression across all input values
1674 -- | minimum value of expression across all input values
1712 min_
1675 min_
1713− :: expr1 (nullity ty)
1676+ :: expr1 (null ty)
1714 -- ^ what to minimize
1677 -- ^ what to minimize
1715 -> aggr ('Null ty)
1678 -> aggr ('Null ty)
1716
1679
1717 -- | the average (arithmetic mean) of all input values
1680 -- | the average (arithmetic mean) of all input values
1718 avg
1681 avg
1719− :: expr1 (nullity ty)
1682+ :: expr1 (null ty)
1720 -- ^ what to average
1683 -- ^ what to average
1721 -> aggr ('Null (PGAvg ty))
1684 -> aggr ('Null (PGAvg ty))
1722
1685
@@ -1730,7 +1693,7 @@ class Aggregate expr1 expr2 aggr
1730 corr(ALL "y", "x")
1693 corr(ALL "y", "x")
1731 -}
1694 -}
1732 corr
1695 corr
1733− :: expr2 (nullity 'PGfloat8)
1696+ :: expr2 (null 'PGfloat8)
1734 -> aggr ('Null 'PGfloat8)
1697 -> aggr ('Null 'PGfloat8)
1735
1698
1736 {- | population covariance
1699 {- | population covariance
@@ -1743,7 +1706,7 @@ class Aggregate expr1 expr2 aggr
1743 covar_pop(ALL "y", "x")
1706 covar_pop(ALL "y", "x")
1744 -}
1707 -}
1745 covarPop
1708 covarPop
1746− :: expr2 (nullity 'PGfloat8)
1709+ :: expr2 (null 'PGfloat8)
1747 -> aggr ('Null 'PGfloat8)
1710 -> aggr ('Null 'PGfloat8)
1748
1711
1749 {- | sample covariance
1712 {- | sample covariance
@@ -1756,7 +1719,7 @@ class Aggregate expr1 expr2 aggr
1756 covar_samp("y", "x")
1719 covar_samp("y", "x")
1757 -}
1720 -}
1758 covarSamp
1721 covarSamp
1759− :: expr2 (nullity 'PGfloat8)
1722+ :: expr2 (null 'PGfloat8)
1760 -> aggr ('Null 'PGfloat8)
1723 -> aggr ('Null 'PGfloat8)
1761
1724
1762 {- | average of the independent variable (sum(X)/N)
1725 {- | average of the independent variable (sum(X)/N)
@@ -1769,7 +1732,7 @@ class Aggregate expr1 expr2 aggr
1769 regr_avgx(ALL "y", "x")
1732 regr_avgx(ALL "y", "x")
1770 -}
1733 -}
1771 regrAvgX
1734 regrAvgX
1772− :: expr2 (nullity 'PGfloat8)
1735+ :: expr2 (null 'PGfloat8)
1773 -> aggr ('Null 'PGfloat8)
1736 -> aggr ('Null 'PGfloat8)
1774
1737
1775 {- | average of the dependent variable (sum(Y)/N)
1738 {- | average of the dependent variable (sum(Y)/N)
@@ -1782,7 +1745,7 @@ class Aggregate expr1 expr2 aggr
1782 regr_avgy("y", "x")
1745 regr_avgy("y", "x")
1783 -}
1746 -}
1784 regrAvgY
1747 regrAvgY
1785− :: expr2 (nullity 'PGfloat8)
1748+ :: expr2 (null 'PGfloat8)
1786 -> aggr ('Null 'PGfloat8)
1749 -> aggr ('Null 'PGfloat8)
1787
1750
1788 {- | number of input rows in which both expressions are nonnull
1751 {- | number of input rows in which both expressions are nonnull
@@ -1795,7 +1758,7 @@ class Aggregate expr1 expr2 aggr
1795 regr_count("y", "x")
1758 regr_count("y", "x")
1796 -}
1759 -}
1797 regrCount
1760 regrCount
1798− :: expr2 (nullity 'PGfloat8)
1761+ :: expr2 (null 'PGfloat8)
1799 -> aggr ('Null 'PGint8)
1762 -> aggr ('Null 'PGint8)
1800
1763
1801 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
1764 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
@@ -1808,68 +1771,68 @@ class Aggregate expr1 expr2 aggr
1808 regr_intercept(ALL "y", "x")
1771 regr_intercept(ALL "y", "x")
1809 -}
1772 -}
1810 regrIntercept
1773 regrIntercept
1811− :: expr2 (nullity 'PGfloat8)
1774+ :: expr2 (null 'PGfloat8)
1812 -> aggr ('Null 'PGfloat8)
1775 -> aggr ('Null 'PGfloat8)
1813
1776
1814 -- | @regr_r2(Y, X)@, square of the correlation coefficient
1777 -- | @regr_r2(Y, X)@, square of the correlation coefficient
1815 regrR2
1778 regrR2
1816− :: expr2 (nullity 'PGfloat8)
1779+ :: expr2 (null 'PGfloat8)
1817 -> aggr ('Null 'PGfloat8)
1780 -> aggr ('Null 'PGfloat8)
1818
1781
1819 -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
1782 -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
1820 -- determined by the (X, Y) pairs
1783 -- determined by the (X, Y) pairs
1821 regrSlope
1784 regrSlope
1822− :: expr2 (nullity 'PGfloat8)
1785+ :: expr2 (null 'PGfloat8)
1823 -> aggr ('Null 'PGfloat8)
1786 -> aggr ('Null 'PGfloat8)
1824
1787
1825 -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
1788 -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
1826 -- (“sum of squares” of the independent variable)
1789 -- (“sum of squares” of the independent variable)
1827 regrSxx
1790 regrSxx
1828− :: expr2 (nullity 'PGfloat8)
1791+ :: expr2 (null 'PGfloat8)
1829 -> aggr ('Null 'PGfloat8)
1792 -> aggr ('Null 'PGfloat8)
1830
1793
1831 -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
1794 -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
1832 -- (“sum of products” of independent times dependent variable)
1795 -- (“sum of products” of independent times dependent variable)
1833 regrSxy
1796 regrSxy
1834− :: expr2 (nullity 'PGfloat8)
1797+ :: expr2 (null 'PGfloat8)
1835 -> aggr ('Null 'PGfloat8)
1798 -> aggr ('Null 'PGfloat8)
1836
1799
1837 -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
1800 -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
1838 -- (“sum of squares” of the dependent variable)
1801 -- (“sum of squares” of the dependent variable)
1839 regrSyy
1802 regrSyy
1840− :: expr2 (nullity 'PGfloat8)
1803+ :: expr2 (null 'PGfloat8)
1841 -> aggr ('Null 'PGfloat8)
1804 -> aggr ('Null 'PGfloat8)
1842
1805
1843 -- | historical alias for `stddevSamp`
1806 -- | historical alias for `stddevSamp`
1844 stddev
1807 stddev
1845− :: expr1 (nullity ty)
1808+ :: expr1 (null ty)
1846 -> aggr ('Null (PGAvg ty))
1809 -> aggr ('Null (PGAvg ty))
1847
1810
1848 -- | population standard deviation of the input values
1811 -- | population standard deviation of the input values
1849 stddevPop
1812 stddevPop
1850− :: expr1 (nullity ty)
1813+ :: expr1 (null ty)
1851 -> aggr ('Null (PGAvg ty))
1814 -> aggr ('Null (PGAvg ty))
1852
1815
1853 -- | sample standard deviation of the input values
1816 -- | sample standard deviation of the input values
1854 stddevSamp
1817 stddevSamp
1855− :: expr1 (nullity ty)
1818+ :: expr1 (null ty)
1856 -> aggr ('Null (PGAvg ty))
1819 -> aggr ('Null (PGAvg ty))
1857
1820
1858 -- | historical alias for `varSamp`
1821 -- | historical alias for `varSamp`
1859 variance
1822 variance
1860− :: expr1 (nullity ty)
1823+ :: expr1 (null ty)
1861 -> aggr ('Null (PGAvg ty))
1824 -> aggr ('Null (PGAvg ty))
1862
1825
1863 -- | population variance of the input values
1826 -- | population variance of the input values
1864 -- (square of the population standard deviation)
1827 -- (square of the population standard deviation)
1865 varPop
1828 varPop
1866− :: expr1 (nullity ty)
1829+ :: expr1 (null ty)
1867 -> aggr ('Null (PGAvg ty))
1830 -> aggr ('Null (PGAvg ty))
1868
1831
1869 -- | sample variance of the input values
1832 -- | sample variance of the input values
1870 -- (square of the sample standard deviation)
1833 -- (square of the sample standard deviation)
1871 varSamp
1834 varSamp
1872− :: expr1 (nullity ty)
1835+ :: expr1 (null ty)
1873 -> aggr ('Null (PGAvg ty))
1836 -> aggr ('Null (PGAvg ty))
1874
1837
1875{- |
1838{- |
@@ -2015,7 +1978,7 @@ instance RenderSQL (TypeExpression schemas ty) where
2015typedef
1978typedef
2016 :: (Has sch schemas schema, Has td schema ('Typedef ty))
1979 :: (Has sch schemas schema, Has td schema ('Typedef ty))
2017 => QualifiedAlias sch td
1980 => QualifiedAlias sch td
2018− -> TypeExpression schemas (nullity ty)
1981+ -> TypeExpression schemas (null ty)
2019typedef = UnsafeTypeExpression . renderSQL
1982typedef = UnsafeTypeExpression . renderSQL
2020
1983
2021-- | The composite type corresponding to a `Table` definition can be expressed
1984-- | The composite type corresponding to a `Table` definition can be expressed
@@ -2023,7 +1986,7 @@ typedef = UnsafeTypeExpression . renderSQL
2023typetable
1986typetable
2024 :: (Has sch schemas schema, Has tab schema ('Table table))
1987 :: (Has sch schemas schema, Has tab schema ('Table table))
2025 => QualifiedAlias sch tab
1988 => QualifiedAlias sch tab
2026− -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
1989+ -> TypeExpression schemas (null ('PGcomposite (TableToRow table)))
2027typetable = UnsafeTypeExpression . renderSQL
1990typetable = UnsafeTypeExpression . renderSQL
2028
1991
2029-- | The composite type corresponding to a `View` definition can be expressed
1992-- | The composite type corresponding to a `View` definition can be expressed
@@ -2031,101 +1994,101 @@ typetable = UnsafeTypeExpression . renderSQL
2031typeview
1994typeview
2032 :: (Has sch schemas schema, Has vw schema ('View view))
1995 :: (Has sch schemas schema, Has vw schema ('View view))
2033 => QualifiedAlias sch vw
1996 => QualifiedAlias sch vw
2034− -> TypeExpression schemas (nullity ('PGcomposite view))
1997+ -> TypeExpression schemas (null ('PGcomposite view))
2035typeview = UnsafeTypeExpression . renderSQL
1998typeview = UnsafeTypeExpression . renderSQL
2036
1999
2037-- | logical Boolean (true/false)
2000-- | logical Boolean (true/false)
2038−bool :: TypeExpression schemas (nullity 'PGbool)
2001+bool :: TypeExpression schemas (null 'PGbool)
2039bool = UnsafeTypeExpression "bool"
2002bool = UnsafeTypeExpression "bool"
2040-- | signed two-byte integer
2003-- | signed two-byte integer
2041−int2, smallint :: TypeExpression schemas (nullity 'PGint2)
2004+int2, smallint :: TypeExpression schemas (null 'PGint2)
2042int2 = UnsafeTypeExpression "int2"
2005int2 = UnsafeTypeExpression "int2"
2043smallint = UnsafeTypeExpression "smallint"
2006smallint = UnsafeTypeExpression "smallint"
2044-- | signed four-byte integer
2007-- | signed four-byte integer
2045−int4, int, integer :: TypeExpression schemas (nullity 'PGint4)
2008+int4, int, integer :: TypeExpression schemas (null 'PGint4)
2046int4 = UnsafeTypeExpression "int4"
2009int4 = UnsafeTypeExpression "int4"
2047int = UnsafeTypeExpression "int"
2010int = UnsafeTypeExpression "int"
2048integer = UnsafeTypeExpression "integer"
2011integer = UnsafeTypeExpression "integer"
2049-- | signed eight-byte integer
2012-- | signed eight-byte integer
2050−int8, bigint :: TypeExpression schemas (nullity 'PGint8)
2013+int8, bigint :: TypeExpression schemas (null 'PGint8)
2051int8 = UnsafeTypeExpression "int8"
2014int8 = UnsafeTypeExpression "int8"
2052bigint = UnsafeTypeExpression "bigint"
2015bigint = UnsafeTypeExpression "bigint"
2053-- | arbitrary precision numeric type
2016-- | arbitrary precision numeric type
2054−numeric :: TypeExpression schemas (nullity 'PGnumeric)
2017+numeric :: TypeExpression schemas (null 'PGnumeric)
2055numeric = UnsafeTypeExpression "numeric"
2018numeric = UnsafeTypeExpression "numeric"
2056-- | single precision floating-point number (4 bytes)
2019-- | single precision floating-point number (4 bytes)
2057−float4, real :: TypeExpression schemas (nullity 'PGfloat4)
2020+float4, real :: TypeExpression schemas (null 'PGfloat4)
2058float4 = UnsafeTypeExpression "float4"
2021float4 = UnsafeTypeExpression "float4"
2059real = UnsafeTypeExpression "real"
2022real = UnsafeTypeExpression "real"
2060-- | double precision floating-point number (8 bytes)
2023-- | double precision floating-point number (8 bytes)
2061−float8, doublePrecision :: TypeExpression schemas (nullity 'PGfloat8)
2024+float8, doublePrecision :: TypeExpression schemas (null 'PGfloat8)
2062float8 = UnsafeTypeExpression "float8"
2025float8 = UnsafeTypeExpression "float8"
2063doublePrecision = UnsafeTypeExpression "double precision"
2026doublePrecision = UnsafeTypeExpression "double precision"
2064-- | currency amount
2027-- | currency amount
2065−money :: TypeExpression schema (nullity 'PGmoney)
2028+money :: TypeExpression schema (null 'PGmoney)
2066money = UnsafeTypeExpression "money"
2029money = UnsafeTypeExpression "money"
2067-- | variable-length character string
2030-- | variable-length character string
2068−text :: TypeExpression schemas (nullity 'PGtext)
2031+text :: TypeExpression schemas (null 'PGtext)
2069text = UnsafeTypeExpression "text"
2032text = UnsafeTypeExpression "text"
2070-- | fixed-length character string
2033-- | fixed-length character string
2071char, character
2034char, character
2072− :: forall n schemas nullity. (KnownNat n, 1 <= n)
2035+ :: forall n schemas null. (KnownNat n, 1 <= n)
2073− => TypeExpression schemas (nullity ('PGchar n))
2036+ => TypeExpression schemas (null ('PGchar n))
2074char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
2037char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
2075character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
2038character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
2076-- | variable-length character string
2039-- | variable-length character string
2077varchar, characterVarying
2040varchar, characterVarying
2078− :: forall n schemas nullity. (KnownNat n, 1 <= n)
2041+ :: forall n schemas null. (KnownNat n, 1 <= n)
2079− => TypeExpression schemas (nullity ('PGvarchar n))
2042+ => TypeExpression schemas (null ('PGvarchar n))
2080varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
2043varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
2081characterVarying = UnsafeTypeExpression $
2044characterVarying = UnsafeTypeExpression $
2082 "character varying(" <> renderNat @n <> ")"
2045 "character varying(" <> renderNat @n <> ")"
2083-- | binary data ("byte array")
2046-- | binary data ("byte array")
2084−bytea :: TypeExpression schemas (nullity 'PGbytea)
2047+bytea :: TypeExpression schemas (null 'PGbytea)
2085bytea = UnsafeTypeExpression "bytea"
2048bytea = UnsafeTypeExpression "bytea"
2086-- | date and time (no time zone)
2049-- | date and time (no time zone)
2087−timestamp :: TypeExpression schemas (nullity 'PGtimestamp)
2050+timestamp :: TypeExpression schemas (null 'PGtimestamp)
2088timestamp = UnsafeTypeExpression "timestamp"
2051timestamp = UnsafeTypeExpression "timestamp"
2089-- | date and time, including time zone
2052-- | date and time, including time zone
2090−timestampWithTimeZone :: TypeExpression schemas (nullity 'PGtimestamptz)
2053+timestampWithTimeZone :: TypeExpression schemas (null 'PGtimestamptz)
2091timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
2054timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
2092-- | calendar date (year, month, day)
2055-- | calendar date (year, month, day)
2093−date :: TypeExpression schemas (nullity 'PGdate)
2056+date :: TypeExpression schemas (null 'PGdate)
2094date = UnsafeTypeExpression "date"
2057date = UnsafeTypeExpression "date"
2095-- | time of day (no time zone)
2058-- | time of day (no time zone)
2096−time :: TypeExpression schemas (nullity 'PGtime)
2059+time :: TypeExpression schemas (null 'PGtime)
2097time = UnsafeTypeExpression "time"
2060time = UnsafeTypeExpression "time"
2098-- | time of day, including time zone
2061-- | time of day, including time zone
2099−timeWithTimeZone :: TypeExpression schemas (nullity 'PGtimetz)
2062+timeWithTimeZone :: TypeExpression schemas (null 'PGtimetz)
2100timeWithTimeZone = UnsafeTypeExpression "time with time zone"
2063timeWithTimeZone = UnsafeTypeExpression "time with time zone"
2101-- | time span
2064-- | time span
2102−interval :: TypeExpression schemas (nullity 'PGinterval)
2065+interval :: TypeExpression schemas (null 'PGinterval)
2103interval = UnsafeTypeExpression "interval"
2066interval = UnsafeTypeExpression "interval"
2104-- | universally unique identifier
2067-- | universally unique identifier
2105−uuid :: TypeExpression schemas (nullity 'PGuuid)
2068+uuid :: TypeExpression schemas (null 'PGuuid)
2106uuid = UnsafeTypeExpression "uuid"
2069uuid = UnsafeTypeExpression "uuid"
2107-- | IPv4 or IPv6 host address
2070-- | IPv4 or IPv6 host address
2108−inet :: TypeExpression schemas (nullity 'PGinet)
2071+inet :: TypeExpression schemas (null 'PGinet)
2109inet = UnsafeTypeExpression "inet"
2072inet = UnsafeTypeExpression "inet"
2110-- | textual JSON data
2073-- | textual JSON data
2111−json :: TypeExpression schemas (nullity 'PGjson)
2074+json :: TypeExpression schemas (null 'PGjson)
2112json = UnsafeTypeExpression "json"
2075json = UnsafeTypeExpression "json"
2113-- | binary JSON data, decomposed
2076-- | binary JSON data, decomposed
2114−jsonb :: TypeExpression schemas (nullity 'PGjsonb)
2077+jsonb :: TypeExpression schemas (null 'PGjsonb)
2115jsonb = UnsafeTypeExpression "jsonb"
2078jsonb = UnsafeTypeExpression "jsonb"
2116-- | variable length array
2079-- | variable length array
2117vararray
2080vararray
2118 :: TypeExpression schemas pg
2081 :: TypeExpression schemas pg
2119− -> TypeExpression schemas (nullity ('PGvararray pg))
2082+ -> TypeExpression schemas (null ('PGvararray pg))
2120vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
2083vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
2121-- | fixed length array
2084-- | fixed length array
2122--
2085--
2123-- >>> renderSQL (fixarray @'[2] json)
2086-- >>> renderSQL (fixarray @'[2] json)
2124-- "json[2]"
2087-- "json[2]"
2125fixarray
2088fixarray
2126− :: forall dims schemas nullity pg. SOP.All KnownNat dims
2089+ :: forall dims schemas null pg. SOP.All KnownNat dims
2127 => TypeExpression schemas pg
2090 => TypeExpression schemas pg
2128− -> TypeExpression schemas (nullity ('PGfixarray dims pg))
2091+ -> TypeExpression schemas (null ('PGfixarray dims pg))
2129fixarray ty = UnsafeTypeExpression $
2092fixarray ty = UnsafeTypeExpression $
2130 renderSQL ty <> renderDims @dims
2093 renderSQL ty <> renderDims @dims
2131 where
2094 where
@@ -2138,45 +2101,45 @@ fixarray ty = UnsafeTypeExpression $
2138 $ hcmap (SOP.Proxy @KnownNat)
2101 $ hcmap (SOP.Proxy @KnownNat)
2139 (K . fromString . show . natVal)
2102 (K . fromString . show . natVal)
2140 (hpure SOP.Proxy :: NP SOP.Proxy ns)
2103 (hpure SOP.Proxy :: NP SOP.Proxy ns)
2141−tsvector :: TypeExpression schemas (nullity 'PGtsvector)
2104+tsvector :: TypeExpression schemas (null 'PGtsvector)
2142tsvector = UnsafeTypeExpression "tsvector"
2105tsvector = UnsafeTypeExpression "tsvector"
2143−tsquery :: TypeExpression schemas (nullity 'PGtsquery)
2106+tsquery :: TypeExpression schemas (null 'PGtsquery)
2144tsquery = UnsafeTypeExpression "tsquery"
2107tsquery = UnsafeTypeExpression "tsquery"
2145
2108
2146-- | `pgtype` is a demoted version of a `PGType`
2109-- | `pgtype` is a demoted version of a `PGType`
2147class PGTyped schemas (ty :: NullityType) where
2110class PGTyped schemas (ty :: NullityType) where
2148 pgtype :: TypeExpression schemas ty
2111 pgtype :: TypeExpression schemas ty
2149−instance PGTyped schemas (nullity 'PGbool) where pgtype = bool
2112+instance PGTyped schemas (null 'PGbool) where pgtype = bool
2150−instance PGTyped schemas (nullity 'PGint2) where pgtype = int2
2113+instance PGTyped schemas (null 'PGint2) where pgtype = int2
2151−instance PGTyped schemas (nullity 'PGint4) where pgtype = int4
2114+instance PGTyped schemas (null 'PGint4) where pgtype = int4
2152−instance PGTyped schemas (nullity 'PGint8) where pgtype = int8
2115+instance PGTyped schemas (null 'PGint8) where pgtype = int8
2153−instance PGTyped schemas (nullity 'PGnumeric) where pgtype = numeric
2116+instance PGTyped schemas (null 'PGnumeric) where pgtype = numeric
2154−instance PGTyped schemas (nullity 'PGfloat4) where pgtype = float4
2117+instance PGTyped schemas (null 'PGfloat4) where pgtype = float4
2155−instance PGTyped schemas (nullity 'PGfloat8) where pgtype = float8
2118+instance PGTyped schemas (null 'PGfloat8) where pgtype = float8
2156−instance PGTyped schemas (nullity 'PGmoney) where pgtype = money
2119+instance PGTyped schemas (null 'PGmoney) where pgtype = money
2157−instance PGTyped schemas (nullity 'PGtext) where pgtype = text
2120+instance PGTyped schemas (null 'PGtext) where pgtype = text
2158instance (KnownNat n, 1 <= n)
2121instance (KnownNat n, 1 <= n)
2159− => PGTyped schemas (nullity ('PGchar n)) where pgtype = char @n
2122+ => PGTyped schemas (null ('PGchar n)) where pgtype = char @n
2160instance (KnownNat n, 1 <= n)
2123instance (KnownNat n, 1 <= n)
2161− => PGTyped schemas (nullity ('PGvarchar n)) where pgtype = varchar @n
2124+ => PGTyped schemas (null ('PGvarchar n)) where pgtype = varchar @n
2162−instance PGTyped schemas (nullity 'PGbytea) where pgtype = bytea
2125+instance PGTyped schemas (null 'PGbytea) where pgtype = bytea
2163−instance PGTyped schemas (nullity 'PGtimestamp) where pgtype = timestamp
2126+instance PGTyped schemas (null 'PGtimestamp) where pgtype = timestamp
2164−instance PGTyped schemas (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
2127+instance PGTyped schemas (null 'PGtimestamptz) where pgtype = timestampWithTimeZone
2165−instance PGTyped schemas (nullity 'PGdate) where pgtype = date
2128+instance PGTyped schemas (null 'PGdate) where pgtype = date
2166−instance PGTyped schemas (nullity 'PGtime) where pgtype = time
2129+instance PGTyped schemas (null 'PGtime) where pgtype = time
2167−instance PGTyped schemas (nullity 'PGtimetz) where pgtype = timeWithTimeZone
2130+instance PGTyped schemas (null 'PGtimetz) where pgtype = timeWithTimeZone
2168−instance PGTyped schemas (nullity 'PGinterval) where pgtype = interval
2131+instance PGTyped schemas (null 'PGinterval) where pgtype = interval
2169−instance PGTyped schemas (nullity 'PGuuid) where pgtype = uuid
2132+instance PGTyped schemas (null 'PGuuid) where pgtype = uuid
2170−instance PGTyped schemas (nullity 'PGjson) where pgtype = json
2133+instance PGTyped schemas (null 'PGjson) where pgtype = json
2171−instance PGTyped schemas (nullity 'PGjsonb) where pgtype = jsonb
2134+instance PGTyped schemas (null 'PGjsonb) where pgtype = jsonb
2172instance PGTyped schemas ty
2135instance PGTyped schemas ty
2173− => PGTyped schemas (nullity ('PGvararray ty)) where
2136+ => PGTyped schemas (null ('PGvararray ty)) where
2174 pgtype = vararray (pgtype @schemas @ty)
2137 pgtype = vararray (pgtype @schemas @ty)
2175instance (SOP.All KnownNat dims, PGTyped schemas ty)
2138instance (SOP.All KnownNat dims, PGTyped schemas ty)
2176− => PGTyped schemas (nullity ('PGfixarray dims ty)) where
2139+ => PGTyped schemas (null ('PGfixarray dims ty)) where
2177 pgtype = fixarray @dims (pgtype @schemas @ty)
2140 pgtype = fixarray @dims (pgtype @schemas @ty)
2178−instance PGTyped schemas (nullity 'PGtsvector) where pgtype = tsvector
2141+instance PGTyped schemas (null 'PGtsvector) where pgtype = tsvector
2179−instance PGTyped schemas (nullity 'PGtsquery) where pgtype = tsquery
2142+instance PGTyped schemas (null 'PGtsquery) where pgtype = tsquery
2180
2143
2181{-----------------------------------------
2144{-----------------------------------------
2182Sorting
2145Sorting
@@ -2417,7 +2380,7 @@ lastValue = unsafeWindowFunction1 "last_value"
2417row of the window frame (counting from 1); null if no such row
2380row of the window frame (counting from 1); null if no such row
2418-}
2381-}
2419nthValue
2382nthValue
2420− :: Expression outer grp commons schemas params from (nullity ty)
2383+ :: Expression outer grp commons schemas params from (null ty)
2421 -- ^ value
2384 -- ^ value
2422 -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2385 -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2423 -- ^ nth
2386 -- ^ nth
@@ -2428,114 +2391,78 @@ nthValue value nth = UnsafeWindowFunction $ "nth_value"
2428{-|
2391{-|
2429Create date from year, month and day fields
2392Create date from year, month and day fields
2430
2393
2431−>>> printSQL (makeDate 1984 7 3)
2394+>>> printSQL (makeDate (1984 :* 7 *: 3))
2432make_date(1984, 7, 3)
2395make_date(1984, 7, 3)
2433-}
2396-}
2434−makeDate
2397+makeDate :: FunctionHet
2435− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2398+ '[ null 'PGint4, null 'PGint4, null 'PGint4 ]
2436− -- ^ year
2399+ ( null 'PGdate )
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" <>
2400+makeDate = unsafeFunctionHet "make_date"
2443− parenthesized (renderCommaSeparated renderSQL (y :* m :* d :* Nil))
2444
2401
2445{-|
2402{-|
2446Create time from hour, minute and seconds fields
2403Create time from hour, minute and seconds fields
2447
2404
2448−>>> printSQL (makeTime 8 15 23.5)
2405+>>> printSQL (makeTime (8 :* 15 *: 23.5))
2449make_time(8, 15, 23.5)
2406make_time(8, 15, 23.5)
2450-}
2407-}
2451−makeTime
2408+makeTime :: FunctionHet
2452− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2409+ '[ null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2453− -- ^ hour
2410+ ( null 'PGtime )
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" <>
2411+makeTime = unsafeFunctionHet "make_time"
2460− parenthesized (renderCommaSeparated renderSQL (h :* m :* s :* Nil))
2461
2412
2462{-|
2413{-|
2463Create timestamp from year, month, day, hour, minute and seconds fields
2414Create timestamp from year, month, day, hour, minute and seconds fields
2464
2415
2465−>>> printSQL (makeTimestamp 2013 7 15 8 15 23.5)
2416+>>> printSQL (makeTimestamp (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
2466make_timestamp(2013, 7, 15, 8, 15, 23.5)
2417make_timestamp(2013, 7, 15, 8, 15, 23.5)
2467-}
2418-}
2468−makeTimestamp
2419+makeTimestamp :: FunctionHet
2469− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2420+ '[ null 'PGint4, null 'PGint4, null 'PGint4
2470− -- ^ year
2421+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2471− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2422+ ( null 'PGtimestamp )
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 =
2423+makeTimestamp = unsafeFunctionHet "make_timestamp"
2483− UnsafeExpression $ "make_timestamp" <> parenthesized
2484− (renderCommaSeparated renderSQL (y :* mon :* d :* h :* m :* s :* Nil))
2485
2424
2486{-|
2425{-|
2487Create timestamp with time zone from
2426Create timestamp with time zone from
2488year, month, day, hour, minute and seconds fields;
2427year, month, day, hour, minute and seconds fields;
2489the current time zone is used
2428the current time zone is used
2490
2429
2491−>>> printSQL (makeTimestamptz 2013 7 15 8 15 23.5)
2430+>>> printSQL (makeTimestamptz (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
2492make_timestamptz(2013, 7, 15, 8, 15, 23.5)
2431make_timestamptz(2013, 7, 15, 8, 15, 23.5)
2493-}
2432-}
2494−makeTimestamptz
2433+makeTimestamptz :: FunctionHet
2495− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2434+ '[ null 'PGint4, null 'PGint4, null 'PGint4
2496− -- ^ year
2435+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2497− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2436+ ( null 'PGtimestamptz )
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 =
2437+makeTimestamptz = unsafeFunctionHet "make_timestamptz"
2509− UnsafeExpression $ "make_timestamptz" <> parenthesized
2510− (renderCommaSeparated renderSQL (y :* mon :* d :* h :* m :* s :* Nil))
2511
2438
2512{-|
2439{-|
2513Affine space operations on time types.
2440Affine space operations on time types.
2514-}
2441-}
2515class TimeOp time diff | time -> diff where
2442class TimeOp time diff | time -> diff where
2516 {-|
2443 {-|
2517− >>> printSQL (makeDate 1984 7 3 !+ 365)
2444+ >>> printSQL (makeDate (1984 :* 7 *: 3) !+ 365)
2518 (make_date(1984, 7, 3) + 365)
2445 (make_date(1984, 7, 3) + 365)
2519 -}
2446 -}
2520− (!+) :: Operator (nullity time) (nullity diff) (nullity time)
2447+ (!+) :: Operator (null time) (null diff) (null time)
2521 (!+) = unsafeBinaryOp "+"
2448 (!+) = unsafeBinaryOp "+"
2522 {-|
2449 {-|
2523− >>> printSQL (365 +! makeDate 1984 7 3)
2450+ >>> printSQL (365 +! makeDate (1984 :* 7 *: 3))
2524 (365 + make_date(1984, 7, 3))
2451 (365 + make_date(1984, 7, 3))
2525 -}
2452 -}
2526− (+!) :: Operator (nullity diff) (nullity time) (nullity time)
2453+ (+!) :: Operator (null diff) (null time) (null time)
2527 (+!) = unsafeBinaryOp "+"
2454 (+!) = unsafeBinaryOp "+"
2528 {-|
2455 {-|
2529− >>> printSQL (makeDate 1984 7 3 !- 365)
2456+ >>> printSQL (makeDate (1984 :* 7 *: 3) !- 365)
2530 (make_date(1984, 7, 3) - 365)
2457 (make_date(1984, 7, 3) - 365)
2531 -}
2458 -}
2532− (!-) :: Operator (nullity time) (nullity diff) (nullity time)
2459+ (!-) :: Operator (null time) (null diff) (null time)
2533 (!-) = unsafeBinaryOp "-"
2460 (!-) = unsafeBinaryOp "-"
2534 {-|
2461 {-|
2535− >>> printSQL (makeDate 1984 7 3 !-! currentDate)
2462+ >>> printSQL (makeDate (1984 :* 7 *: 3) !-! currentDate)
2536 (make_date(1984, 7, 3) - CURRENT_DATE)
2463 (make_date(1984, 7, 3) - CURRENT_DATE)
2537 -}
2464 -}
2538− (!-!) :: Operator (nullity time) (nullity time) (nullity diff)
2465+ (!-!) :: Operator (null time) (null time) (null diff)
2539 (!-!) = unsafeBinaryOp "-"
2466 (!-!) = unsafeBinaryOp "-"
2540instance TimeOp 'PGtimestamp 'PGinterval
2467instance TimeOp 'PGtimestamp 'PGinterval
2541instance TimeOp 'PGtimestamptz 'PGinterval
2468instance TimeOp 'PGtimestamptz 'PGinterval
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4
@@ -91,6 +91,7 @@ module Squeal.PostgreSQL.Schema
91 , Elem
91 , Elem
92 , In
92 , In
93 , Length
93 , Length
94+ , (*:)
94 -- * Type Classifications
95 -- * Type Classifications
95 , HasOid (..)
96 , HasOid (..)
96 , PGNum
97 , PGNum
@@ -786,3 +787,6 @@ instance (forall t0 t1. RenderSQL (p t0 t1))
786-- | A `single` step.
787-- | A `single` step.
787single :: p x0 x1 -> AlignedList p x0 x1
788single :: p x0 x1 -> AlignedList p x0 x1
788single step = step :>> Done
789single step = step :>> Done
790+
791+(*:) :: f x -> f y -> NP f '[x,y]
792+x *: y = x :* y :* Nil