on dev help sign in
haddocks and subquery expressions
commit31bfd2ab853235bd49e65ef8b382bf17baf59c8f authorEitan Chatav <eitan.chatav@gmail.com> dateWed 5 Sep 2018, 11:51 (8 years ago) parentf740d3f
2 files changed+236−225
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+1 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+235−225
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+1
@@ -625,6 +625,7 @@ resultErrorCode
625625 -> io (Maybe ByteString)
626626resultErrorCode = liftResult (flip LibPQ.resultErrorField LibPQ.DiagSqlstate)
627627
628+-- | `Exception`s that can be thrown by Squeal.
628629data SquealException
629630 = PQException
630631 { sqlExecStatus :: LibPQ.ExecStatus
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+235−225
@@ -29,31 +29,28 @@ Squeal queries.
2929module Squeal.PostgreSQL.Query
3030 ( -- * Queries
3131 Query (UnsafeQuery, renderQuery)
32− , union
33− , unionAll
34− , intersect
35− , intersectAll
36− , except
37− , exceptAll
38− -- * Select
32+ -- ** Select
3933 , select
4034 , selectDistinct
4135 , selectStar
4236 , selectDistinctStar
4337 , selectDotStar
4438 , selectDistinctDotStar
39+ -- ** Values
4540 , values
4641 , values_
47− -- * Table Expressions
48− , TableExpression (..)
49− , renderTableExpression
50− , from
51− , where_
52− , groupBy
53− , having
54− , orderBy
55− , limit
56− , offset
42+ -- ** Set Operations
43+ , union
44+ , unionAll
45+ , intersect
46+ , intersectAll
47+ , except
48+ , exceptAll
49+ -- ** With
50+ , With (with)
51+ , CommonTableExpression (..)
52+ , renderCommonTableExpression
53+ , renderCommonTableExpressions
5754 -- ** Json
5855 , jsonEach
5956 , jsonbEach
@@ -69,7 +66,17 @@ module Squeal.PostgreSQL.Query
6966 , jsonbToRecord
7067 , jsonToRecordSet
7168 , jsonbToRecordSet
72− -- * From
69+ -- * Table Expressions
70+ , TableExpression (..)
71+ , renderTableExpression
72+ , from
73+ , where_
74+ , groupBy
75+ , having
76+ , orderBy
77+ , limit
78+ , offset
79+ -- * From Clauses
7380 , FromClause (..)
7481 , table
7582 , subquery
@@ -89,38 +96,33 @@ module Squeal.PostgreSQL.Query
8996 -- * Sorting
9097 , SortExpression (..)
9198 , renderSortExpression
92− -- * Subquery expressions
99+ -- * Subquery Expressions
93100 , in_
94101 , rowIn
95− , allEq
96− , rowAllEq
97− , anyEq
98− , rowAnyEq
99− , allNeq
100− , rowAllNeq
101− , anyNeq
102− , rowAnyNeq
102+ , eqAll
103+ , rowEqAll
104+ , eqAny
105+ , rowEqAny
106+ , neqAll
107+ , rowNeqAll
108+ , neqAny
109+ , rowNeqAny
103110 , allLt
104− , rowAllLt
105− , anyLt
106− , rowAnyLt
107− , allLte
108− , rowAllLte
109− , anyLte
110− , rowAnyLte
111− , allGt
112− , rowAllGt
113− , anyGt
114− , rowAnyGt
115− , allGte
116− , rowAllGte
117− , anyGte
118− , rowAnyGte
119− -- * With
120− , With (with)
121− , CommonTableExpression (..)
122− , renderCommonTableExpression
123− , renderCommonTableExpressions
111+ , rowLtAll
112+ , ltAny
113+ , rowLtAny
114+ , lteAll
115+ , rowLteAll
116+ , lteAny
117+ , rowLteAny
118+ , gtAll
119+ , rowGtAll
120+ , gtAny
121+ , rowGtAny
122+ , gteAll
123+ , rowGteAll
124+ , gteAny
125+ , rowGteAny
124126 ) where
125127
126128import Control.DeepSeq
@@ -139,9 +141,7 @@ import Squeal.PostgreSQL.Schema
139141
140142{- |
141143The process of retrieving or the command to retrieve data from a database
142−is called a `Query`. The `select`, `selectStar`, `selectDotStar`,
143−`selectDistinct`, `selectDistinctStar` and `selectDistinctDotStar` commands
144−are used to specify queries.
144+is called a `Query`. Let's see some examples of queries.
145145
146146simple query:
147147
@@ -312,6 +312,16 @@ in printSQL query
312312:}
313313SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
314314
315+value queries:
316+
317+>>> :{
318+let
319+ query :: Query '[] '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
320+ query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]
321+in printSQL query
322+:}
323+SELECT * FROM (VALUES (1, TRUE), (2, FALSE)) AS t ("foo", "bar")
324+
315325set operations:
316326
317327>>> :{
@@ -708,41 +718,41 @@ unsafeSetOfFunction fun expr = UnsafeQuery $
708718
709719-- | Expands the outermost JSON object into a set of key/value pairs.
710720jsonEach
711− :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json
721+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
712722 -> Query schema params
713723 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
714724jsonEach = unsafeSetOfFunction "json_each"
715725
716726-- | Expands the outermost binary JSON object into a set of key/value pairs.
717727jsonbEach
718− :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb
728+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
719729 -> Query schema params
720730 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
721731jsonbEach = unsafeSetOfFunction "jsonb_each"
722732
723733-- | Expands the outermost JSON object into a set of key/value pairs.
724734jsonEachAsText
725− :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json
735+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
726736 -> Query schema params
727737 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
728738jsonEachAsText = unsafeSetOfFunction "json_each_text"
729739
730740-- | Expands the outermost binary JSON object into a set of key/value pairs.
731741jsonbEachAsText
732− :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb
742+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
733743 -> Query schema params
734744 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
735745jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
736746
737747-- | Returns set of keys in the outermost JSON object.
738748jsonObjectKeys
739− :: Expression schema '[] 'Ungrouped params (nullity 'PGjson)
749+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
740750 -> Query schema params '["json_object_keys" ::: 'NotNull 'PGtext]
741751jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
742752
743753-- | Returns set of keys in the outermost JSON object.
744754jsonbObjectKeys
745− :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
755+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
746756 -> Query schema params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
747757jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
748758
@@ -759,24 +769,24 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
759769-- | Expands the JSON expression to a row whose columns match the record
760770-- type defined by the given table.
761771jsonPopulateRecord
762− :: TypeExpression schema (nullity ('PGcomposite row))
763− -> Expression schema '[] 'Ungrouped params (nullity 'PGjson)
772+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
773+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
764774 -> Query schema params row
765775jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
766776
767777-- | Expands the binary JSON expression to a row whose columns match the record
768778-- type defined by the given table.
769779jsonbPopulateRecord
770− :: TypeExpression schema (nullity ('PGcomposite row))
771− -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
780+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
781+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
772782 -> Query schema params row
773783jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
774784
775785-- | Expands the outermost array of objects in the given JSON expression to a
776786-- set of rows whose columns match the record type defined by the given table.
777787jsonPopulateRecordSet
778− :: TypeExpression schema (nullity ('PGcomposite row))
779− -> Expression schema '[] 'Ungrouped params (nullity 'PGjson)
788+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
789+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
780790 -> Query schema params row
781791jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
782792
@@ -784,17 +794,17 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
784794-- to a set of rows whose columns match the record type defined by the given
785795-- table.
786796jsonbPopulateRecordSet
787− :: TypeExpression schema (nullity ('PGcomposite row))
788− -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
797+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
798+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
789799 -> Query schema params row
790800jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
791801
792802unsafeRecordFunction
793− :: (SListI row, json `In` PGJsonType)
803+ :: (SListI record, json `In` PGJsonType)
794804 => ByteString
795805 -> Expression schema '[] 'Ungrouped params (nullity json)
796− -> NP (Aliased (TypeExpression schema)) row
797− -> Query schema params row
806+ -> NP (Aliased (TypeExpression schema)) record
807+ -> Query schema params record
798808unsafeRecordFunction fun expr types = UnsafeQuery $
799809 "SELECT * FROM " <> fun <> "("
800810 <> renderExpression expr <> ")"
@@ -806,36 +816,34 @@ unsafeRecordFunction fun expr types = UnsafeQuery $
806816
807817-- | Builds an arbitrary record from a JSON object.
808818jsonToRecord
809− :: SListI row
810− => Expression schema '[] 'Ungrouped params (nullity 'PGjson)
811− -> NP (Aliased (TypeExpression schema)) row
812− -> Query schema params row
819+ :: SListI record
820+ => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
821+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
822+ -> Query schema params record
813823jsonToRecord = unsafeRecordFunction "json_to_record"
814824
815825-- | Builds an arbitrary record from a binary JSON object.
816826jsonbToRecord
817− :: SListI row
818− => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
819− -> NP (Aliased (TypeExpression schema)) row
820− -> Query schema params row
827+ :: SListI record
828+ => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
829+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
830+ -> Query schema params record
821831jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
822832
823833-- | Builds an arbitrary set of records from a JSON array of objects.
824834jsonToRecordSet
825− :: SListI row
826− => Expression schema '[] 'Ungrouped params (nullity 'PGjson)
827− -> NP (Aliased (TypeExpression schema)) row
828− -> Query schema params row
835+ :: SListI record
836+ => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
837+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
838+ -> Query schema params record
829839jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
830840
831−-- | Builds an arbitrary set of records from a binary JSON array of objects (see
832−-- note below). As with all functions returning record, the caller must
833−-- explicitly define the structure of the record with an AS clause.
841+-- | Builds an arbitrary set of records from a binary JSON array of objects.
834842jsonbToRecordSet
835− :: SListI row
836− => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
837− -> NP (Aliased (TypeExpression schema)) row
838− -> Query schema params row
843+ :: SListI record
844+ => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
845+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
846+ -> Query schema params record
839847jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
840848
841849{-----------------------------------------
@@ -1136,221 +1144,221 @@ rowIn
11361144 -> Condition schema from grp params
11371145rowIn = unsafeRowSubqueryExpression "IN"
11381146
1139−-- | >>> printSQL $ true `allEq` values_ (true `as` #foo)
1140−-- TRUE ALL = (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1141−allEq
1142− :: Expression schema from grp params ty
1143− -> Query schema params '[alias ::: ty]
1147+-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
1148+-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1149+eqAll
1150+ :: Expression schema from grp params ty -- ^ expression
1151+ -> Query schema params '[alias ::: ty] -- ^ subquery
11441152 -> Condition schema from grp params
1145−allEq = unsafeSubqueryExpression "ALL ="
1153+eqAll = unsafeSubqueryExpression "= ALL"
11461154
11471155-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1148−-- >>> printSQL $ myRow `rowAllEq` values_ myRow
1149−-- ROW(1, FALSE) ALL = (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1150−rowAllEq
1156+-- >>> printSQL $ myRow `rowEqAll` values_ myRow
1157+-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1158+rowEqAll
11511159 :: SListI row
1152− => NP (Aliased (Expression schema from grp params)) row
1153− -> Query schema params row
1160+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1161+ -> Query schema params row -- ^ subquery
11541162 -> Condition schema from grp params
1155−rowAllEq = unsafeRowSubqueryExpression "ALL ="
1163+rowEqAll = unsafeRowSubqueryExpression "= ALL"
11561164
1157−-- | >>> printSQL $ true `anyEq` values_ (true `as` #foo)
1158−-- TRUE ANY = (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1159−anyEq
1160− :: Expression schema from grp params ty
1161− -> Query schema params '[alias ::: ty]
1165+-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
1166+-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1167+eqAny
1168+ :: Expression schema from grp params ty -- ^ expression
1169+ -> Query schema params '[alias ::: ty] -- ^ subquery
11621170 -> Condition schema from grp params
1163−anyEq = unsafeSubqueryExpression "ANY ="
1171+eqAny = unsafeSubqueryExpression "= ANY"
11641172
11651173-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1166−-- >>> printSQL $ myRow `rowAnyEq` values_ myRow
1167−-- ROW(1, FALSE) ANY = (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1168−rowAnyEq
1174+-- >>> printSQL $ myRow `rowEqAny` values_ myRow
1175+-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1176+rowEqAny
11691177 :: SListI row
1170− => NP (Aliased (Expression schema from grp params)) row
1171− -> Query schema params row
1178+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1179+ -> Query schema params row -- ^ subquery
11721180 -> Condition schema from grp params
1173−rowAnyEq = unsafeRowSubqueryExpression "ANY ="
1181+rowEqAny = unsafeRowSubqueryExpression "= ANY"
11741182
1175−-- | >>> printSQL $ true `allNeq` values_ (true `as` #foo)
1176−-- TRUE ALL <> (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1177−allNeq
1178− :: Expression schema from grp params ty
1179− -> Query schema params '[alias ::: ty]
1183+-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
1184+-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1185+neqAll
1186+ :: Expression schema from grp params ty -- ^ expression
1187+ -> Query schema params '[alias ::: ty] -- ^ subquery
11801188 -> Condition schema from grp params
1181−allNeq = unsafeSubqueryExpression "ALL <>"
1189+neqAll = unsafeSubqueryExpression "<> ALL"
11821190
11831191-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1184−-- >>> printSQL $ myRow `rowAllNeq` values_ myRow
1185−-- ROW(1, FALSE) ALL <> (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1186−rowAllNeq
1192+-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
1193+-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1194+rowNeqAll
11871195 :: SListI row
1188− => NP (Aliased (Expression schema from grp params)) row
1189− -> Query schema params row
1196+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1197+ -> Query schema params row -- ^ subquery
11901198 -> Condition schema from grp params
1191−rowAllNeq = unsafeRowSubqueryExpression "ALL <>"
1199+rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
11921200
1193−-- | >>> printSQL $ true `anyNeq` values_ (true `as` #foo)
1194−-- TRUE ANY <> (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1195−anyNeq
1196− :: Expression schema from grp params ty
1197− -> Query schema params '[alias ::: ty]
1201+-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
1202+-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1203+neqAny
1204+ :: Expression schema from grp params ty -- ^ expression
1205+ -> Query schema params '[alias ::: ty] -- ^ subquery
11981206 -> Condition schema from grp params
1199−anyNeq = unsafeSubqueryExpression "ANY <>"
1207+neqAny = unsafeSubqueryExpression "<> ANY"
12001208
12011209-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1202−-- >>> printSQL $ myRow `rowAnyNeq` values_ myRow
1203−-- ROW(1, FALSE) ANY <> (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1204−rowAnyNeq
1210+-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
1211+-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1212+rowNeqAny
12051213 :: SListI row
1206− => NP (Aliased (Expression schema from grp params)) row
1207− -> Query schema params row
1214+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1215+ -> Query schema params row -- ^ subquery
12081216 -> Condition schema from grp params
1209−rowAnyNeq = unsafeRowSubqueryExpression "ANY <>"
1217+rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
12101218
12111219-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
12121220-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12131221allLt
1214− :: Expression schema from grp params ty
1215− -> Query schema params '[alias ::: ty]
1222+ :: Expression schema from grp params ty -- ^ expression
1223+ -> Query schema params '[alias ::: ty] -- ^ subquery
12161224 -> Condition schema from grp params
12171225allLt = unsafeSubqueryExpression "ALL <"
12181226
12191227-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1220−-- >>> printSQL $ myRow `rowAllLt` values_ myRow
1228+-- >>> printSQL $ myRow `rowLtAll` values_ myRow
12211229-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1222−rowAllLt
1230+rowLtAll
12231231 :: SListI row
1224− => NP (Aliased (Expression schema from grp params)) row
1225− -> Query schema params row
1232+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1233+ -> Query schema params row -- ^ subquery
12261234 -> Condition schema from grp params
1227−rowAllLt = unsafeRowSubqueryExpression "ALL <"
1235+rowLtAll = unsafeRowSubqueryExpression "ALL <"
12281236
1229−-- | >>> printSQL $ true `anyLt` values_ (true `as` #foo)
1237+-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
12301238-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1231−anyLt
1232− :: Expression schema from grp params ty
1233− -> Query schema params '[alias ::: ty]
1239+ltAny
1240+ :: Expression schema from grp params ty -- ^ expression
1241+ -> Query schema params '[alias ::: ty] -- ^ subquery
12341242 -> Condition schema from grp params
1235−anyLt = unsafeSubqueryExpression "ANY <"
1243+ltAny = unsafeSubqueryExpression "ANY <"
12361244
12371245-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1238−-- >>> printSQL $ myRow `rowAllLt` values_ myRow
1246+-- >>> printSQL $ myRow `rowLtAll` values_ myRow
12391247-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1240−rowAnyLt
1248+rowLtAny
12411249 :: SListI row
1242− => NP (Aliased (Expression schema from grp params)) row
1243− -> Query schema params row
1250+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1251+ -> Query schema params row -- ^ subquery
12441252 -> Condition schema from grp params
1245−rowAnyLt = unsafeRowSubqueryExpression "ANY <"
1253+rowLtAny = unsafeRowSubqueryExpression "ANY <"
12461254
1247−-- | >>> printSQL $ true `allLte` values_ (true `as` #foo)
1248−-- TRUE ALL <= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1249−allLte
1250− :: Expression schema from grp params ty
1251− -> Query schema params '[alias ::: ty]
1255+-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
1256+-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1257+lteAll
1258+ :: Expression schema from grp params ty -- ^ expression
1259+ -> Query schema params '[alias ::: ty] -- ^ subquery
12521260 -> Condition schema from grp params
1253−allLte = unsafeSubqueryExpression "ALL <="
1261+lteAll = unsafeSubqueryExpression "<= ALL"
12541262
12551263-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1256−-- >>> printSQL $ myRow `rowAllLte` values_ myRow
1257−-- ROW(1, FALSE) ALL <= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1258−rowAllLte
1264+-- >>> printSQL $ myRow `rowLteAll` values_ myRow
1265+-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1266+rowLteAll
12591267 :: SListI row
1260− => NP (Aliased (Expression schema from grp params)) row
1261− -> Query schema params row
1268+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1269+ -> Query schema params row -- ^ subquery
12621270 -> Condition schema from grp params
1263−rowAllLte = unsafeRowSubqueryExpression "ALL <="
1271+rowLteAll = unsafeRowSubqueryExpression "<= ALL"
12641272
1265−-- | >>> printSQL $ true `anyLte` values_ (true `as` #foo)
1266−-- TRUE ANY <= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1267−anyLte
1268− :: Expression schema from grp params ty
1269− -> Query schema params '[alias ::: ty]
1273+-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
1274+-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1275+lteAny
1276+ :: Expression schema from grp params ty -- ^ expression
1277+ -> Query schema params '[alias ::: ty] -- ^ subquery
12701278 -> Condition schema from grp params
1271−anyLte = unsafeSubqueryExpression "ANY <="
1279+lteAny = unsafeSubqueryExpression "<= ANY"
12721280
12731281-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1274−-- >>> printSQL $ myRow `rowAnyLte` values_ myRow
1275−-- ROW(1, FALSE) ANY <= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1276−rowAnyLte
1282+-- >>> printSQL $ myRow `rowLteAny` values_ myRow
1283+-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1284+rowLteAny
12771285 :: SListI row
1278− => NP (Aliased (Expression schema from grp params)) row
1279− -> Query schema params row
1286+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1287+ -> Query schema params row -- ^ subquery
12801288 -> Condition schema from grp params
1281−rowAnyLte = unsafeRowSubqueryExpression "ANY <="
1289+rowLteAny = unsafeRowSubqueryExpression "<= ANY"
12821290
1283−-- | >>> printSQL $ true `allGt` values_ (true `as` #foo)
1284−-- TRUE ALL > (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1285−allGt
1286− :: Expression schema from grp params ty
1287− -> Query schema params '[alias ::: ty]
1291+-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
1292+-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1293+gtAll
1294+ :: Expression schema from grp params ty -- ^ expression
1295+ -> Query schema params '[alias ::: ty] -- ^ subquery
12881296 -> Condition schema from grp params
1289−allGt = unsafeSubqueryExpression "ALL >"
1297+gtAll = unsafeSubqueryExpression "> ALL"
12901298
12911299-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1292−-- >>> printSQL $ myRow `rowAllGt` values_ myRow
1293−-- ROW(1, FALSE) ALL > (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1294−rowAllGt
1300+-- >>> printSQL $ myRow `rowGtAll` values_ myRow
1301+-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1302+rowGtAll
12951303 :: SListI row
1296− => NP (Aliased (Expression schema from grp params)) row
1297− -> Query schema params row
1304+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1305+ -> Query schema params row -- ^ subquery
12981306 -> Condition schema from grp params
1299−rowAllGt = unsafeRowSubqueryExpression "ALL >"
1307+rowGtAll = unsafeRowSubqueryExpression "> ALL"
13001308
1301−-- | >>> printSQL $ true `anyGt` values_ (true `as` #foo)
1302−-- TRUE ANY > (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1303−anyGt
1304− :: Expression schema from grp params ty
1305− -> Query schema params '[alias ::: ty]
1309+-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
1310+-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1311+gtAny
1312+ :: Expression schema from grp params ty -- ^ expression
1313+ -> Query schema params '[alias ::: ty] -- ^ subquery
13061314 -> Condition schema from grp params
1307−anyGt = unsafeSubqueryExpression "ANY >"
1315+gtAny = unsafeSubqueryExpression "> ANY"
13081316
13091317-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1310−-- >>> printSQL $ myRow `rowAnyGt` values_ myRow
1311−-- ROW(1, FALSE) ANY > (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1312−rowAnyGt
1318+-- >>> printSQL $ myRow `rowGtAny` values_ myRow
1319+-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1320+rowGtAny
13131321 :: SListI row
1314− => NP (Aliased (Expression schema from grp params)) row
1315− -> Query schema params row
1322+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1323+ -> Query schema params row -- ^ subquery
13161324 -> Condition schema from grp params
1317−rowAnyGt = unsafeRowSubqueryExpression "ANY >"
1325+rowGtAny = unsafeRowSubqueryExpression "> ANY"
13181326
1319−-- | >>> printSQL $ true `allGte` values_ (true `as` #foo)
1320−-- TRUE ALL >= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1321−allGte
1322− :: Expression schema from grp params ty
1323− -> Query schema params '[alias ::: ty]
1327+-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
1328+-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1329+gteAll
1330+ :: Expression schema from grp params ty -- ^ expression
1331+ -> Query schema params '[alias ::: ty] -- ^ subquery
13241332 -> Condition schema from grp params
1325−allGte = unsafeSubqueryExpression "ALL >="
1333+gteAll = unsafeSubqueryExpression ">= ALL"
13261334
13271335-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1328−-- >>> printSQL $ myRow `rowAllGte` values_ myRow
1329−-- ROW(1, FALSE) ALL >= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1330−rowAllGte
1336+-- >>> printSQL $ myRow `rowGteAll` values_ myRow
1337+-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1338+rowGteAll
13311339 :: SListI row
1332− => NP (Aliased (Expression schema from grp params)) row
1333− -> Query schema params row
1340+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1341+ -> Query schema params row -- ^ subquery
13341342 -> Condition schema from grp params
1335−rowAllGte = unsafeRowSubqueryExpression "ALL >="
1343+rowGteAll = unsafeRowSubqueryExpression ">= ALL"
13361344
1337−-- | >>> printSQL $ true `anyGte` values_ (true `as` #foo)
1338−-- TRUE ANY >= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1339−anyGte
1340− :: Expression schema from grp params ty
1341− -> Query schema params '[alias ::: ty]
1345+-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
1346+-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1347+gteAny
1348+ :: Expression schema from grp params ty -- ^ expression
1349+ -> Query schema params '[alias ::: ty] -- ^ subquery
13421350 -> Condition schema from grp params
1343−anyGte = unsafeSubqueryExpression "ANY >="
1351+gteAny = unsafeSubqueryExpression ">= ANY"
13441352
13451353-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1346−-- >>> printSQL $ myRow `rowAnyGte` values_ myRow
1347−-- ROW(1, FALSE) ANY >= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1348−rowAnyGte
1354+-- >>> printSQL $ myRow `rowGteAny` values_ myRow
1355+-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1356+rowGteAny
13491357 :: SListI row
1350− => NP (Aliased (Expression schema from grp params)) row
1351− -> Query schema params row
1358+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1359+ -> Query schema params row -- ^ subquery
13521360 -> Condition schema from grp params
1353−rowAnyGte = unsafeRowSubqueryExpression "ANY >="
1361+rowGteAny = unsafeRowSubqueryExpression ">= ANY"
13541362
13551363-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
13561364data CommonTableExpression statement
@@ -1373,7 +1381,7 @@ instance (KnownSymbol alias, schema1 ~ (alias ::: 'View cte ': schema))
13731381
13741382-- | render a `CommonTableExpression`.
13751383renderCommonTableExpression
1376− :: (forall sch ps row. statement ps sch row -> ByteString)
1384+ :: (forall sch ps row. statement ps sch row -> ByteString) -- ^ render statement
13771385 -> CommonTableExpression statement params schema0 schema1 -> ByteString
13781386renderCommonTableExpression renderStatement
13791387 (CommonTableExpression (statement `As` alias)) =
@@ -1381,7 +1389,7 @@ renderCommonTableExpression renderStatement
13811389
13821390-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
13831391renderCommonTableExpressions
1384− :: (forall sch ps row. statement ps sch row -> ByteString)
1392+ :: (forall sch ps row. statement ps sch row -> ByteString) -- ^ render statement
13851393 -> CommonTableExpression statement params schema0 schema1
13861394 -> AlignedList (CommonTableExpression statement params) schema1 schema2
13871395 -> ByteString
@@ -1397,7 +1405,9 @@ renderCommonTableExpressions renderStatement cte ctes =
13971405class With statement where
13981406 with
13991407 :: AlignedList (CommonTableExpression statement params) schema0 schema1
1408+ -- ^ common table expressions
14001409 -> statement schema1 params row
1410+ -- ^ larger query
14011411 -> statement schema0 params row
14021412instance With Query where
14031413 with Done query = query