on dev help sign in
3vl
f7aedefEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+41−42
@@ -351,7 +351,7 @@ null_ = UnsafeExpression "NULL"
351
351
352-- | analagous to `Just`
352-- | analagous to `Just`
353--
353--
354−-- >>> printSQL $ notNull true
354+-- >>> printSQL $ true
355-- TRUE
355-- TRUE
356notNull
356notNull
357 :: Expression schema rels grouping params ('NotNull ty)
357 :: Expression schema rels grouping params ('NotNull ty)
@@ -360,7 +360,7 @@ notNull = UnsafeExpression . renderExpression
360
360
361-- | return the leftmost value which is not NULL
361-- | return the leftmost value which is not NULL
362--
362--
363−-- >>> printSQL $ coalesce [null_, notNull true] false
363+-- >>> printSQL $ coalesce [null_, true] false
364-- COALESCE(NULL, TRUE, FALSE)
364-- COALESCE(NULL, TRUE, FALSE)
365coalesce
365coalesce
366 :: [Expression schema relations grouping params ('Null ty)]
366 :: [Expression schema relations grouping params ('Null ty)]
@@ -431,7 +431,7 @@ nullIf
431nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
431nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
432 (renderExpression x <> ", " <> renderExpression y)
432 (renderExpression x <> ", " <> renderExpression y)
433
433
434−-- | >>> printSQL $ array [null_, notNull false, notNull true]
434+-- | >>> printSQL $ array [null_, false, true]
435-- ARRAY[NULL, FALSE, TRUE]
435-- ARRAY[NULL, FALSE, TRUE]
436array
436array
437 :: [Expression schema relations grouping params ty]
437 :: [Expression schema relations grouping params ty]
@@ -693,28 +693,27 @@ ceiling_
693 -> Expression schema relations grouping params (nullity frac)
693 -> Expression schema relations grouping params (nullity frac)
694ceiling_ = unsafeFunction "ceiling"
694ceiling_ = unsafeFunction "ceiling"
695
695
696−-- | A `Condition` is a boolean valued `Expression`. While SQL allows
696+-- | A `Condition` is an `Expression`, which can evaluate
697−-- conditions to have @NULL@, Squeal instead chooses to disallow @NULL@,
697+-- to `TRUE`, `FALSE` or `NULL`. This is because SQL uses
698−-- forcing one to handle the case of @NULL@ explicitly to produce
698+-- a three valued logic.
699−-- a `Condition`.
700type Condition schema relations grouping params =
699type Condition schema relations grouping params =
701− Expression schema relations grouping params ('NotNull 'PGbool)
700+ Expression schema relations grouping params ('Null 'PGbool)
702
701
703-- | >>> printSQL true
702-- | >>> printSQL true
704-- TRUE
703-- TRUE
705−true :: Condition schema relations grouping params
704+true :: Expression schema relations grouping params (nullity 'PGbool)
706true = UnsafeExpression "TRUE"
705true = UnsafeExpression "TRUE"
707
706
708-- | >>> printSQL false
707-- | >>> printSQL false
709-- FALSE
708-- FALSE
710−false :: Condition schema relations grouping params
709+false :: Expression schema relations grouping params (nullity 'PGbool)
711false = UnsafeExpression "FALSE"
710false = UnsafeExpression "FALSE"
712
711
713-- | >>> printSQL $ not_ true
712-- | >>> printSQL $ not_ true
714-- (NOT TRUE)
713-- (NOT TRUE)
715not_
714not_
716− :: Condition schema relations grouping params
715+ :: Expression schema relations grouping params (nullity 'PGbool)
717− -> Condition schema relations grouping params
716+ -> Expression schema relations grouping params (nullity 'PGbool)
718not_ = unsafeUnaryOp "NOT"
717not_ = unsafeUnaryOp "NOT"
719
718
720-- | >>> printSQL $ true .&& false
719-- | >>> printSQL $ true .&& false
@@ -742,12 +741,12 @@ not_ = unsafeUnaryOp "NOT"
742-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
741-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
743caseWhenThenElse
742caseWhenThenElse
744 :: [ ( Condition schema relations grouping params
743 :: [ ( Condition schema relations grouping params
745− , Expression schema relations grouping params (ty)
744+ , Expression schema relations grouping params ty
746 ) ]
745 ) ]
747 -- ^ whens and thens
746 -- ^ whens and thens
748− -> Expression schema relations grouping params (ty)
747+ -> Expression schema relations grouping params ty
749 -- ^ else
748 -- ^ else
750− -> Expression schema relations grouping params (ty)
749+ -> Expression schema relations grouping params ty
751caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
750caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
752 [ "CASE"
751 [ "CASE"
753 , mconcat
752 , mconcat
@@ -770,65 +769,65 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
770-- CASE WHEN TRUE THEN 1 ELSE 0 END
769-- CASE WHEN TRUE THEN 1 ELSE 0 END
771ifThenElse
770ifThenElse
772 :: Condition schema relations grouping params
771 :: Condition schema relations grouping params
773− -> Expression schema relations grouping params (ty) -- ^ then
772+ -> Expression schema relations grouping params ty -- ^ then
774− -> Expression schema relations grouping params (ty) -- ^ else
773+ -> Expression schema relations grouping params ty -- ^ else
775− -> Expression schema relations grouping params (ty)
774+ -> Expression schema relations grouping params ty
776ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
775ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
777
776
778-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
777-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
779-- will produce @NULL@s if one of their arguments is @NULL@.
778-- will produce @NULL@s if one of their arguments is @NULL@.
780--
779--
781−-- >>> printSQL $ notNull true .== null_
780+-- >>> printSQL $ true .== null_
782-- (TRUE = NULL)
781-- (TRUE = NULL)
783(.==)
782(.==)
784− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
783+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
785− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
784+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
786− -> Expression schema relations grouping params (nullity 'PGbool)
785+ -> Condition schema relations grouping params
787(.==) = unsafeBinaryOp "="
786(.==) = unsafeBinaryOp "="
788infix 4 .==
787infix 4 .==
789
788
790−-- | >>> printSQL $ notNull true ./= null_
789+-- | >>> printSQL $ true ./= null_
791-- (TRUE <> NULL)
790-- (TRUE <> NULL)
792(./=)
791(./=)
793− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
792+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
794− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
793+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
795− -> Expression schema relations grouping params (nullity 'PGbool)
794+ -> Condition schema relations grouping params
796(./=) = unsafeBinaryOp "<>"
795(./=) = unsafeBinaryOp "<>"
797infix 4 ./=
796infix 4 ./=
798
797
799−-- | >>> printSQL $ notNull true .>= null_
798+-- | >>> printSQL $ true .>= null_
800-- (TRUE >= NULL)
799-- (TRUE >= NULL)
801(.>=)
800(.>=)
802− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
801+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
803− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
802+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
804− -> Expression schema relations grouping params (nullity 'PGbool)
803+ -> Condition schema relations grouping params
805(.>=) = unsafeBinaryOp ">="
804(.>=) = unsafeBinaryOp ">="
806infix 4 .>=
805infix 4 .>=
807
806
808−-- | >>> printSQL $ notNull true .< null_
807+-- | >>> printSQL $ true .< null_
809-- (TRUE < NULL)
808-- (TRUE < NULL)
810(.<)
809(.<)
811− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
810+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
812− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
811+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
813− -> Expression schema relations grouping params (nullity 'PGbool)
812+ -> Condition schema relations grouping params
814(.<) = unsafeBinaryOp "<"
813(.<) = unsafeBinaryOp "<"
815infix 4 .<
814infix 4 .<
816
815
817−-- | >>> printSQL $ notNull true .<= null_
816+-- | >>> printSQL $ true .<= null_
818-- (TRUE <= NULL)
817-- (TRUE <= NULL)
819(.<=)
818(.<=)
820− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
819+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
821− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
820+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
822− -> Expression schema relations grouping params (nullity 'PGbool)
821+ -> Condition schema relations grouping params
823(.<=) = unsafeBinaryOp "<="
822(.<=) = unsafeBinaryOp "<="
824infix 4 .<=
823infix 4 .<=
825
824
826−-- | >>> printSQL $ notNull true .> null_
825+-- | >>> printSQL $ true .> null_
827-- (TRUE > NULL)
826-- (TRUE > NULL)
828(.>)
827(.>)
829− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
828+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
830− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
829+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
831− -> Expression schema relations grouping params (nullity 'PGbool)
830+ -> Condition schema relations grouping params
832(.>) = unsafeBinaryOp ">"
831(.>) = unsafeBinaryOp ">"
833infix 4 .>
832infix 4 .>
834
833