@@ -22,25 +22,55 @@ import Rel8.Table.Opaleye ( binaryspec )
22import Rel8.Schema.Context ( DB )
22import Rel8.Schema.Context ( DB )
25+-- | Combine the results of two queries of the same type, collapsing
26+-- duplicates. @union a b@ is the same as the SQL statement @x UNION b@.
28+-- >>> select c $ values [lit True, lit True, lit False] `union` values [lit True]
25union :: EqTable a => Query a -> Query a -> Query a
30union :: EqTable a => Query a -> Query a -> Query a
26union = zipOpaleyeWith (Opaleye.unionExplicit binaryspec)
31union = zipOpaleyeWith (Opaleye.unionExplicit binaryspec)
34+-- | Combine the results of two queries of the same type, retaining duplicates.
35+-- @unionAll a b@ is the same as the SQL statement @x UNION ALL b@.
37+-- >>> select c $ values [lit True, lit True, lit False] `unionAll` values [lit True]
38+-- [True,True,False,True]
29unionAll :: Table DB a => Query a -> Query a -> Query a
39unionAll :: Table DB a => Query a -> Query a -> Query a
30unionAll = zipOpaleyeWith (Opaleye.unionAllExplicit binaryspec)
40unionAll = zipOpaleyeWith (Opaleye.unionAllExplicit binaryspec)
43+-- | Find the intersection of two queries, collapsing duplicates. @intersect a
44+-- b@ is the same as the SQL statement @x INTERSECT b@.
46+-- >>> select c $ values [lit True, lit True, lit False] `intersect` values [lit True]
33intersect :: EqTable a => Query a -> Query a -> Query a
48intersect :: EqTable a => Query a -> Query a -> Query a
34intersect = zipOpaleyeWith (Opaleye.intersectExplicit binaryspec)
49intersect = zipOpaleyeWith (Opaleye.intersectExplicit binaryspec)
52+-- | Find the intersection of two queries, retaining duplicates. @intersectAll
53+-- a b@ is the same as the SQL statement @x INTERSECT ALL b@.
55+-- >>> select c $ values [lit True, lit True, lit False] `intersectAll` values [lit True, lit True]
37intersectAll :: Table DB a => Query a -> Query a -> Query a
57intersectAll :: Table DB a => Query a -> Query a -> Query a
38intersectAll = zipOpaleyeWith (Opaleye.intersectAllExplicit binaryspec)
58intersectAll = zipOpaleyeWith (Opaleye.intersectAllExplicit binaryspec)
61+-- | Find the difference of two queries, collapsing duplicates @except a b@ is
62+-- the same as the SQL statement @x INTERSECT b@.
64+-- >>> select c $ values [lit True, lit False, lit False] `except` values [lit True]
41except :: EqTable a => Query a -> Query a -> Query a
66except :: EqTable a => Query a -> Query a -> Query a
42except = zipOpaleyeWith (Opaleye.exceptExplicit binaryspec)
67except = zipOpaleyeWith (Opaleye.exceptExplicit binaryspec)
70+-- | Find the difference of two queries, retaining duplicates. @exceptAll a b@
71+-- is the same as the SQL statement @x EXCEPT ALL b@.
73+-- >>> select c $ values [lit True, lit False, lit False] `exceptAll` values [lit True]
45exceptAll :: Table DB a => Query a -> Query a -> Query a
75exceptAll :: Table DB a => Query a -> Query a -> Query a
46exceptAll = zipOpaleyeWith (Opaleye.exceptAllExplicit binaryspec)
76exceptAll = zipOpaleyeWith (Opaleye.exceptAllExplicit binaryspec)