@@ -93,13 +93,6 @@ module Squeal.PostgreSQL.Query
9393 , By (..)
9494 , GroupByClause (..)
9595 , HavingClause (..)
96− -- * Subquery Expressions
97− , exists
98− , in_
99− , notIn
100− , Operator
101− , subAll
102− , subAny
10396 ) where
10497
10598import Control.DeepSeq
@@ -1093,90 +1086,6 @@ instance RenderSQL (HavingClause outer commons grp schemas params from) where
10931086 Having conditions ->
10941087 " HAVING" <+> commaSeparated (renderSQL <$> conditions)
10951088
1096−{- |
1097−The argument of `exists` is an arbitrary subquery. The subquery is evaluated
1098−to determine whether it returns any rows. If it returns at least one row,
1099−the result of `exists` is `true`; if the subquery returns no rows,
1100−the result of `exists` is `false`.
1101−
1102−The subquery can refer to variables from the surrounding query,
1103−which will act as constants during any one evaluation of the subquery.
1104−
1105−The subquery will generally only be executed long enough to determine whether
1106−at least one row is returned, not all the way to completion.
1107−-}
1108−exists
1109− :: Query (Join outer from) commons schemas params row
1110− -> Condition outer commons grp schemas params from
1111−exists query = UnsafeExpression $ "EXISTS" <+> parenthesized (renderSQL query)
1112−
1113−{- |
1114−The right-hand side is a parenthesized subquery, which must return
1115−exactly one column. The left-hand expression is evaluated and compared to each
1116−row of the subquery result using the given `Operator`,
1117−which must yield a Boolean result. The result of `subAll` is `true`
1118−if all rows yield true (including the case where the subquery returns no rows).
1119−The result is `false` if any `false` result is found.
1120−The result is `null_` if no comparison with a subquery row returns `false`,
1121−and at least one comparison returns `null_`.
1122−
1123−>>> printSQL $ subAll true (.==) (values_ (true `as` #foo))
1124−(TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo")))
1125−-}
1126−subAll
1127− :: Expression outer commons grp schemas params from ty1 -- ^ expression
1128− -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
1129− -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
1130− -> Condition outer commons grp schemas params from
1131−subAll expr (?) qry = expr ?
1132− (UnsafeExpression $ "ALL" <+> parenthesized (renderSQL qry))
1133−
1134−{- |
1135−The right-hand side is a parenthesized subquery, which must return exactly one column.
1136−The left-hand expression is evaluated and compared to each row of the subquery result
1137−using the given `Operator`, which must yield a Boolean result. The result of `subAny` is `true`
1138−if any `true` result is obtained. The result is `false` if no true result is found
1139−(including the case where the subquery returns no rows).
1140−
1141−>>> printSQL $ subAll "foo" like (values_ ("foobar" `as` #foo))
1142−(E'foo' LIKE ALL (SELECT * FROM (VALUES (E'foobar')) AS t ("foo")))
1143−-}
1144−subAny
1145− :: Expression outer commons grp schemas params from ty1 -- ^ expression
1146− -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
1147− -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
1148− -> Condition outer commons grp schemas params from
1149−subAny expr (?) qry = expr ?
1150− (UnsafeExpression $ "ANY" <+> parenthesized (renderSQL qry))
1151−
1152−{- |
1153−The result is `true` if the left-hand expression's result is equal
1154−to any of the right-hand expressions.
1155−
1156−>>> printSQL $ true `in_` [true, false, null_]
1157−TRUE IN (TRUE, FALSE, NULL)
1158−-}
1159−in_
1160− :: Expression outer commons grp schemas params from ty -- ^ expression
1161− -> [Expression outer commons grp schemas params from ty]
1162− -> Condition outer commons grp schemas params from
1163−expr `in_` exprs = UnsafeExpression $ renderSQL expr <+> "IN"
1164− <+> parenthesized (commaSeparated (renderSQL <$> exprs))
1165−
1166−{- |
1167−The result is `true` if the left-hand expression's result is not equal
1168−to any of the right-hand expressions.
1169−
1170−>>> printSQL $ true `notIn` [false, null_]
1171−TRUE NOT IN (FALSE, NULL)
1172−-}
1173−notIn
1174− :: Expression outer commons grp schemas params from ty -- ^ expression
1175− -> [Expression outer commons grp schemas params from ty]
1176− -> Condition outer commons grp schemas params from
1177−expr `notIn` exprs = UnsafeExpression $ renderSQL expr <+> "NOT IN"
1178− <+> parenthesized (commaSeparated (renderSQL <$> exprs))
1179−
11801089-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
11811090data CommonTableExpression statement
11821091 (schemas :: SchemasType)