@@ -73,49 +73,70 @@ sge = \case
7373 NonNullable -> ge
7474
7575
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 '(<?)'.
7679(<.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
7780(<.) = slt nullabilization
7881infix 4 <.
7982
8083
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 '(<=?)'.
8287(<=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
8388(<=.) = sle nullabilization
8489infix 4 <=.
8590
8691
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 '(>?)'.
8895(>.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
8996(>.) = sgt nullabilization
9097infix 4 >.
9198
9299
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 '(>=?)'.
94103(>=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
95104(>=.) = sge nullabilization
96105infix 4 >=.
97106
98107
108+-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
109+-- are @null@.
99110(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
100111a <? b = coalesce $ unsafeLiftOpNullable lt a b
101112infix 4 <?
102113
103114
115+-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
116+-- are @null@.
104117(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
105118a <=? b = coalesce $ unsafeLiftOpNullable le a b
106119infix 4 <=?
107120
108121
122+-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
123+-- are @null@.
109124(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
110125a >? b = coalesce $ unsafeLiftOpNullable gt a b
111126infix 4 >?
112127
113128
129+-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
130+-- are @null@.
114131(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
115132a >=? b = coalesce $ unsafeLiftOpNullable ge a b
116133infix 4 >=?
117134
118135
136+-- | Given two expressions, return the expression that sorts less than the
137+-- other.
138+--
139+-- Corresponds to the SQL @least()@ function.
119140leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
120141leastExpr ma mb = case nullabilization @a of
121142 Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
@@ -124,6 +145,10 @@ leastExpr ma mb = case nullabilization @a of
124145 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
125146
126147
148+-- | Given two expressions, return the expression that sorts greater than the
149+-- other.
150+--
151+-- Corresponds to the SQL @greatest()@ function.
127152greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
128153greatestExpr ma mb = case nullabilization @a of
129154 Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma