@@ -73,49 +73,70 @@ sge = \case
73 NonNullable -> ge
73 NonNullable -> ge
76+-- | Corresponds to the SQL @<@ operator. Note that this differs from SQL @<@
77+-- as @null@ will sort below any other value. For a version of @<@ that exactly
78+-- matches SQL, see '(<?)'.
76(<.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
79(<.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
77(<.) = slt nullabilization
80(<.) = slt nullabilization
81−-- | The PostgreSQL @<=@ operator.
84+-- | Corresponds to the SQL @<=@ operator. Note that this differs from SQL @<=@
85+-- as @null@ will sort below any other value. For a version of @<=@ that exactly
86+-- matches SQL, see '(<=?)'.
82(<=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
87(<=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
83(<=.) = sle nullabilization
88(<=.) = sle nullabilization
84infix 4 <=.
89infix 4 <=.
87−-- | The PostgreSQL @>@ operator.
92+-- | Corresponds to the SQL @>@ operator. Note that this differs from SQL @>@
93+-- as @null@ will sort below any other value. For a version of @>@ that exactly
94+-- matches SQL, see '(>?)'.
88(>.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
95(>.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
89(>.) = sgt nullabilization
96(>.) = sgt nullabilization
93−-- | The PostgreSQL @>=@ operator.
100+-- | Corresponds to the SQL @>=@ operator. Note that this differs from SQL @>@
101+-- as @null@ will sort below any other value. For a version of @>=@ that
102+-- exactly matches SQL, see '(>=?)'.
94(>=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
103(>=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
95(>=.) = sge nullabilization
104(>=.) = sge nullabilization
96infix 4 >=.
105infix 4 >=.
108+-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
99(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
110(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
100a <? b = coalesce $ unsafeLiftOpNullable lt a b
111a <? b = coalesce $ unsafeLiftOpNullable lt a b
101infix 4 <?
112infix 4 <?
115+-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
104(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
117(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
105a <=? b = coalesce $ unsafeLiftOpNullable le a b
118a <=? b = coalesce $ unsafeLiftOpNullable le a b
106infix 4 <=?
119infix 4 <=?
122+-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
109(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
124(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
110a >? b = coalesce $ unsafeLiftOpNullable gt a b
125a >? b = coalesce $ unsafeLiftOpNullable gt a b
111infix 4 >?
126infix 4 >?
129+-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
114(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
131(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
115a >=? b = coalesce $ unsafeLiftOpNullable ge a b
132a >=? b = coalesce $ unsafeLiftOpNullable ge a b
116infix 4 >=?
133infix 4 >=?
136+-- | Given two expressions, return the expression that sorts less than the
139+-- Corresponds to the SQL @least()@ function.
119leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
140leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
120leastExpr ma mb = case nullabilization @a of
141leastExpr ma mb = case nullabilization @a of
121 Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
142 Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
@@ -124,6 +145,10 @@ leastExpr ma mb = case nullabilization @a of
124 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
145 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
148+-- | Given two expressions, return the expression that sorts greater than the
151+-- Corresponds to the SQL @greatest()@ function.
127greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
152greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
128greatestExpr ma mb = case nullabilization @a of
153greatestExpr ma mb = case nullabilization @a of
129 Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
154 Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma