on master help sign in
Document Query.Set
commita7e9e9e70b10f14e1187e13513ea34c267666191 authorOllie Charles <ollie@ocharles.org.uk> dateTue 23 Mar 2021, 16:20 (6 years ago) parent134ddcf
1 file changed+30
src/Rel8/Query/Set.hs+30
src/Rel8/Query/Set.hs+30
@@ -22,25 +22,55 @@ import Rel8.Table.Opaleye ( binaryspec )
2222import Rel8.Schema.Context ( DB )
2323
2424
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]
2530union :: EqTable a => Query a -> Query a -> Query a
2631union = zipOpaleyeWith (Opaleye.unionExplicit binaryspec)
2732
2833
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]
2939unionAll :: Table DB a => Query a -> Query a -> Query a
3040unionAll = zipOpaleyeWith (Opaleye.unionAllExplicit binaryspec)
3141
3242
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]
3348intersect :: EqTable a => Query a -> Query a -> Query a
3449intersect = zipOpaleyeWith (Opaleye.intersectExplicit binaryspec)
3550
3651
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]
3757intersectAll :: Table DB a => Query a -> Query a -> Query a
3858intersectAll = zipOpaleyeWith (Opaleye.intersectAllExplicit binaryspec)
3959
4060
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]
4166except :: EqTable a => Query a -> Query a -> Query a
4267except = zipOpaleyeWith (Opaleye.exceptExplicit binaryspec)
4368
4469
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]
4575exceptAll :: Table DB a => Query a -> Query a -> Query a
4676exceptAll = zipOpaleyeWith (Opaleye.exceptAllExplicit binaryspec)