on dev help sign in
simplify subAny/subAll
commit7e3913dd0bc48cd95e6b55df032879943e105958 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateThu 21 Feb 2019, 09:37 (8 years ago) parent80fe4f5
1 file changed+6−16
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+6−16
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+6−16
@@ -107,7 +107,6 @@ import Data.Word
107107import Generics.SOP hiding (from)
108108import GHC.TypeLits
109109
110−import qualified Data.ByteString as ByteString
111110import qualified GHC.Generics as GHC
112111
113112import Squeal.PostgreSQL.Expression
@@ -1091,21 +1090,15 @@ The result is `null_` if no comparison with a subquery row returns `false`,
10911090and at least one comparison returns `null_`.
10921091
10931092>>> printSQL $ subAll true (.==) (values_ (true `as` #foo))
1094−TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1093+(TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo")))
10951094-}
10961095subAll
10971096 :: Expression outer grp commons schemas params from ty1 -- ^ expression
10981097 -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
10991098 -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
11001099 -> Condition outer grp commons schemas params from
1101−subAll expr (?) qry = UnsafeExpression $
1102− renderSQL expr <> op <> "ALL" <+> parenthesized (renderSQL qry)
1103− where
1104− nil = UnsafeExpression ""
1105− op = ByteString.init
1106− . ByteString.tail
1107− . renderSQL
1108− $ nil ? nil
1100+subAll expr (?) qry = expr ?
1101+ (UnsafeExpression $ "ALL" <+> parenthesized (renderSQL qry))
11091102
11101103{- |
11111104The right-hand side is a parenthesized subquery, which must return exactly one column.
@@ -1115,18 +1108,15 @@ if any `true` result is obtained. The result is `false` if no true result is fou
11151108(including the case where the subquery returns no rows).
11161109
11171110>>> printSQL $ subAll "foo" like (values_ ("foobar" `as` #foo))
1118−E'foo' LIKE ALL (SELECT * FROM (VALUES (E'foobar')) AS t ("foo"))
1111+(E'foo' LIKE ALL (SELECT * FROM (VALUES (E'foobar')) AS t ("foo")))
11191112-}
11201113subAny
11211114 :: Expression outer grp commons schemas params from ty1 -- ^ expression
11221115 -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
11231116 -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
11241117 -> Condition outer grp commons schemas params from
1125−subAny expr (?) qry = UnsafeExpression $
1126− renderSQL expr <+> renderSQL (nil ? nil) <+> "ANY"
1127− <+> parenthesized (renderSQL qry)
1128− where
1129− nil = UnsafeExpression ""
1118+subAny expr (?) qry = expr ?
1119+ (UnsafeExpression $ "ANY" <+> parenthesized (renderSQL qry))
11301120
11311121{-
11321122The result is `true` if the left-hand expression's result is equal