@@ -29,31 +29,28 @@ Squeal queries.
29module Squeal.PostgreSQL.Query
29module Squeal.PostgreSQL.Query
30 ( -- * Queries
30 ( -- * Queries
31 Query (UnsafeQuery, renderQuery)
31 Query (UnsafeQuery, renderQuery)
38− -- * Select
32+ -- ** Select
40 , selectDistinct
34 , selectDistinct
41 , selectStar
35 , selectStar
42 , selectDistinctStar
36 , selectDistinctStar
43 , selectDotStar
37 , selectDotStar
44 , selectDistinctDotStar
38 , selectDistinctDotStar
47− -- * Table Expressions
42+ -- ** Set Operations
48− , TableExpression (..)
43+ , union
49− , renderTableExpression
44+ , unionAll
50− , from
45+ , intersect
51− , where_
46+ , intersectAll
52− , groupBy
47+ , except
53− , having
48+ , exceptAll
54− , orderBy
49+ -- ** With
55− , limit
50+ , With (with)
56− , offset
51+ , CommonTableExpression (..)
52+ , renderCommonTableExpression
53+ , renderCommonTableExpressions
57 -- ** Json
54 -- ** Json
58 , jsonEach
55 , jsonEach
59 , jsonbEach
56 , jsonbEach
@@ -69,7 +66,17 @@ module Squeal.PostgreSQL.Query
69 , jsonbToRecord
66 , jsonbToRecord
70 , jsonToRecordSet
67 , jsonToRecordSet
71 , jsonbToRecordSet
68 , jsonbToRecordSet
69+ -- * Table Expressions
70+ , TableExpression (..)
71+ , renderTableExpression
72− -- * From
79+ -- * From Clauses
73 , FromClause (..)
80 , FromClause (..)
75 , subquery
82 , subquery
@@ -89,38 +96,33 @@ module Squeal.PostgreSQL.Query
89 -- * Sorting
96 -- * Sorting
90 , SortExpression (..)
97 , SortExpression (..)
91 , renderSortExpression
98 , renderSortExpression
92− -- * Subquery expressions
99+ -- * Subquery Expressions
96− , rowAllEq
103+ , rowEqAll
98− , rowAnyEq
105+ , rowEqAny
99− , allNeq
106+ , neqAll
100− , rowAllNeq
107+ , rowNeqAll
101− , anyNeq
108+ , neqAny
102− , rowAnyNeq
109+ , rowNeqAny
104− , rowAllLt
111+ , rowLtAll
106− , rowAnyLt
113+ , rowLtAny
107− , allLte
114+ , lteAll
108− , rowAllLte
115+ , rowLteAll
109− , anyLte
116+ , lteAny
110− , rowAnyLte
117+ , rowLteAny
112− , rowAllGt
119+ , rowGtAll
114− , rowAnyGt
121+ , rowGtAny
115− , allGte
122+ , gteAll
116− , rowAllGte
123+ , rowGteAll
117− , anyGte
124+ , gteAny
118− , rowAnyGte
125+ , rowGteAny
121− , CommonTableExpression (..)
122− , renderCommonTableExpression
123− , renderCommonTableExpressions
126import Control.DeepSeq
128import Control.DeepSeq
@@ -139,9 +141,7 @@ import Squeal.PostgreSQL.Schema
141The process of retrieving or the command to retrieve data from a database
143The process of retrieving or the command to retrieve data from a database
142−is called a `Query`. The `select`, `selectStar`, `selectDotStar`,
144+is called a `Query`. Let's see some examples of queries.
143−`selectDistinct`, `selectDistinctStar` and `selectDistinctDotStar` commands
144−are used to specify queries.
146simple query:
146simple query:
@@ -312,6 +312,16 @@ in printSQL query
313SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
313SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
319+ query :: Query '[] '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
320+ query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]
323+SELECT * FROM (VALUES (1, TRUE), (2, FALSE)) AS t ("foo", "bar")
315set operations:
325set operations:
@@ -708,41 +718,41 @@ unsafeSetOfFunction fun expr = UnsafeQuery $
709-- | Expands the outermost JSON object into a set of key/value pairs.
719-- | Expands the outermost JSON object into a set of key/value pairs.
711− :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json
721+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
712 -> Query schema params
722 -> Query schema params
713 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
723 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
714jsonEach = unsafeSetOfFunction "json_each"
724jsonEach = unsafeSetOfFunction "json_each"
716-- | Expands the outermost binary JSON object into a set of key/value pairs.
726-- | Expands the outermost binary JSON object into a set of key/value pairs.
718− :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb
728+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
719 -> Query schema params
729 -> Query schema params
720 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
730 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
721jsonbEach = unsafeSetOfFunction "jsonb_each"
731jsonbEach = unsafeSetOfFunction "jsonb_each"
723-- | Expands the outermost JSON object into a set of key/value pairs.
733-- | Expands the outermost JSON object into a set of key/value pairs.
724jsonEachAsText
734jsonEachAsText
725− :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json
735+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
726 -> Query schema params
736 -> Query schema params
727 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
737 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
728jsonEachAsText = unsafeSetOfFunction "json_each_text"
738jsonEachAsText = unsafeSetOfFunction "json_each_text"
730-- | Expands the outermost binary JSON object into a set of key/value pairs.
740-- | Expands the outermost binary JSON object into a set of key/value pairs.
731jsonbEachAsText
741jsonbEachAsText
732− :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb
742+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
733 -> Query schema params
743 -> Query schema params
734 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
744 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
735jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
745jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
737-- | Returns set of keys in the outermost JSON object.
747-- | Returns set of keys in the outermost JSON object.
738jsonObjectKeys
748jsonObjectKeys
739− :: Expression schema '[] 'Ungrouped params (nullity 'PGjson)
749+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
740 -> Query schema params '["json_object_keys" ::: 'NotNull 'PGtext]
750 -> Query schema params '["json_object_keys" ::: 'NotNull 'PGtext]
741jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
751jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
743-- | Returns set of keys in the outermost JSON object.
753-- | Returns set of keys in the outermost JSON object.
744jsonbObjectKeys
754jsonbObjectKeys
745− :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
755+ :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
746 -> Query schema params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
756 -> Query schema params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
747jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
757jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
@@ -759,24 +769,24 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
759-- | Expands the JSON expression to a row whose columns match the record
769-- | Expands the JSON expression to a row whose columns match the record
760-- type defined by the given table.
770-- type defined by the given table.
761jsonPopulateRecord
771jsonPopulateRecord
762− :: TypeExpression schema (nullity ('PGcomposite row))
772+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
763− -> Expression schema '[] 'Ungrouped params (nullity 'PGjson)
773+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
764 -> Query schema params row
774 -> Query schema params row
765jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
775jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
767-- | Expands the binary JSON expression to a row whose columns match the record
777-- | Expands the binary JSON expression to a row whose columns match the record
768-- type defined by the given table.
778-- type defined by the given table.
769jsonbPopulateRecord
779jsonbPopulateRecord
770− :: TypeExpression schema (nullity ('PGcomposite row))
780+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
771− -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
781+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
772 -> Query schema params row
782 -> Query schema params row
773jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
783jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
775-- | Expands the outermost array of objects in the given JSON expression to a
785-- | Expands the outermost array of objects in the given JSON expression to a
776-- set of rows whose columns match the record type defined by the given table.
786-- set of rows whose columns match the record type defined by the given table.
777jsonPopulateRecordSet
787jsonPopulateRecordSet
778− :: TypeExpression schema (nullity ('PGcomposite row))
788+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
779− -> Expression schema '[] 'Ungrouped params (nullity 'PGjson)
789+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
780 -> Query schema params row
790 -> Query schema params row
781jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
791jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
@@ -784,17 +794,17 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
784-- to a set of rows whose columns match the record type defined by the given
794-- to a set of rows whose columns match the record type defined by the given
786jsonbPopulateRecordSet
796jsonbPopulateRecordSet
787− :: TypeExpression schema (nullity ('PGcomposite row))
797+ :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
788− -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
798+ -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
789 -> Query schema params row
799 -> Query schema params row
790jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
800jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
792unsafeRecordFunction
802unsafeRecordFunction
793− :: (SListI row, json `In` PGJsonType)
803+ :: (SListI record, json `In` PGJsonType)
794 => ByteString
804 => ByteString
795 -> Expression schema '[] 'Ungrouped params (nullity json)
805 -> Expression schema '[] 'Ungrouped params (nullity json)
796− -> NP (Aliased (TypeExpression schema)) row
806+ -> NP (Aliased (TypeExpression schema)) record
797− -> Query schema params row
807+ -> Query schema params record
798unsafeRecordFunction fun expr types = UnsafeQuery $
808unsafeRecordFunction fun expr types = UnsafeQuery $
799 "SELECT * FROM " <> fun <> "("
809 "SELECT * FROM " <> fun <> "("
800 <> renderExpression expr <> ")"
810 <> renderExpression expr <> ")"
@@ -806,36 +816,34 @@ unsafeRecordFunction fun expr types = UnsafeQuery $
807-- | Builds an arbitrary record from a JSON object.
817-- | Builds an arbitrary record from a JSON object.
808jsonToRecord
818jsonToRecord
809− :: SListI row
819+ :: SListI record
810− => Expression schema '[] 'Ungrouped params (nullity 'PGjson)
820+ => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
811− -> NP (Aliased (TypeExpression schema)) row
821+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
812− -> Query schema params row
822+ -> Query schema params record
813jsonToRecord = unsafeRecordFunction "json_to_record"
823jsonToRecord = unsafeRecordFunction "json_to_record"
815-- | Builds an arbitrary record from a binary JSON object.
825-- | Builds an arbitrary record from a binary JSON object.
816jsonbToRecord
826jsonbToRecord
817− :: SListI row
827+ :: SListI record
818− => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
828+ => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
819− -> NP (Aliased (TypeExpression schema)) row
829+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
820− -> Query schema params row
830+ -> Query schema params record
821jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
831jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
823-- | Builds an arbitrary set of records from a JSON array of objects.
833-- | Builds an arbitrary set of records from a JSON array of objects.
824jsonToRecordSet
834jsonToRecordSet
825− :: SListI row
835+ :: SListI record
826− => Expression schema '[] 'Ungrouped params (nullity 'PGjson)
836+ => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
827− -> NP (Aliased (TypeExpression schema)) row
837+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
828− -> Query schema params row
838+ -> Query schema params record
829jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
839jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
831−-- | Builds an arbitrary set of records from a binary JSON array of objects (see
841+-- | Builds an arbitrary set of records from a binary JSON array of objects.
832−-- note below). As with all functions returning record, the caller must
833−-- explicitly define the structure of the record with an AS clause.
834jsonbToRecordSet
842jsonbToRecordSet
835− :: SListI row
843+ :: SListI record
836− => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb)
844+ => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
837− -> NP (Aliased (TypeExpression schema)) row
845+ -> NP (Aliased (TypeExpression schema)) record -- ^ record types
838− -> Query schema params row
846+ -> Query schema params record
839jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
847jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
841{-----------------------------------------
849{-----------------------------------------
@@ -1136,221 +1144,221 @@ rowIn
1136 -> Condition schema from grp params
1144 -> Condition schema from grp params
1137rowIn = unsafeRowSubqueryExpression "IN"
1145rowIn = unsafeRowSubqueryExpression "IN"
1139−-- | >>> printSQL $ true `allEq` values_ (true `as` #foo)
1147+-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
1140−-- TRUE ALL = (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1148+-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1142− :: Expression schema from grp params ty
1150+ :: Expression schema from grp params ty -- ^ expression
1143− -> Query schema params '[alias ::: ty]
1151+ -> Query schema params '[alias ::: ty] -- ^ subquery
1144 -> Condition schema from grp params
1152 -> Condition schema from grp params
1145−allEq = unsafeSubqueryExpression "ALL ="
1153+eqAll = unsafeSubqueryExpression "= ALL"
1147-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1155-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1148−-- >>> printSQL $ myRow `rowAllEq` values_ myRow
1156+-- >>> printSQL $ myRow `rowEqAll` values_ myRow
1149−-- ROW(1, FALSE) ALL = (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1157+-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1150−rowAllEq
1158+rowEqAll
1151 :: SListI row
1159 :: SListI row
1152− => NP (Aliased (Expression schema from grp params)) row
1160+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1153− -> Query schema params row
1161+ -> Query schema params row -- ^ subquery
1154 -> Condition schema from grp params
1162 -> Condition schema from grp params
1155−rowAllEq = unsafeRowSubqueryExpression "ALL ="
1163+rowEqAll = unsafeRowSubqueryExpression "= ALL"
1157−-- | >>> printSQL $ true `anyEq` values_ (true `as` #foo)
1165+-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
1158−-- TRUE ANY = (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1166+-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1160− :: Expression schema from grp params ty
1168+ :: Expression schema from grp params ty -- ^ expression
1161− -> Query schema params '[alias ::: ty]
1169+ -> Query schema params '[alias ::: ty] -- ^ subquery
1162 -> Condition schema from grp params
1170 -> Condition schema from grp params
1163−anyEq = unsafeSubqueryExpression "ANY ="
1171+eqAny = unsafeSubqueryExpression "= ANY"
1165-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1173-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1166−-- >>> printSQL $ myRow `rowAnyEq` values_ myRow
1174+-- >>> printSQL $ myRow `rowEqAny` values_ myRow
1167−-- ROW(1, FALSE) ANY = (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1175+-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1168−rowAnyEq
1176+rowEqAny
1169 :: SListI row
1177 :: SListI row
1170− => NP (Aliased (Expression schema from grp params)) row
1178+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1171− -> Query schema params row
1179+ -> Query schema params row -- ^ subquery
1172 -> Condition schema from grp params
1180 -> Condition schema from grp params
1173−rowAnyEq = unsafeRowSubqueryExpression "ANY ="
1181+rowEqAny = unsafeRowSubqueryExpression "= ANY"
1175−-- | >>> printSQL $ true `allNeq` values_ (true `as` #foo)
1183+-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
1176−-- TRUE ALL <> (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1184+-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1178− :: Expression schema from grp params ty
1186+ :: Expression schema from grp params ty -- ^ expression
1179− -> Query schema params '[alias ::: ty]
1187+ -> Query schema params '[alias ::: ty] -- ^ subquery
1180 -> Condition schema from grp params
1188 -> Condition schema from grp params
1181−allNeq = unsafeSubqueryExpression "ALL <>"
1189+neqAll = unsafeSubqueryExpression "<> ALL"
1183-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1191-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1184−-- >>> printSQL $ myRow `rowAllNeq` values_ myRow
1192+-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
1185−-- ROW(1, FALSE) ALL <> (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1193+-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1186−rowAllNeq
1194+rowNeqAll
1187 :: SListI row
1195 :: SListI row
1188− => NP (Aliased (Expression schema from grp params)) row
1196+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1189− -> Query schema params row
1197+ -> Query schema params row -- ^ subquery
1190 -> Condition schema from grp params
1198 -> Condition schema from grp params
1191−rowAllNeq = unsafeRowSubqueryExpression "ALL <>"
1199+rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1193−-- | >>> printSQL $ true `anyNeq` values_ (true `as` #foo)
1201+-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
1194−-- TRUE ANY <> (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1202+-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1196− :: Expression schema from grp params ty
1204+ :: Expression schema from grp params ty -- ^ expression
1197− -> Query schema params '[alias ::: ty]
1205+ -> Query schema params '[alias ::: ty] -- ^ subquery
1198 -> Condition schema from grp params
1206 -> Condition schema from grp params
1199−anyNeq = unsafeSubqueryExpression "ANY <>"
1207+neqAny = unsafeSubqueryExpression "<> ANY"
1201-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1209-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1202−-- >>> printSQL $ myRow `rowAnyNeq` values_ myRow
1210+-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
1203−-- ROW(1, FALSE) ANY <> (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1211+-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1204−rowAnyNeq
1212+rowNeqAny
1205 :: SListI row
1213 :: SListI row
1206− => NP (Aliased (Expression schema from grp params)) row
1214+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1207− -> Query schema params row
1215+ -> Query schema params row -- ^ subquery
1208 -> Condition schema from grp params
1216 -> Condition schema from grp params
1209−rowAnyNeq = unsafeRowSubqueryExpression "ANY <>"
1217+rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1211-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
1219-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
1212-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1220-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1214− :: Expression schema from grp params ty
1222+ :: Expression schema from grp params ty -- ^ expression
1215− -> Query schema params '[alias ::: ty]
1223+ -> Query schema params '[alias ::: ty] -- ^ subquery
1216 -> Condition schema from grp params
1224 -> Condition schema from grp params
1217allLt = unsafeSubqueryExpression "ALL <"
1225allLt = unsafeSubqueryExpression "ALL <"
1219-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1227-- | >>> 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
1221-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1229-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1222−rowAllLt
1230+rowLtAll
1223 :: SListI row
1231 :: SListI row
1224− => NP (Aliased (Expression schema from grp params)) row
1232+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1225− -> Query schema params row
1233+ -> Query schema params row -- ^ subquery
1226 -> Condition schema from grp params
1234 -> Condition schema from grp params
1227−rowAllLt = unsafeRowSubqueryExpression "ALL <"
1235+rowLtAll = unsafeRowSubqueryExpression "ALL <"
1229−-- | >>> printSQL $ true `anyLt` values_ (true `as` #foo)
1237+-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
1230-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1238-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1232− :: Expression schema from grp params ty
1240+ :: Expression schema from grp params ty -- ^ expression
1233− -> Query schema params '[alias ::: ty]
1241+ -> Query schema params '[alias ::: ty] -- ^ subquery
1234 -> Condition schema from grp params
1242 -> Condition schema from grp params
1235−anyLt = unsafeSubqueryExpression "ANY <"
1243+ltAny = unsafeSubqueryExpression "ANY <"
1237-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1245-- | >>> 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
1239-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1247-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1240−rowAnyLt
1248+rowLtAny
1241 :: SListI row
1249 :: SListI row
1242− => NP (Aliased (Expression schema from grp params)) row
1250+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1243− -> Query schema params row
1251+ -> Query schema params row -- ^ subquery
1244 -> Condition schema from grp params
1252 -> Condition schema from grp params
1245−rowAnyLt = unsafeRowSubqueryExpression "ANY <"
1253+rowLtAny = unsafeRowSubqueryExpression "ANY <"
1247−-- | >>> printSQL $ true `allLte` values_ (true `as` #foo)
1255+-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
1248−-- TRUE ALL <= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1256+-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1250− :: Expression schema from grp params ty
1258+ :: Expression schema from grp params ty -- ^ expression
1251− -> Query schema params '[alias ::: ty]
1259+ -> Query schema params '[alias ::: ty] -- ^ subquery
1252 -> Condition schema from grp params
1260 -> Condition schema from grp params
1253−allLte = unsafeSubqueryExpression "ALL <="
1261+lteAll = unsafeSubqueryExpression "<= ALL"
1255-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1263-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1256−-- >>> printSQL $ myRow `rowAllLte` values_ myRow
1264+-- >>> printSQL $ myRow `rowLteAll` values_ myRow
1257−-- ROW(1, FALSE) ALL <= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1265+-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1258−rowAllLte
1266+rowLteAll
1259 :: SListI row
1267 :: SListI row
1260− => NP (Aliased (Expression schema from grp params)) row
1268+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1261− -> Query schema params row
1269+ -> Query schema params row -- ^ subquery
1262 -> Condition schema from grp params
1270 -> Condition schema from grp params
1263−rowAllLte = unsafeRowSubqueryExpression "ALL <="
1271+rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1265−-- | >>> printSQL $ true `anyLte` values_ (true `as` #foo)
1273+-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
1266−-- TRUE ANY <= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1274+-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1268− :: Expression schema from grp params ty
1276+ :: Expression schema from grp params ty -- ^ expression
1269− -> Query schema params '[alias ::: ty]
1277+ -> Query schema params '[alias ::: ty] -- ^ subquery
1270 -> Condition schema from grp params
1278 -> Condition schema from grp params
1271−anyLte = unsafeSubqueryExpression "ANY <="
1279+lteAny = unsafeSubqueryExpression "<= ANY"
1273-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1281-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1274−-- >>> printSQL $ myRow `rowAnyLte` values_ myRow
1282+-- >>> printSQL $ myRow `rowLteAny` values_ myRow
1275−-- ROW(1, FALSE) ANY <= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1283+-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1276−rowAnyLte
1284+rowLteAny
1277 :: SListI row
1285 :: SListI row
1278− => NP (Aliased (Expression schema from grp params)) row
1286+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1279− -> Query schema params row
1287+ -> Query schema params row -- ^ subquery
1280 -> Condition schema from grp params
1288 -> Condition schema from grp params
1281−rowAnyLte = unsafeRowSubqueryExpression "ANY <="
1289+rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1283−-- | >>> printSQL $ true `allGt` values_ (true `as` #foo)
1291+-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
1284−-- TRUE ALL > (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1292+-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1286− :: Expression schema from grp params ty
1294+ :: Expression schema from grp params ty -- ^ expression
1287− -> Query schema params '[alias ::: ty]
1295+ -> Query schema params '[alias ::: ty] -- ^ subquery
1288 -> Condition schema from grp params
1296 -> Condition schema from grp params
1289−allGt = unsafeSubqueryExpression "ALL >"
1297+gtAll = unsafeSubqueryExpression "> ALL"
1291-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1299-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1292−-- >>> printSQL $ myRow `rowAllGt` values_ myRow
1300+-- >>> printSQL $ myRow `rowGtAll` values_ myRow
1293−-- ROW(1, FALSE) ALL > (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1301+-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1294−rowAllGt
1302+rowGtAll
1295 :: SListI row
1303 :: SListI row
1296− => NP (Aliased (Expression schema from grp params)) row
1304+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1297− -> Query schema params row
1305+ -> Query schema params row -- ^ subquery
1298 -> Condition schema from grp params
1306 -> Condition schema from grp params
1299−rowAllGt = unsafeRowSubqueryExpression "ALL >"
1307+rowGtAll = unsafeRowSubqueryExpression "> ALL"
1301−-- | >>> printSQL $ true `anyGt` values_ (true `as` #foo)
1309+-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
1302−-- TRUE ANY > (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1310+-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1304− :: Expression schema from grp params ty
1312+ :: Expression schema from grp params ty -- ^ expression
1305− -> Query schema params '[alias ::: ty]
1313+ -> Query schema params '[alias ::: ty] -- ^ subquery
1306 -> Condition schema from grp params
1314 -> Condition schema from grp params
1307−anyGt = unsafeSubqueryExpression "ANY >"
1315+gtAny = unsafeSubqueryExpression "> ANY"
1309-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1317-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1310−-- >>> printSQL $ myRow `rowAnyGt` values_ myRow
1318+-- >>> printSQL $ myRow `rowGtAny` values_ myRow
1311−-- ROW(1, FALSE) ANY > (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1319+-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1312−rowAnyGt
1320+rowGtAny
1313 :: SListI row
1321 :: SListI row
1314− => NP (Aliased (Expression schema from grp params)) row
1322+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1315− -> Query schema params row
1323+ -> Query schema params row -- ^ subquery
1316 -> Condition schema from grp params
1324 -> Condition schema from grp params
1317−rowAnyGt = unsafeRowSubqueryExpression "ANY >"
1325+rowGtAny = unsafeRowSubqueryExpression "> ANY"
1319−-- | >>> printSQL $ true `allGte` values_ (true `as` #foo)
1327+-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
1320−-- TRUE ALL >= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1328+-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1322− :: Expression schema from grp params ty
1330+ :: Expression schema from grp params ty -- ^ expression
1323− -> Query schema params '[alias ::: ty]
1331+ -> Query schema params '[alias ::: ty] -- ^ subquery
1324 -> Condition schema from grp params
1332 -> Condition schema from grp params
1325−allGte = unsafeSubqueryExpression "ALL >="
1333+gteAll = unsafeSubqueryExpression ">= ALL"
1327-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1335-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1328−-- >>> printSQL $ myRow `rowAllGte` values_ myRow
1336+-- >>> printSQL $ myRow `rowGteAll` values_ myRow
1329−-- ROW(1, FALSE) ALL >= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1337+-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1330−rowAllGte
1338+rowGteAll
1331 :: SListI row
1339 :: SListI row
1332− => NP (Aliased (Expression schema from grp params)) row
1340+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1333− -> Query schema params row
1341+ -> Query schema params row -- ^ subquery
1334 -> Condition schema from grp params
1342 -> Condition schema from grp params
1335−rowAllGte = unsafeRowSubqueryExpression "ALL >="
1343+rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1337−-- | >>> printSQL $ true `anyGte` values_ (true `as` #foo)
1345+-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
1338−-- TRUE ANY >= (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1346+-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1340− :: Expression schema from grp params ty
1348+ :: Expression schema from grp params ty -- ^ expression
1341− -> Query schema params '[alias ::: ty]
1349+ -> Query schema params '[alias ::: ty] -- ^ subquery
1342 -> Condition schema from grp params
1350 -> Condition schema from grp params
1343−anyGte = unsafeSubqueryExpression "ANY >="
1351+gteAny = unsafeSubqueryExpression ">= ANY"
1345-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1353-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression '[] '[] 'Ungrouped '[])) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1346−-- >>> printSQL $ myRow `rowAnyGte` values_ myRow
1354+-- >>> printSQL $ myRow `rowGteAny` values_ myRow
1347−-- ROW(1, FALSE) ANY >= (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1355+-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1348−rowAnyGte
1356+rowGteAny
1349 :: SListI row
1357 :: SListI row
1350− => NP (Aliased (Expression schema from grp params)) row
1358+ => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1351− -> Query schema params row
1359+ -> Query schema params row -- ^ subquery
1352 -> Condition schema from grp params
1360 -> Condition schema from grp params
1353−rowAnyGte = unsafeRowSubqueryExpression "ANY >="
1361+rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1355-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1363-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1356data CommonTableExpression statement
1364data CommonTableExpression statement
@@ -1373,7 +1381,7 @@ instance (KnownSymbol alias, schema1 ~ (alias ::: 'View cte ': schema))
1374-- | render a `CommonTableExpression`.
1382-- | render a `CommonTableExpression`.
1375renderCommonTableExpression
1383renderCommonTableExpression
1376− :: (forall sch ps row. statement ps sch row -> ByteString)
1384+ :: (forall sch ps row. statement ps sch row -> ByteString) -- ^ render statement
1377 -> CommonTableExpression statement params schema0 schema1 -> ByteString
1385 -> CommonTableExpression statement params schema0 schema1 -> ByteString
1378renderCommonTableExpression renderStatement
1386renderCommonTableExpression renderStatement
1379 (CommonTableExpression (statement `As` alias)) =
1387 (CommonTableExpression (statement `As` alias)) =
@@ -1381,7 +1389,7 @@ renderCommonTableExpression renderStatement
1382-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1390-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1383renderCommonTableExpressions
1391renderCommonTableExpressions
1384− :: (forall sch ps row. statement ps sch row -> ByteString)
1392+ :: (forall sch ps row. statement ps sch row -> ByteString) -- ^ render statement
1385 -> CommonTableExpression statement params schema0 schema1
1393 -> CommonTableExpression statement params schema0 schema1
1386 -> AlignedList (CommonTableExpression statement params) schema1 schema2
1394 -> AlignedList (CommonTableExpression statement params) schema1 schema2
1387 -> ByteString
1395 -> ByteString
@@ -1397,7 +1405,9 @@ renderCommonTableExpressions renderStatement cte ctes =
1397class With statement where
1405class With statement where
1399 :: AlignedList (CommonTableExpression statement params) schema0 schema1
1407 :: AlignedList (CommonTableExpression statement params) schema0 schema1
1408+ -- ^ common table expressions
1400 -> statement schema1 params row
1409 -> statement schema1 params row
1401 -> statement schema0 params row
1411 -> statement schema0 params row
1402instance With Query where
1412instance With Query where
1403 with Done query = query
1413 with Done query = query