on master help sign in
Document Query.Set
a7e9e9eOllie Charles
src/Rel8/Query/Set.hs+30
@@ -22,25 +22,55 @@ import Rel8.Table.Opaleye ( binaryspec )
22import Rel8.Schema.Context ( DB )
22import Rel8.Schema.Context ( DB )
23
23
24
24
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@.
27+--
28+-- >>> select c $ values [lit True, lit True, lit False] `union` values [lit True]
29+-- [False,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)
27
32
28
33
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@.
36+--
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)
31
41
32
42
43+-- | Find the intersection of two queries, collapsing duplicates. @intersect a
44+-- b@ is the same as the SQL statement @x INTERSECT b@.
45+--
46+-- >>> select c $ values [lit True, lit True, lit False] `intersect` values [lit True]
47+-- [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)
35
50
36
51
52+-- | Find the intersection of two queries, retaining duplicates. @intersectAll
53+-- a b@ is the same as the SQL statement @x INTERSECT ALL b@.
54+--
55+-- >>> select c $ values [lit True, lit True, lit False] `intersectAll` values [lit True, lit True]
56+-- [True,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)
39
59
40
60
61+-- | Find the difference of two queries, collapsing duplicates @except a b@ is
62+-- the same as the SQL statement @x INTERSECT b@.
63+--
64+-- >>> select c $ values [lit True, lit False, lit False] `except` values [lit True]
65+-- [False]
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)
43
68
44
69
70+-- | Find the difference of two queries, retaining duplicates. @exceptAll a b@
71+-- is the same as the SQL statement @x EXCEPT ALL b@.
72+--
73+-- >>> select c $ values [lit True, lit False, lit False] `exceptAll` values [lit True]
74+-- [False,False]
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)