on dev help sign in
Merge pull request #97 from morphismtech/dev-window-stats
7caa3a2Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+3−3
@@ -298,7 +298,7 @@ check
298 , HasAll aliases (TableToRow table) subcolumns )
298 , HasAll aliases (TableToRow table) subcolumns )
299 => NP Alias aliases
299 => NP Alias aliases
300 -- ^ specify the subcolumns which are getting checked
300 -- ^ specify the subcolumns which are getting checked
301− -> (forall t. Condition '[] schemas '[] 'Ungrouped '[t ::: subcolumns])
301+ -> (forall t. Condition 'Ungrouped '[] schemas '[] '[t ::: subcolumns])
302 -- ^ a closed `Condition` on those subcolumns
302 -- ^ a closed `Condition` on those subcolumns
303 -> TableConstraintExpression sch tab schemas ('Check aliases)
303 -> TableConstraintExpression sch tab schemas ('Check aliases)
304check _cols condition = UnsafeTableConstraintExpression $
304check _cols condition = UnsafeTableConstraintExpression $
@@ -759,7 +759,7 @@ newtype AlterColumn (schemas :: SchemasType) (ty0 :: ColumnType) (ty1 :: ColumnT
759-- :}
759-- :}
760-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
760-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
761setDefault
761setDefault
762− :: Expression '[] schemas '[] 'Ungrouped '[] ty -- ^ default value to set
762+ :: Expression 'Ungrouped '[] schemas '[] '[] ty -- ^ default value to set
763 -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
763 -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
764setDefault expression = UnsafeAlterColumn $
764setDefault expression = UnsafeAlterColumn $
765 "SET DEFAULT" <+> renderExpression expression
765 "SET DEFAULT" <+> renderExpression expression
@@ -1010,7 +1010,7 @@ notNullable ty = UnsafeColumnTypeExpression $ renderSQL ty <+> "NOT NULL"
1010
1010
1011-- | used in `createTable` commands as a column constraint to give a default
1011-- | used in `createTable` commands as a column constraint to give a default
1012default_
1012default_
1013− :: Expression '[] schemas '[] 'Ungrouped '[] ty
1013+ :: Expression 'Ungrouped '[] schemas '[] '[] ty
1014 -> ColumnTypeExpression schemas ('NoDef :=> ty)
1014 -> ColumnTypeExpression schemas ('NoDef :=> ty)
1015 -> ColumnTypeExpression schemas ('Def :=> ty)
1015 -> ColumnTypeExpression schemas ('Def :=> ty)
1016default_ x ty = UnsafeColumnTypeExpression $
1016default_ x ty = UnsafeColumnTypeExpression $
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+897−497
@@ -16,11 +16,13 @@ Squeal expressions are the atoms used to build statements.
16 , FlexibleContexts
16 , FlexibleContexts
17 , FlexibleInstances
17 , FlexibleInstances
18 , FunctionalDependencies
18 , FunctionalDependencies
19+ , GADTs
19 , GeneralizedNewtypeDeriving
20 , GeneralizedNewtypeDeriving
20 , LambdaCase
21 , LambdaCase
21 , MagicHash
22 , MagicHash
22 , OverloadedStrings
23 , OverloadedStrings
23 , ScopedTypeVariables
24 , ScopedTypeVariables
25+ , StandaloneDeriving
24 , TypeApplications
26 , TypeApplications
25 , TypeFamilies
27 , TypeFamilies
26 , TypeInType
28 , TypeInType
@@ -132,15 +134,27 @@ module Squeal.PostgreSQL.Expression
132 , jsonbInsert
134 , jsonbInsert
133 , jsonbPretty
135 , jsonbPretty
134 -- ** Aggregation
136 -- ** Aggregation
135− , unsafeAggregate, unsafeAggregateDistinct
137+ , Aggregate (..)
136− , sum_, sumDistinct
138+ , Distinction (..)
137− , PGAvg (avg, avgDistinct)
139+ , PGAvg
138− , bitAnd, bitOr, boolAnd, boolOr
140+ -- * Window Functions
139− , bitAndDistinct, bitOrDistinct, boolAndDistinct, boolOrDistinct
141+ , WindowDefinition (..)
140− , countStar
142+ , partitionBy
141− , count, countDistinct
143+ , WindowFunction (..)
142− , every, everyDistinct
144+ , rank
143− , max_, maxDistinct, min_, minDistinct
145+ , rowNumber
146+ , denseRank
147+ , percentRank
148+ , cumeDist
149+ , ntile
150+ , lag
151+ , lead
152+ , firstValue
153+ , lastValue
154+ , nthValue
155+ -- * Sorting
156+ , SortExpression (..)
157+ , OrderBy (..)
144 -- * Types
158 -- * Types
145 , TypeExpression (..)
159 , TypeExpression (..)
146 , PGTyped (..)
160 , PGTyped (..)
@@ -180,7 +194,10 @@ module Squeal.PostgreSQL.Expression
180 , fixarray
194 , fixarray
181 -- * Re-export
195 -- * Re-export
182 , (&)
196 , (&)
183− , NP ((:*), Nil)
197+ , NP (..)
198+ , (:*:) (..)
199+ , I (..)
200+ , K (..)
184 ) where
201 ) where
185
202
186import Control.Category
203import Control.Category
@@ -194,6 +211,7 @@ import Data.Ratio
194import Data.String
211import Data.String
195import Data.Word
212import Data.Word
196import Generics.SOP hiding (from)
213import Generics.SOP hiding (from)
214+import GHC.Generics ((:*:) (..))
197import GHC.OverloadedLabels
215import GHC.OverloadedLabels
198import GHC.TypeLits
216import GHC.TypeLits
199import Prelude hiding (id, (.))
217import Prelude hiding (id, (.))
@@ -219,16 +237,16 @@ values from primitive expression using arithmetic, logical,
219and other operations.
237and other operations.
220-}
238-}
221newtype Expression
239newtype Expression
240+ (grp :: Grouping)
222 (commons :: FromType)
241 (commons :: FromType)
223 (schemas :: SchemasType)
242 (schemas :: SchemasType)
224 (params :: [NullityType])
243 (params :: [NullityType])
225− (grp :: Grouping)
226 (from :: FromType)
244 (from :: FromType)
227 (ty :: NullityType)
245 (ty :: NullityType)
228 = UnsafeExpression { renderExpression :: ByteString }
246 = UnsafeExpression { renderExpression :: ByteString }
229 deriving (GHC.Generic,Show,Eq,Ord,NFData)
247 deriving (GHC.Generic,Show,Eq,Ord,NFData)
230
248
231−instance RenderSQL (Expression commons schemas params grp from ty) where
249+instance RenderSQL (Expression grp commons schemas params from ty) where
232 renderSQL = renderExpression
250 renderSQL = renderExpression
233
251
234{- | A `HasParameter` constraint is used to indicate a value that is
252{- | A `HasParameter` constraint is used to indicate a value that is
@@ -246,12 +264,12 @@ class KnownNat n => HasParameter
246 | n params -> ty where
264 | n params -> ty where
247 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
265 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
248 --
266 --
249− -- >>> let expr = parameter @1 int4 :: Expression '[] schemas '[ 'Null 'PGint4] grp from ('Null 'PGint4)
267+ -- >>> let expr = parameter @1 int4 :: Expression grp '[] schemas '[ 'Null 'PGint4] from ('Null 'PGint4)
250 -- >>> printSQL expr
268 -- >>> printSQL expr
251 -- ($1 :: int4)
269 -- ($1 :: int4)
252 parameter
270 parameter
253 :: TypeExpression schemas ty
271 :: TypeExpression schemas ty
254− -> Expression commons schemas params grp from ty
272+ -> Expression grp commons schemas params from ty
255 parameter ty = UnsafeExpression $ parenthesized $
273 parameter ty = UnsafeExpression $ parenthesized $
256 "$" <> renderNat @n <+> "::"
274 "$" <> renderNat @n <+> "::"
257 <+> renderSQL ty
275 <+> renderSQL ty
@@ -262,38 +280,44 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
262-- | `param` takes a `Nat` using type application and for basic types,
280-- | `param` takes a `Nat` using type application and for basic types,
263-- infers a `TypeExpression`.
281-- infers a `TypeExpression`.
264--
282--
265−-- >>> let expr = param @1 :: Expression commons schemas '[ 'Null 'PGint4] grp from ('Null 'PGint4)
283+-- >>> let expr = param @1 :: Expression grp commons schemas '[ 'Null 'PGint4] from ('Null 'PGint4)
266-- >>> printSQL expr
284-- >>> printSQL expr
267-- ($1 :: int4)
285-- ($1 :: int4)
268param
286param
269 :: forall n commons schemas params from grp ty
287 :: forall n commons schemas params from grp ty
270 . (PGTyped schemas ty, HasParameter n params ty)
288 . (PGTyped schemas ty, HasParameter n params ty)
271− => Expression commons schemas params grp from ty -- ^ param
289+ => Expression grp commons schemas params from ty -- ^ param
272param = parameter @n (pgtype @schemas)
290param = parameter @n (pgtype @schemas)
273
291
274instance (HasUnique tab from row, Has col row ty)
292instance (HasUnique tab from row, Has col row ty)
275− => IsLabel col (Expression commons schemas params 'Ungrouped from ty) where
293+ => IsLabel col (Expression 'Ungrouped commons schemas params from ty) where
276 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
294 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
295+instance (HasUnique tab from row, Has col row ty, tys ~ '[ty])
296+ => IsLabel col (NP (Expression 'Ungrouped commons schemas params from) tys) where
297+ fromLabel = fromLabel @col :* Nil
277instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
298instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
278 => IsLabel col
299 => IsLabel col
279− (Aliased (Expression commons schemas params 'Ungrouped from) column) where
300+ (Aliased (Expression 'Ungrouped commons schemas params from) column) where
280 fromLabel = fromLabel @col `As` Alias
301 fromLabel = fromLabel @col `As` Alias
281instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: ty])
302instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: ty])
282 => IsLabel col
303 => IsLabel col
283− (NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns) where
304+ (NP (Aliased (Expression 'Ungrouped commons schemas params from)) columns) where
284 fromLabel = fromLabel @col :* Nil
305 fromLabel = fromLabel @col :* Nil
285
306
286instance (Has tab from row, Has col row ty)
307instance (Has tab from row, Has col row ty)
287− => IsQualified tab col (Expression commons schemas params 'Ungrouped from ty) where
308+ => IsQualified tab col (Expression 'Ungrouped commons schemas params from ty) where
288 tab ! col = UnsafeExpression $
309 tab ! col = UnsafeExpression $
289 renderSQL tab <> "." <> renderSQL col
310 renderSQL tab <> "." <> renderSQL col
311+instance (Has tab from row, Has col row ty, tys ~ '[ty])
312+ => IsQualified tab col (NP (Expression 'Ungrouped commons schemas params from) tys) where
313+ tab ! col = tab ! col :* Nil
290instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
314instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
291 => IsQualified tab col
315 => IsQualified tab col
292− (Aliased (Expression commons schemas params 'Ungrouped from) column) where
316+ (Aliased (Expression 'Ungrouped commons schemas params from) column) where
293 tab ! col = tab ! col `As` col
317 tab ! col = tab ! col `As` col
294instance (Has tab from row, Has col row ty, columns ~ '[col ::: ty])
318instance (Has tab from row, Has col row ty, columns ~ '[col ::: ty])
295 => IsQualified tab col
319 => IsQualified tab col
296− (NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns) where
320+ (NP (Aliased (Expression 'Ungrouped commons schemas params from)) columns) where
297 tab ! col = tab ! col :* Nil
321 tab ! col = tab ! col :* Nil
298
322
299instance
323instance
@@ -301,15 +325,23 @@ instance
301 , Has col row ty
325 , Has col row ty
302 , GroupedBy tab col bys
326 , GroupedBy tab col bys
303 ) => IsLabel col
327 ) => IsLabel col
304− (Expression commons schemas params ('Grouped bys) from ty) where
328+ (Expression ('Grouped bys) commons schemas params from ty) where
305 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
329 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
330+instance
331+ ( HasUnique tab from row
332+ , Has col row ty
333+ , GroupedBy tab col bys
334+ , tys ~ '[ty]
335+ ) => IsLabel col
336+ (NP (Expression ('Grouped bys) commons schemas params from) tys) where
337+ fromLabel = fromLabel @col :* Nil
306instance
338instance
307 ( HasUnique tab from row
339 ( HasUnique tab from row
308 , Has col row ty
340 , Has col row ty
309 , GroupedBy tab col bys
341 , GroupedBy tab col bys
310 , column ~ (col ::: ty)
342 , column ~ (col ::: ty)
311 ) => IsLabel col
343 ) => IsLabel col
312− (Aliased (Expression commons schemas params ('Grouped bys) from) column) where
344+ (Aliased (Expression ('Grouped bys) commons schemas params from) column) where
313 fromLabel = fromLabel @col `As` Alias
345 fromLabel = fromLabel @col `As` Alias
314instance
346instance
315 ( HasUnique tab from row
347 ( HasUnique tab from row
@@ -317,7 +349,7 @@ instance
317 , GroupedBy tab col bys
349 , GroupedBy tab col bys
318 , columns ~ '[col ::: ty]
350 , columns ~ '[col ::: ty]
319 ) => IsLabel col
351 ) => IsLabel col
320− (NP (Aliased (Expression commons schemas params ('Grouped bys) from)) columns) where
352+ (NP (Aliased (Expression ('Grouped bys) commons schemas params from)) columns) where
321 fromLabel = fromLabel @col :* Nil
353 fromLabel = fromLabel @col :* Nil
322
354
323instance
355instance
@@ -325,16 +357,24 @@ instance
325 , Has col row ty
357 , Has col row ty
326 , GroupedBy tab col bys
358 , GroupedBy tab col bys
327 ) => IsQualified tab col
359 ) => IsQualified tab col
328− (Expression commons schemas params ('Grouped bys) from ty) where
360+ (Expression ('Grouped bys) commons schemas params from ty) where
329 tab ! col = UnsafeExpression $
361 tab ! col = UnsafeExpression $
330 renderSQL tab <> "." <> renderSQL col
362 renderSQL tab <> "." <> renderSQL col
363+instance
364+ ( Has tab from row
365+ , Has col row ty
366+ , GroupedBy tab col bys
367+ , tys ~ '[ty]
368+ ) => IsQualified tab col
369+ (NP (Expression ('Grouped bys) commons schemas params from) tys) where
370+ tab ! col = tab ! col :* Nil
331instance
371instance
332 ( Has tab from row
372 ( Has tab from row
333 , Has col row ty
373 , Has col row ty
334 , GroupedBy tab col bys
374 , GroupedBy tab col bys
335 , column ~ (col ::: ty)
375 , column ~ (col ::: ty)
336 ) => IsQualified tab col
376 ) => IsQualified tab col
337− (Aliased (Expression commons schemas params ('Grouped bys) from) column) where
377+ (Aliased (Expression ('Grouped bys) commons schemas params from) column) where
338 tab ! col = tab ! col `As` col
378 tab ! col = tab ! col `As` col
339instance
379instance
340 ( Has tab from row
380 ( Has tab from row
@@ -342,7 +382,7 @@ instance
342 , GroupedBy tab col bys
382 , GroupedBy tab col bys
343 , columns ~ '[col ::: ty]
383 , columns ~ '[col ::: ty]
344 ) => IsQualified tab col
384 ) => IsQualified tab col
345− (NP (Aliased (Expression commons schemas params ('Grouped bys) from)) columns) where
385+ (NP (Aliased (Expression ('Grouped bys) commons schemas params from)) columns) where
346 tab ! col = tab ! col :* Nil
386 tab ! col = tab ! col :* Nil
347
387
348-- | analagous to `Nothing`
388-- | analagous to `Nothing`
@@ -366,11 +406,11 @@ notNull = UnsafeExpression . renderSQL
366-- >>> printSQL $ coalesce [null_, true] false
406-- >>> printSQL $ coalesce [null_, true] false
367-- COALESCE(NULL, TRUE, FALSE)
407-- COALESCE(NULL, TRUE, FALSE)
368coalesce
408coalesce
369− :: [Expression commons schemas params grp from ('Null ty)]
409+ :: [Expression grp commons schemas params from ('Null ty)]
370 -- ^ @NULL@s may be present
410 -- ^ @NULL@s may be present
371− -> Expression commons schemas params grp from ('NotNull ty)
411+ -> Expression grp commons schemas params from ('NotNull ty)
372 -- ^ @NULL@ is absent
412 -- ^ @NULL@ is absent
373− -> Expression commons schemas params grp from ('NotNull ty)
413+ -> Expression grp commons schemas params from ('NotNull ty)
374coalesce nullxs notNullx = UnsafeExpression $
414coalesce nullxs notNullx = UnsafeExpression $
375 "COALESCE" <> parenthesized (commaSeparated
415 "COALESCE" <> parenthesized (commaSeparated
376 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
416 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
@@ -380,26 +420,26 @@ coalesce nullxs notNullx = UnsafeExpression $
380-- >>> printSQL $ fromNull true null_
420-- >>> printSQL $ fromNull true null_
381-- COALESCE(NULL, TRUE)
421-- COALESCE(NULL, TRUE)
382fromNull
422fromNull
383− :: Expression commons schemas params grp from ('NotNull ty)
423+ :: Expression grp commons schemas params from ('NotNull ty)
384 -- ^ what to convert @NULL@ to
424 -- ^ what to convert @NULL@ to
385− -> Expression commons schemas params grp from ('Null ty)
425+ -> Expression grp commons schemas params from ('Null ty)
386− -> Expression commons schemas params grp from ('NotNull ty)
426+ -> Expression grp commons schemas params from ('NotNull ty)
387fromNull notNullx nullx = coalesce [nullx] notNullx
427fromNull notNullx nullx = coalesce [nullx] notNullx
388
428
389-- | >>> printSQL $ null_ & isNull
429-- | >>> printSQL $ null_ & isNull
390-- NULL IS NULL
430-- NULL IS NULL
391isNull
431isNull
392− :: Expression commons schemas params grp from ('Null ty)
432+ :: Expression grp commons schemas params from ('Null ty)
393 -- ^ possibly @NULL@
433 -- ^ possibly @NULL@
394− -> Condition commons schemas params grp from
434+ -> Condition grp commons schemas params from
395isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
435isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
396
436
397-- | >>> printSQL $ null_ & isNotNull
437-- | >>> printSQL $ null_ & isNotNull
398-- NULL IS NOT NULL
438-- NULL IS NOT NULL
399isNotNull
439isNotNull
400− :: Expression commons schemas params grp from ('Null ty)
440+ :: Expression grp commons schemas params from ('Null ty)
401 -- ^ possibly @NULL@
441 -- ^ possibly @NULL@
402− -> Condition commons schemas params grp from
442+ -> Condition grp commons schemas params from
403isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
443isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
404
444
405-- | analagous to `maybe` using @IS NULL@
445-- | analagous to `maybe` using @IS NULL@
@@ -407,13 +447,13 @@ isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
407-- >>> printSQL $ matchNull true not_ null_
447-- >>> printSQL $ matchNull true not_ null_
408-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
448-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
409matchNull
449matchNull
410− :: Expression commons schemas params grp from (nullty)
450+ :: Expression grp commons schemas params from (nullty)
411 -- ^ what to convert @NULL@ to
451 -- ^ what to convert @NULL@ to
412− -> ( Expression commons schemas params grp from ('NotNull ty)
452+ -> ( Expression grp commons schemas params from ('NotNull ty)
413− -> Expression commons schemas params grp from (nullty) )
453+ -> Expression grp commons schemas params from (nullty) )
414 -- ^ function to perform when @NULL@ is absent
454 -- ^ function to perform when @NULL@ is absent
415− -> Expression commons schemas params grp from ('Null ty)
455+ -> Expression grp commons schemas params from ('Null ty)
416− -> Expression commons schemas params grp from (nullty)
456+ -> Expression grp commons schemas params from (nullty)
417matchNull y f x = ifThenElse (isNull x) y
457matchNull y f x = ifThenElse (isNull x) y
418 (f (UnsafeExpression (renderSQL x)))
458 (f (UnsafeExpression (renderSQL x)))
419
459
@@ -421,25 +461,25 @@ matchNull y f x = ifThenElse (isNull x) y
421`nullIf` gives @NULL@.
461`nullIf` gives @NULL@.
422
462
423>>> :set -XTypeApplications -XDataKinds
463>>> :set -XTypeApplications -XDataKinds
424−>>> let expr = nullIf false (param @1) :: Expression commons schemas '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
464+>>> let expr = nullIf false (param @1) :: Expression grp commons schemas '[ 'NotNull 'PGbool] from ('Null 'PGbool)
425>>> printSQL expr
465>>> printSQL expr
426NULL IF (FALSE, ($1 :: bool))
466NULL IF (FALSE, ($1 :: bool))
427-}
467-}
428nullIf
468nullIf
429− :: Expression commons schemas params grp from ('NotNull ty)
469+ :: Expression grp commons schemas params from ('NotNull ty)
430 -- ^ @NULL@ is absent
470 -- ^ @NULL@ is absent
431− -> Expression commons schemas params grp from ('NotNull ty)
471+ -> Expression grp commons schemas params from ('NotNull ty)
432 -- ^ @NULL@ is absent
472 -- ^ @NULL@ is absent
433− -> Expression commons schemas params grp from ('Null ty)
473+ -> Expression grp commons schemas params from ('Null ty)
434nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
474nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
435 (renderSQL x <> ", " <> renderSQL y)
475 (renderSQL x <> ", " <> renderSQL y)
436
476
437-- | >>> printSQL $ array [null_, false, true]
477-- | >>> printSQL $ array [null_, false, true]
438-- ARRAY[NULL, FALSE, TRUE]
478-- ARRAY[NULL, FALSE, TRUE]
439array
479array
440− :: [Expression commons schemas params grp from ty]
480+ :: [Expression grp commons schemas params from ty]
441 -- ^ array elements
481 -- ^ array elements
442− -> Expression commons schemas params grp from (nullity ('PGvararray ty))
482+ -> Expression grp commons schemas params from (nullity ('PGvararray ty))
443array xs = UnsafeExpression $
483array xs = UnsafeExpression $
444 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
484 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
445
485
@@ -447,13 +487,13 @@ array xs = UnsafeExpression $
447-- (ARRAY[NULL, FALSE, TRUE])[2]
487-- (ARRAY[NULL, FALSE, TRUE])[2]
448index
488index
449 :: Word64 -- ^ index
489 :: Word64 -- ^ index
450− -> Expression commons schemas params grp from (nullity ('PGvararray ty)) -- ^ array
490+ -> Expression grp commons schemas params from (nullity ('PGvararray ty)) -- ^ array
451− -> Expression commons schemas params grp from (NullifyType ty)
491+ -> Expression grp commons schemas params from (NullifyType ty)
452index n expr = UnsafeExpression $
492index n expr = UnsafeExpression $
453 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
493 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
454
494
455instance (KnownSymbol label, label `In` labels) => IsPGlabel label
495instance (KnownSymbol label, label `In` labels) => IsPGlabel label
456− (Expression commons schemas params grp from (nullity ('PGenum labels))) where
496+ (Expression grp commons schemas params from (nullity ('PGenum labels))) where
457 label = UnsafeExpression $ renderSQL (PGlabel @label)
497 label = UnsafeExpression $ renderSQL (PGlabel @label)
458
498
459-- | A row constructor is an expression that builds a row value
499-- | A row constructor is an expression that builds a row value
@@ -465,14 +505,14 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
465-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
505-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
466-- :}
506-- :}
467--
507--
468−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression commons schemas from grp params ('NotNull Complex)
508+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression grp commons schemas params from ('NotNull Complex)
469-- >>> printSQL i
509-- >>> printSQL i
470-- ROW(0, 1)
510-- ROW(0, 1)
471row
511row
472 :: SListI row
512 :: SListI row
473− => NP (Aliased (Expression commons schemas params grp from)) row
513+ => NP (Aliased (Expression grp commons schemas params from)) row
474 -- ^ zero or more expressions for the row field values
514 -- ^ zero or more expressions for the row field values
475− -> Expression commons schemas params grp from (nullity ('PGcomposite row))
515+ -> Expression grp commons schemas params from (nullity ('PGcomposite row))
476row exprs = UnsafeExpression $ "ROW" <> parenthesized
516row exprs = UnsafeExpression $ "ROW" <> parenthesized
477 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
517 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
478
518
@@ -483,7 +523,7 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
483-- type Schema = '["complex" ::: 'Typedef Complex]
523-- type Schema = '["complex" ::: 'Typedef Complex]
484-- :}
524-- :}
485--
525--
486−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] (Public Schema) from grp params ('NotNull Complex)
526+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression grp '[] (Public Schema) from params ('NotNull Complex)
487-- >>> printSQL $ i & field #complex #imaginary
527-- >>> printSQL $ i & field #complex #imaginary
488-- (ROW(0, 1)::"complex")."imaginary"
528-- (ROW(0, 1)::"complex")."imaginary"
489field
529field
@@ -492,41 +532,41 @@ field
492 , Has field row ty)
532 , Has field row ty)
493 => QualifiedAlias sch tydef -- ^ row type
533 => QualifiedAlias sch tydef -- ^ row type
494 -> Alias field -- ^ field name
534 -> Alias field -- ^ field name
495− -> Expression commons schemas params grp from ('NotNull ('PGcomposite row))
535+ -> Expression grp commons schemas params from ('NotNull ('PGcomposite row))
496− -> Expression commons schemas params grp from ty
536+ -> Expression grp commons schemas params from ty
497field td fld expr = UnsafeExpression $
537field td fld expr = UnsafeExpression $
498 parenthesized (renderSQL expr <> "::" <> renderSQL td)
538 parenthesized (renderSQL expr <> "::" <> renderSQL td)
499 <> "." <> renderSQL fld
539 <> "." <> renderSQL fld
500
540
501instance Semigroup
541instance Semigroup
502− (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
542+ (Expression grp commons schemas params from (nullity ('PGvararray ty))) where
503 (<>) = unsafeBinaryOp "||"
543 (<>) = unsafeBinaryOp "||"
504
544
505instance Monoid
545instance Monoid
506− (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
546+ (Expression grp commons schemas params from (nullity ('PGvararray ty))) where
507 mempty = array []
547 mempty = array []
508 mappend = (<>)
548 mappend = (<>)
509
549
510−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression commons schemas '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
550+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression grp commons schemas '[ 'NotNull 'PGtimestamptz] from ('NotNull 'PGtimestamptz)
511-- >>> printSQL expr
551-- >>> printSQL expr
512-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
552-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
513greatest
553greatest
514− :: Expression commons schemas params grp from (nullty)
554+ :: Expression grp commons schemas params from (nullty)
515 -- ^ needs at least 1 argument
555 -- ^ needs at least 1 argument
516− -> [Expression commons schemas params grp from (nullty)]
556+ -> [Expression grp commons schemas params from (nullty)]
517 -- ^ or more
557 -- ^ or more
518− -> Expression commons schemas params grp from (nullty)
558+ -> Expression grp commons schemas params from (nullty)
519greatest x xs = UnsafeExpression $ "GREATEST("
559greatest x xs = UnsafeExpression $ "GREATEST("
520 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
560 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
521
561
522-- | >>> printSQL $ least currentTimestamp [null_]
562-- | >>> printSQL $ least currentTimestamp [null_]
523-- LEAST(CURRENT_TIMESTAMP, NULL)
563-- LEAST(CURRENT_TIMESTAMP, NULL)
524least
564least
525− :: Expression commons schemas params grp from (nullty)
565+ :: Expression grp commons schemas params from (nullty)
526 -- ^ needs at least 1 argument
566 -- ^ needs at least 1 argument
527− -> [Expression commons schemas params grp from (nullty)]
567+ -> [Expression grp commons schemas params from (nullty)]
528 -- ^ or more
568 -- ^ or more
529− -> Expression commons schemas params grp from (nullty)
569+ -> Expression grp commons schemas params from (nullty)
530least x xs = UnsafeExpression $ "LEAST("
570least x xs = UnsafeExpression $ "LEAST("
531 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
571 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
532
572
@@ -535,9 +575,9 @@ least x xs = UnsafeExpression $ "LEAST("
535unsafeBinaryOp
575unsafeBinaryOp
536 :: ByteString
576 :: ByteString
537 -- ^ operator
577 -- ^ operator
538− -> Expression commons schemas params grp from (ty0)
578+ -> Expression grp commons schemas params from (ty0)
539− -> Expression commons schemas params grp from (ty1)
579+ -> Expression grp commons schemas params from (ty1)
540− -> Expression commons schemas params grp from (ty2)
580+ -> Expression grp commons schemas params from (ty2)
541unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
581unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
542 renderSQL x <+> op <+> renderSQL y
582 renderSQL x <+> op <+> renderSQL y
543
583
@@ -546,8 +586,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
546unsafeUnaryOp
586unsafeUnaryOp
547 :: ByteString
587 :: ByteString
548 -- ^ operator
588 -- ^ operator
549− -> Expression commons schemas params grp from (ty0)
589+ -> Expression grp commons schemas params from (ty0)
550− -> Expression commons schemas params grp from (ty1)
590+ -> Expression grp commons schemas params from (ty1)
551unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
591unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
552 op <+> renderSQL x
592 op <+> renderSQL x
553
593
@@ -556,8 +596,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
556unsafeFunction
596unsafeFunction
557 :: ByteString
597 :: ByteString
558 -- ^ function
598 -- ^ function
559− -> Expression commons schemas params grp from (xty)
599+ -> Expression grp commons schemas params from (xty)
560− -> Expression commons schemas params grp from (yty)
600+ -> Expression grp commons schemas params from (yty)
561unsafeFunction fun x = UnsafeExpression $
601unsafeFunction fun x = UnsafeExpression $
562 fun <> parenthesized (renderSQL x)
602 fun <> parenthesized (renderSQL x)
563
603
@@ -566,13 +606,13 @@ unsafeVariadicFunction
566 :: SListI elems
606 :: SListI elems
567 => ByteString
607 => ByteString
568 -- ^ function
608 -- ^ function
569− -> NP (Expression commons schemas params grp from) elems
609+ -> NP (Expression grp commons schemas params from) elems
570− -> Expression commons schemas params grp from ret
610+ -> Expression grp commons schemas params from ret
571unsafeVariadicFunction fun x = UnsafeExpression $
611unsafeVariadicFunction fun x = UnsafeExpression $
572 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
612 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
573
613
574instance ty `In` PGNum
614instance ty `In` PGNum
575− => Num (Expression commons schemas params grp from (nullity ty)) where
615+ => Num (Expression grp commons schemas params from (nullity ty)) where
576 (+) = unsafeBinaryOp "+"
616 (+) = unsafeBinaryOp "+"
577 (-) = unsafeBinaryOp "-"
617 (-) = unsafeBinaryOp "-"
578 (*) = unsafeBinaryOp "*"
618 (*) = unsafeBinaryOp "*"
@@ -584,12 +624,12 @@ instance ty `In` PGNum
584 . show
624 . show
585
625
586instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
626instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
587− (Expression commons schemas params grp from (nullity ty)) where
627+ (Expression grp commons schemas params from (nullity ty)) where
588 (/) = unsafeBinaryOp "/"
628 (/) = unsafeBinaryOp "/"
589 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
629 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
590
630
591instance (ty `In` PGNum, ty `In` PGFloating) => Floating
631instance (ty `In` PGNum, ty `In` PGFloating) => Floating
592− (Expression commons schemas params grp from (nullity ty)) where
632+ (Expression grp commons schemas params from (nullity ty)) where
593 pi = UnsafeExpression "pi()"
633 pi = UnsafeExpression "pi()"
594 exp = unsafeFunction "exp"
634 exp = unsafeFunction "exp"
595 log = unsafeFunction "ln"
635 log = unsafeFunction "ln"
@@ -612,18 +652,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
612
652
613-- | >>> :{
653-- | >>> :{
614-- let
654-- let
615−-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
655+-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
616-- expression = atan2_ pi 2
656-- expression = atan2_ pi 2
617-- in printSQL expression
657-- in printSQL expression
618-- :}
658-- :}
619-- atan2(pi(), 2)
659-- atan2(pi(), 2)
620atan2_
660atan2_
621 :: float `In` PGFloating
661 :: float `In` PGFloating
622− => Expression commons schemas params grp from (nullity float)
662+ => Expression grp commons schemas params from (nullity float)
623 -- ^ numerator
663 -- ^ numerator
624− -> Expression commons schemas params grp from (nullity float)
664+ -> Expression grp commons schemas params from (nullity float)
625 -- ^ denominator
665 -- ^ denominator
626− -> Expression commons schemas params grp from (nullity float)
666+ -> Expression grp commons schemas params from (nullity float)
627atan2_ y x = UnsafeExpression $
667atan2_ y x = UnsafeExpression $
628 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
668 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
629
669
@@ -636,9 +676,9 @@ atan2_ y x = UnsafeExpression $
636cast
676cast
637 :: TypeExpression schemas ty1
677 :: TypeExpression schemas ty1
638 -- ^ type to cast as
678 -- ^ type to cast as
639− -> Expression commons schemas params grp from ty0
679+ -> Expression grp commons schemas params from ty0
640 -- ^ value to convert
680 -- ^ value to convert
641− -> Expression commons schemas params grp from ty1
681+ -> Expression grp commons schemas params from ty1
642cast ty x = UnsafeExpression $ parenthesized $
682cast ty x = UnsafeExpression $ parenthesized $
643 renderSQL x <+> "::" <+> renderSQL ty
683 renderSQL x <+> "::" <+> renderSQL ty
644
684
@@ -646,136 +686,136 @@ cast ty x = UnsafeExpression $ parenthesized $
646--
686--
647-- >>> :{
687-- >>> :{
648-- let
688-- let
649−-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
689+-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
650-- expression = 5 `quot_` 2
690-- expression = 5 `quot_` 2
651-- in printSQL expression
691-- in printSQL expression
652-- :}
692-- :}
653-- (5 / 2)
693-- (5 / 2)
654quot_
694quot_
655 :: int `In` PGIntegral
695 :: int `In` PGIntegral
656− => Expression commons schemas params grp from (nullity int)
696+ => Expression grp commons schemas params from (nullity int)
657 -- ^ numerator
697 -- ^ numerator
658− -> Expression commons schemas params grp from (nullity int)
698+ -> Expression grp commons schemas params from (nullity int)
659 -- ^ denominator
699 -- ^ denominator
660− -> Expression commons schemas params grp from (nullity int)
700+ -> Expression grp commons schemas params from (nullity int)
661quot_ = unsafeBinaryOp "/"
701quot_ = unsafeBinaryOp "/"
662
702
663-- | remainder upon integer division
703-- | remainder upon integer division
664--
704--
665-- >>> :{
705-- >>> :{
666-- let
706-- let
667−-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
707+-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
668-- expression = 5 `rem_` 2
708-- expression = 5 `rem_` 2
669-- in printSQL expression
709-- in printSQL expression
670-- :}
710-- :}
671-- (5 % 2)
711-- (5 % 2)
672rem_
712rem_
673 :: int `In` PGIntegral
713 :: int `In` PGIntegral
674− => Expression commons schemas params grp from (nullity int)
714+ => Expression grp commons schemas params from (nullity int)
675 -- ^ numerator
715 -- ^ numerator
676− -> Expression commons schemas params grp from (nullity int)
716+ -> Expression grp commons schemas params from (nullity int)
677 -- ^ denominator
717 -- ^ denominator
678− -> Expression commons schemas params grp from (nullity int)
718+ -> Expression grp commons schemas params from (nullity int)
679rem_ = unsafeBinaryOp "%"
719rem_ = unsafeBinaryOp "%"
680
720
681-- | >>> :{
721-- | >>> :{
682-- let
722-- let
683−-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
723+-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
684-- expression = trunc pi
724-- expression = trunc pi
685-- in printSQL expression
725-- in printSQL expression
686-- :}
726-- :}
687-- trunc(pi())
727-- trunc(pi())
688trunc
728trunc
689 :: frac `In` PGFloating
729 :: frac `In` PGFloating
690− => Expression commons schemas params grp from (nullity frac)
730+ => Expression grp commons schemas params from (nullity frac)
691 -- ^ fractional number
731 -- ^ fractional number
692− -> Expression commons schemas params grp from (nullity frac)
732+ -> Expression grp commons schemas params from (nullity frac)
693trunc = unsafeFunction "trunc"
733trunc = unsafeFunction "trunc"
694
734
695-- | >>> :{
735-- | >>> :{
696-- let
736-- let
697−-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
737+-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
698-- expression = round_ pi
738-- expression = round_ pi
699-- in printSQL expression
739-- in printSQL expression
700-- :}
740-- :}
701-- round(pi())
741-- round(pi())
702round_
742round_
703 :: frac `In` PGFloating
743 :: frac `In` PGFloating
704− => Expression commons schemas params grp from (nullity frac)
744+ => Expression grp commons schemas params from (nullity frac)
705 -- ^ fractional number
745 -- ^ fractional number
706− -> Expression commons schemas params grp from (nullity frac)
746+ -> Expression grp commons schemas params from (nullity frac)
707round_ = unsafeFunction "round"
747round_ = unsafeFunction "round"
708
748
709-- | >>> :{
749-- | >>> :{
710-- let
750-- let
711−-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
751+-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
712-- expression = ceiling_ pi
752-- expression = ceiling_ pi
713-- in printSQL expression
753-- in printSQL expression
714-- :}
754-- :}
715-- ceiling(pi())
755-- ceiling(pi())
716ceiling_
756ceiling_
717 :: frac `In` PGFloating
757 :: frac `In` PGFloating
718− => Expression commons schemas params grp from (nullity frac)
758+ => Expression grp commons schemas params from (nullity frac)
719 -- ^ fractional number
759 -- ^ fractional number
720− -> Expression commons schemas params grp from (nullity frac)
760+ -> Expression grp commons schemas params from (nullity frac)
721ceiling_ = unsafeFunction "ceiling"
761ceiling_ = unsafeFunction "ceiling"
722
762
723-- | A `Condition` is an `Expression`, which can evaluate
763-- | A `Condition` is an `Expression`, which can evaluate
724-- to `true`, `false` or `null_`. This is because SQL uses
764-- to `true`, `false` or `null_`. This is because SQL uses
725-- a three valued logic.
765-- a three valued logic.
726−type Condition commons schemas params grp from =
766+type Condition grp commons schemas params from =
727− Expression commons schemas params grp from ('Null 'PGbool)
767+ Expression grp commons schemas params from ('Null 'PGbool)
728
768
729-- | >>> printSQL true
769-- | >>> printSQL true
730-- TRUE
770-- TRUE
731−true :: Expression commons schemas params grp from (nullity 'PGbool)
771+true :: Expression grp commons schemas params from (nullity 'PGbool)
732true = UnsafeExpression "TRUE"
772true = UnsafeExpression "TRUE"
733
773
734-- | >>> printSQL false
774-- | >>> printSQL false
735-- FALSE
775-- FALSE
736−false :: Expression commons schemas params grp from (nullity 'PGbool)
776+false :: Expression grp commons schemas params from (nullity 'PGbool)
737false = UnsafeExpression "FALSE"
777false = UnsafeExpression "FALSE"
738
778
739-- | >>> printSQL $ not_ true
779-- | >>> printSQL $ not_ true
740-- (NOT TRUE)
780-- (NOT TRUE)
741not_
781not_
742− :: Expression commons schemas params grp from (nullity 'PGbool)
782+ :: Expression grp commons schemas params from (nullity 'PGbool)
743− -> Expression commons schemas params grp from (nullity 'PGbool)
783+ -> Expression grp commons schemas params from (nullity 'PGbool)
744not_ = unsafeUnaryOp "NOT"
784not_ = unsafeUnaryOp "NOT"
745
785
746-- | >>> printSQL $ true .&& false
786-- | >>> printSQL $ true .&& false
747-- (TRUE AND FALSE)
787-- (TRUE AND FALSE)
748(.&&)
788(.&&)
749− :: Expression commons schemas params grp from (nullity 'PGbool)
789+ :: Expression grp commons schemas params from (nullity 'PGbool)
750− -> Expression commons schemas params grp from (nullity 'PGbool)
790+ -> Expression grp commons schemas params from (nullity 'PGbool)
751− -> Expression commons schemas params grp from (nullity 'PGbool)
791+ -> Expression grp commons schemas params from (nullity 'PGbool)
752infixr 3 .&&
792infixr 3 .&&
753(.&&) = unsafeBinaryOp "AND"
793(.&&) = unsafeBinaryOp "AND"
754
794
755-- | >>> printSQL $ true .|| false
795-- | >>> printSQL $ true .|| false
756-- (TRUE OR FALSE)
796-- (TRUE OR FALSE)
757(.||)
797(.||)
758− :: Expression commons schemas params grp from (nullity 'PGbool)
798+ :: Expression grp commons schemas params from (nullity 'PGbool)
759− -> Expression commons schemas params grp from (nullity 'PGbool)
799+ -> Expression grp commons schemas params from (nullity 'PGbool)
760− -> Expression commons schemas params grp from (nullity 'PGbool)
800+ -> Expression grp commons schemas params from (nullity 'PGbool)
761infixr 2 .||
801infixr 2 .||
762(.||) = unsafeBinaryOp "OR"
802(.||) = unsafeBinaryOp "OR"
763
803
764-- | >>> :{
804-- | >>> :{
765-- let
805-- let
766−-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
806+-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
767-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
807-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
768-- in printSQL expression
808-- in printSQL expression
769-- :}
809-- :}
770-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
810-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
771caseWhenThenElse
811caseWhenThenElse
772− :: [ ( Condition commons schemas params grp from
812+ :: [ ( Condition grp commons schemas params from
773− , Expression commons schemas params grp from ty
813+ , Expression grp commons schemas params from ty
774 ) ]
814 ) ]
775 -- ^ whens and thens
815 -- ^ whens and thens
776− -> Expression commons schemas params grp from ty
816+ -> Expression grp commons schemas params from ty
777 -- ^ else
817 -- ^ else
778− -> Expression commons schemas params grp from ty
818+ -> Expression grp commons schemas params from ty
779caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
819caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
780 [ "CASE"
820 [ "CASE"
781 , mconcat
821 , mconcat
@@ -791,16 +831,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
791
831
792-- | >>> :{
832-- | >>> :{
793-- let
833-- let
794−-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
834+-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
795-- expression = ifThenElse true 1 0
835-- expression = ifThenElse true 1 0
796-- in printSQL expression
836-- in printSQL expression
797-- :}
837-- :}
798-- CASE WHEN TRUE THEN 1 ELSE 0 END
838-- CASE WHEN TRUE THEN 1 ELSE 0 END
799ifThenElse
839ifThenElse
800− :: Condition commons schemas params grp from
840+ :: Condition grp commons schemas params from
801− -> Expression commons schemas params grp from ty -- ^ then
841+ -> Expression grp commons schemas params from ty -- ^ then
802− -> Expression commons schemas params grp from ty -- ^ else
842+ -> Expression grp commons schemas params from ty -- ^ else
803− -> Expression commons schemas params grp from ty
843+ -> Expression grp commons schemas params from ty
804ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
844ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
805
845
806-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
846-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -809,85 +849,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
809-- >>> printSQL $ true .== null_
849-- >>> printSQL $ true .== null_
810-- (TRUE = NULL)
850-- (TRUE = NULL)
811(.==)
851(.==)
812− :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
852+ :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
813− -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
853+ -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
814− -> Condition commons schemas params grp from
854+ -> Condition grp commons schemas params from
815(.==) = unsafeBinaryOp "="
855(.==) = unsafeBinaryOp "="
816infix 4 .==
856infix 4 .==
817
857
818-- | >>> printSQL $ true ./= null_
858-- | >>> printSQL $ true ./= null_
819-- (TRUE <> NULL)
859-- (TRUE <> NULL)
820(./=)
860(./=)
821− :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
861+ :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
822− -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
862+ -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
823− -> Condition commons schemas params grp from
863+ -> Condition grp commons schemas params from
824(./=) = unsafeBinaryOp "<>"
864(./=) = unsafeBinaryOp "<>"
825infix 4 ./=
865infix 4 ./=
826
866
827-- | >>> printSQL $ true .>= null_
867-- | >>> printSQL $ true .>= null_
828-- (TRUE >= NULL)
868-- (TRUE >= NULL)
829(.>=)
869(.>=)
830− :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
870+ :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
831− -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
871+ -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
832− -> Condition commons schemas params grp from
872+ -> Condition grp commons schemas params from
833(.>=) = unsafeBinaryOp ">="
873(.>=) = unsafeBinaryOp ">="
834infix 4 .>=
874infix 4 .>=
835
875
836-- | >>> printSQL $ true .< null_
876-- | >>> printSQL $ true .< null_
837-- (TRUE < NULL)
877-- (TRUE < NULL)
838(.<)
878(.<)
839− :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
879+ :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
840− -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
880+ -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
841− -> Condition commons schemas params grp from
881+ -> Condition grp commons schemas params from
842(.<) = unsafeBinaryOp "<"
882(.<) = unsafeBinaryOp "<"
843infix 4 .<
883infix 4 .<
844
884
845-- | >>> printSQL $ true .<= null_
885-- | >>> printSQL $ true .<= null_
846-- (TRUE <= NULL)
886-- (TRUE <= NULL)
847(.<=)
887(.<=)
848− :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
888+ :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
849− -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
889+ -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
850− -> Condition commons schemas params grp from
890+ -> Condition grp commons schemas params from
851(.<=) = unsafeBinaryOp "<="
891(.<=) = unsafeBinaryOp "<="
852infix 4 .<=
892infix 4 .<=
853
893
854-- | >>> printSQL $ true .> null_
894-- | >>> printSQL $ true .> null_
855-- (TRUE > NULL)
895-- (TRUE > NULL)
856(.>)
896(.>)
857− :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
897+ :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
858− -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
898+ -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
859− -> Condition commons schemas params grp from
899+ -> Condition grp commons schemas params from
860(.>) = unsafeBinaryOp ">"
900(.>) = unsafeBinaryOp ">"
861infix 4 .>
901infix 4 .>
862
902
863-- | >>> printSQL currentDate
903-- | >>> printSQL currentDate
864-- CURRENT_DATE
904-- CURRENT_DATE
865currentDate
905currentDate
866− :: Expression commons schemas params grp from (nullity 'PGdate)
906+ :: Expression grp commons schemas params from (nullity 'PGdate)
867currentDate = UnsafeExpression "CURRENT_DATE"
907currentDate = UnsafeExpression "CURRENT_DATE"
868
908
869-- | >>> printSQL currentTime
909-- | >>> printSQL currentTime
870-- CURRENT_TIME
910-- CURRENT_TIME
871currentTime
911currentTime
872− :: Expression commons schemas params grp from (nullity 'PGtimetz)
912+ :: Expression grp commons schemas params from (nullity 'PGtimetz)
873currentTime = UnsafeExpression "CURRENT_TIME"
913currentTime = UnsafeExpression "CURRENT_TIME"
874
914
875-- | >>> printSQL currentTimestamp
915-- | >>> printSQL currentTimestamp
876-- CURRENT_TIMESTAMP
916-- CURRENT_TIMESTAMP
877currentTimestamp
917currentTimestamp
878− :: Expression commons schemas params grp from (nullity 'PGtimestamptz)
918+ :: Expression grp commons schemas params from (nullity 'PGtimestamptz)
879currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
919currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
880
920
881-- | >>> printSQL localTime
921-- | >>> printSQL localTime
882-- LOCALTIME
922-- LOCALTIME
883localTime
923localTime
884− :: Expression commons schemas params grp from (nullity 'PGtime)
924+ :: Expression grp commons schemas params from (nullity 'PGtime)
885localTime = UnsafeExpression "LOCALTIME"
925localTime = UnsafeExpression "LOCALTIME"
886
926
887-- | >>> printSQL localTimestamp
927-- | >>> printSQL localTimestamp
888-- LOCALTIMESTAMP
928-- LOCALTIMESTAMP
889localTimestamp
929localTimestamp
890− :: Expression commons schemas params grp from (nullity 'PGtimestamp)
930+ :: Expression grp commons schemas params from (nullity 'PGtimestamp)
891localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
931localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
892
932
893{-----------------------------------------
933{-----------------------------------------
@@ -895,7 +935,7 @@ text
895-----------------------------------------}
935-----------------------------------------}
896
936
897instance IsString
937instance IsString
898− (Expression commons schemas params grp from (nullity 'PGtext)) where
938+ (Expression grp commons schemas params from (nullity 'PGtext)) where
899 fromString str = UnsafeExpression $
939 fromString str = UnsafeExpression $
900 "E\'" <> fromString (escape =<< str) <> "\'"
940 "E\'" <> fromString (escape =<< str) <> "\'"
901 where
941 where
@@ -911,36 +951,36 @@ instance IsString
911 c -> [c]
951 c -> [c]
912
952
913instance Semigroup
953instance Semigroup
914− (Expression commons schemas params grp from (nullity 'PGtext)) where
954+ (Expression grp commons schemas params from (nullity 'PGtext)) where
915 (<>) = unsafeBinaryOp "||"
955 (<>) = unsafeBinaryOp "||"
916
956
917instance Monoid
957instance Monoid
918− (Expression commons schemas params grp from (nullity 'PGtext)) where
958+ (Expression grp commons schemas params from (nullity 'PGtext)) where
919 mempty = fromString ""
959 mempty = fromString ""
920 mappend = (<>)
960 mappend = (<>)
921
961
922-- | >>> printSQL $ lower "ARRRGGG"
962-- | >>> printSQL $ lower "ARRRGGG"
923-- lower(E'ARRRGGG')
963-- lower(E'ARRRGGG')
924lower
964lower
925− :: Expression commons schemas params grp from (nullity 'PGtext)
965+ :: Expression grp commons schemas params from (nullity 'PGtext)
926 -- ^ string to lower case
966 -- ^ string to lower case
927− -> Expression commons schemas params grp from (nullity 'PGtext)
967+ -> Expression grp commons schemas params from (nullity 'PGtext)
928lower = unsafeFunction "lower"
968lower = unsafeFunction "lower"
929
969
930-- | >>> printSQL $ upper "eeee"
970-- | >>> printSQL $ upper "eeee"
931-- upper(E'eeee')
971-- upper(E'eeee')
932upper
972upper
933− :: Expression commons schemas params grp from (nullity 'PGtext)
973+ :: Expression grp commons schemas params from (nullity 'PGtext)
934 -- ^ string to upper case
974 -- ^ string to upper case
935− -> Expression commons schemas params grp from (nullity 'PGtext)
975+ -> Expression grp commons schemas params from (nullity 'PGtext)
936upper = unsafeFunction "upper"
976upper = unsafeFunction "upper"
937
977
938-- | >>> printSQL $ charLength "four"
978-- | >>> printSQL $ charLength "four"
939-- char_length(E'four')
979-- char_length(E'four')
940charLength
980charLength
941− :: Expression commons schemas params grp from (nullity 'PGtext)
981+ :: Expression grp commons schemas params from (nullity 'PGtext)
942 -- ^ string to measure
982 -- ^ string to measure
943− -> Expression commons schemas params grp from (nullity 'PGint4)
983+ -> Expression grp commons schemas params from (nullity 'PGint4)
944charLength = unsafeFunction "char_length"
984charLength = unsafeFunction "char_length"
945
985
946-- | The `like` expression returns true if the @string@ matches
986-- | The `like` expression returns true if the @string@ matches
@@ -953,11 +993,11 @@ charLength = unsafeFunction "char_length"
953-- >>> printSQL $ "abc" `like` "a%"
993-- >>> printSQL $ "abc" `like` "a%"
954-- (E'abc' LIKE E'a%')
994-- (E'abc' LIKE E'a%')
955like
995like
956− :: Expression commons schemas params grp from (nullity 'PGtext)
996+ :: Expression grp commons schemas params from (nullity 'PGtext)
957 -- ^ string
997 -- ^ string
958− -> Expression commons schemas params grp from (nullity 'PGtext)
998+ -> Expression grp commons schemas params from (nullity 'PGtext)
959 -- ^ pattern
999 -- ^ pattern
960− -> Expression commons schemas params grp from (nullity 'PGbool)
1000+ -> Expression grp commons schemas params from (nullity 'PGbool)
961like = unsafeBinaryOp "LIKE"
1001like = unsafeBinaryOp "LIKE"
962
1002
963-- | The key word ILIKE can be used instead of LIKE to make the
1003-- | The key word ILIKE can be used instead of LIKE to make the
@@ -966,11 +1006,11 @@ like = unsafeBinaryOp "LIKE"
966-- >>> printSQL $ "abc" `ilike` "a%"
1006-- >>> printSQL $ "abc" `ilike` "a%"
967-- (E'abc' ILIKE E'a%')
1007-- (E'abc' ILIKE E'a%')
968ilike
1008ilike
969− :: Expression commons schemas params grp from (nullity 'PGtext)
1009+ :: Expression grp commons schemas params from (nullity 'PGtext)
970 -- ^ string
1010 -- ^ string
971− -> Expression commons schemas params grp from (nullity 'PGtext)
1011+ -> Expression grp commons schemas params from (nullity 'PGtext)
972 -- ^ pattern
1012 -- ^ pattern
973− -> Expression commons schemas params grp from (nullity 'PGbool)
1013+ -> Expression grp commons schemas params from (nullity 'PGbool)
974ilike = unsafeBinaryOp "ILIKE"
1014ilike = unsafeBinaryOp "ILIKE"
975
1015
976{-----------------------------------------
1016{-----------------------------------------
@@ -985,36 +1025,36 @@ Table 9.44: json and jsonb operators
985-- | Get JSON value (object field or array element) at a key.
1025-- | Get JSON value (object field or array element) at a key.
986(.->)
1026(.->)
987 :: (json `In` PGJsonType, key `In` PGJsonKey)
1027 :: (json `In` PGJsonType, key `In` PGJsonKey)
988− => Expression commons schemas params grp from (nullity json)
1028+ => Expression grp commons schemas params from (nullity json)
989− -> Expression commons schemas params grp from (nullity key)
1029+ -> Expression grp commons schemas params from (nullity key)
990− -> Expression commons schemas params grp from ('Null json)
1030+ -> Expression grp commons schemas params from ('Null json)
991infixl 8 .->
1031infixl 8 .->
992(.->) = unsafeBinaryOp "->"
1032(.->) = unsafeBinaryOp "->"
993
1033
994-- | Get JSON value (object field or array element) at a key, as text.
1034-- | Get JSON value (object field or array element) at a key, as text.
995(.->>)
1035(.->>)
996 :: (json `In` PGJsonType, key `In` PGJsonKey)
1036 :: (json `In` PGJsonType, key `In` PGJsonKey)
997− => Expression commons schemas params grp from (nullity json)
1037+ => Expression grp commons schemas params from (nullity json)
998− -> Expression commons schemas params grp from (nullity key)
1038+ -> Expression grp commons schemas params from (nullity key)
999− -> Expression commons schemas params grp from ('Null 'PGtext)
1039+ -> Expression grp commons schemas params from ('Null 'PGtext)
1000infixl 8 .->>
1040infixl 8 .->>
1001(.->>) = unsafeBinaryOp "->>"
1041(.->>) = unsafeBinaryOp "->>"
1002
1042
1003-- | Get JSON value at a specified path.
1043-- | Get JSON value at a specified path.
1004(.#>)
1044(.#>)
1005 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1045 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1006− => Expression commons schemas params grp from (nullity json)
1046+ => Expression grp commons schemas params from (nullity json)
1007− -> Expression commons schemas params grp from (nullity path)
1047+ -> Expression grp commons schemas params from (nullity path)
1008− -> Expression commons schemas params grp from ('Null json)
1048+ -> Expression grp commons schemas params from ('Null json)
1009infixl 8 .#>
1049infixl 8 .#>
1010(.#>) = unsafeBinaryOp "#>"
1050(.#>) = unsafeBinaryOp "#>"
1011
1051
1012-- | Get JSON value at a specified path as text.
1052-- | Get JSON value at a specified path as text.
1013(.#>>)
1053(.#>>)
1014 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1054 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1015− => Expression commons schemas params grp from (nullity json)
1055+ => Expression grp commons schemas params from (nullity json)
1016− -> Expression commons schemas params grp from (nullity path)
1056+ -> Expression grp commons schemas params from (nullity path)
1017− -> Expression commons schemas params grp from ('Null 'PGtext)
1057+ -> Expression grp commons schemas params from ('Null 'PGtext)
1018infixl 8 .#>>
1058infixl 8 .#>>
1019(.#>>) = unsafeBinaryOp "#>>"
1059(.#>>) = unsafeBinaryOp "#>>"
1020
1060
@@ -1023,42 +1063,42 @@ infixl 8 .#>>
1023-- | Does the left JSON value contain the right JSON path/value entries at the
1063-- | Does the left JSON value contain the right JSON path/value entries at the
1024-- top level?
1064-- top level?
1025(.@>)
1065(.@>)
1026− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1066+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1027− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1067+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1028− -> Condition commons schemas params grp from
1068+ -> Condition grp commons schemas params from
1029infixl 9 .@>
1069infixl 9 .@>
1030(.@>) = unsafeBinaryOp "@>"
1070(.@>) = unsafeBinaryOp "@>"
1031
1071
1032-- | Are the left JSON path/value entries contained at the top level within the
1072-- | Are the left JSON path/value entries contained at the top level within the
1033-- right JSON value?
1073-- right JSON value?
1034(.<@)
1074(.<@)
1035− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1075+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1036− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1076+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1037− -> Condition commons schemas params grp from
1077+ -> Condition grp commons schemas params from
1038infixl 9 .<@
1078infixl 9 .<@
1039(.<@) = unsafeBinaryOp "<@"
1079(.<@) = unsafeBinaryOp "<@"
1040
1080
1041-- | Does the string exist as a top-level key within the JSON value?
1081-- | Does the string exist as a top-level key within the JSON value?
1042(.?)
1082(.?)
1043− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1083+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1044− -> Expression commons schemas params grp from (nullity 'PGtext)
1084+ -> Expression grp commons schemas params from (nullity 'PGtext)
1045− -> Condition commons schemas params grp from
1085+ -> Condition grp commons schemas params from
1046infixl 9 .?
1086infixl 9 .?
1047(.?) = unsafeBinaryOp "?"
1087(.?) = unsafeBinaryOp "?"
1048
1088
1049-- | Do any of these array strings exist as top-level keys?
1089-- | Do any of these array strings exist as top-level keys?
1050(.?|)
1090(.?|)
1051− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1091+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1052− -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1092+ -> Expression grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1053− -> Condition commons schemas params grp from
1093+ -> Condition grp commons schemas params from
1054infixl 9 .?|
1094infixl 9 .?|
1055(.?|) = unsafeBinaryOp "?|"
1095(.?|) = unsafeBinaryOp "?|"
1056
1096
1057-- | Do all of these array strings exist as top-level keys?
1097-- | Do all of these array strings exist as top-level keys?
1058(.?&)
1098(.?&)
1059− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1099+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1060− -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1100+ -> Expression grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1061− -> Condition commons schemas params grp from
1101+ -> Condition grp commons schemas params from
1062infixl 9 .?&
1102infixl 9 .?&
1063(.?&) = unsafeBinaryOp "?&"
1103(.?&) = unsafeBinaryOp "?&"
1064
1104
@@ -1081,9 +1121,9 @@ instance
1081-- count from the end). Throws an error if top level container is not an array.
1121-- count from the end). Throws an error if top level container is not an array.
1082(.-.)
1122(.-.)
1083 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1123 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1084− => Expression commons schemas params grp from (nullity 'PGjsonb)
1124+ => Expression grp commons schemas params from (nullity 'PGjsonb)
1085− -> Expression commons schemas params grp from (nullity key)
1125+ -> Expression grp commons schemas params from (nullity key)
1086− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1126+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1087infixl 6 .-.
1127infixl 6 .-.
1088(.-.) = unsafeBinaryOp "-"
1128(.-.) = unsafeBinaryOp "-"
1089
1129
@@ -1091,9 +1131,9 @@ infixl 6 .-.
1091-- integers count from the end)
1131-- integers count from the end)
1092(#-.)
1132(#-.)
1093 :: PGTextArray "(#-.)" arrayty
1133 :: PGTextArray "(#-.)" arrayty
1094− => Expression commons schemas params grp from (nullity 'PGjsonb)
1134+ => Expression grp commons schemas params from (nullity 'PGjsonb)
1095− -> Expression commons schemas params grp from (nullity arrayty)
1135+ -> Expression grp commons schemas params from (nullity arrayty)
1096− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1136+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1097infixl 6 #-.
1137infixl 6 #-.
1098(#-.) = unsafeBinaryOp "#-"
1138(#-.) = unsafeBinaryOp "#-"
1099
1139
@@ -1104,14 +1144,14 @@ Table 9.45: JSON creation functions
1104-- | Literal binary JSON
1144-- | Literal binary JSON
1105jsonbLit
1145jsonbLit
1106 :: JSON.ToJSON x
1146 :: JSON.ToJSON x
1107− => x -> Expression commons schemas params grp from (nullity 'PGjsonb)
1147+ => x -> Expression grp commons schemas params from (nullity 'PGjsonb)
1108jsonbLit = cast jsonb . UnsafeExpression
1148jsonbLit = cast jsonb . UnsafeExpression
1109 . singleQuotedUtf8 . toStrict . JSON.encode
1149 . singleQuotedUtf8 . toStrict . JSON.encode
1110
1150
1111-- | Literal JSON
1151-- | Literal JSON
1112jsonLit
1152jsonLit
1113 :: JSON.ToJSON x
1153 :: JSON.ToJSON x
1114− => x -> Expression commons schemas params grp from (nullity 'PGjson)
1154+ => x -> Expression grp commons schemas params from (nullity 'PGjson)
1115jsonLit = cast json . UnsafeExpression
1155jsonLit = cast json . UnsafeExpression
1116 . singleQuotedUtf8 . toStrict . JSON.encode
1156 . singleQuotedUtf8 . toStrict . JSON.encode
1117
1157
@@ -1122,8 +1162,8 @@ jsonLit = cast json . UnsafeExpression
1122-- number, a Boolean, or a null value, the text representation will be used, in
1162-- number, a Boolean, or a null value, the text representation will be used, in
1123-- such a fashion that it is a valid json value.
1163-- such a fashion that it is a valid json value.
1124toJson
1164toJson
1125− :: Expression commons schemas params grp from (nullity ty)
1165+ :: Expression grp commons schemas params from (nullity ty)
1126− -> Expression commons schemas params grp from (nullity 'PGjson)
1166+ -> Expression grp commons schemas params from (nullity 'PGjson)
1127toJson = unsafeFunction "to_json"
1167toJson = unsafeFunction "to_json"
1128
1168
1129-- | Returns the value as jsonb. Arrays and composites are converted
1169-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1133,43 +1173,43 @@ toJson = unsafeFunction "to_json"
1133-- number, a Boolean, or a null value, the text representation will be used, in
1173-- number, a Boolean, or a null value, the text representation will be used, in
1134-- such a fashion that it is a valid jsonb value.
1174-- such a fashion that it is a valid jsonb value.
1135toJsonb
1175toJsonb
1136− :: Expression commons schemas params grp from (nullity ty)
1176+ :: Expression grp commons schemas params from (nullity ty)
1137− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1177+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1138toJsonb = unsafeFunction "to_jsonb"
1178toJsonb = unsafeFunction "to_jsonb"
1139
1179
1140-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1180-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1141-- becomes a JSON array of arrays.
1181-- becomes a JSON array of arrays.
1142arrayToJson
1182arrayToJson
1143 :: PGArray "arrayToJson" arr
1183 :: PGArray "arrayToJson" arr
1144− => Expression commons schemas params grp from (nullity arr)
1184+ => Expression grp commons schemas params from (nullity arr)
1145− -> Expression commons schemas params grp from (nullity 'PGjson)
1185+ -> Expression grp commons schemas params from (nullity 'PGjson)
1146arrayToJson = unsafeFunction "array_to_json"
1186arrayToJson = unsafeFunction "array_to_json"
1147
1187
1148-- | Returns the row as a JSON object.
1188-- | Returns the row as a JSON object.
1149rowToJson
1189rowToJson
1150− :: Expression commons schemas params grp from (nullity ('PGcomposite ty))
1190+ :: Expression grp commons schemas params from (nullity ('PGcomposite ty))
1151− -> Expression commons schemas params grp from (nullity 'PGjson)
1191+ -> Expression grp commons schemas params from (nullity 'PGjson)
1152rowToJson = unsafeFunction "row_to_json"
1192rowToJson = unsafeFunction "row_to_json"
1153
1193
1154-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1194-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1155-- argument list.
1195-- argument list.
1156jsonBuildArray
1196jsonBuildArray
1157 :: SListI elems
1197 :: SListI elems
1158− => NP (Expression commons schemas params grp from) elems
1198+ => NP (Expression grp commons schemas params from) elems
1159− -> Expression commons schemas params grp from (nullity 'PGjson)
1199+ -> Expression grp commons schemas params from (nullity 'PGjson)
1160jsonBuildArray = unsafeVariadicFunction "json_build_array"
1200jsonBuildArray = unsafeVariadicFunction "json_build_array"
1161
1201
1162-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1202-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1163-- variadic argument list.
1203-- variadic argument list.
1164jsonbBuildArray
1204jsonbBuildArray
1165 :: SListI elems
1205 :: SListI elems
1166− => NP (Expression commons schemas params grp from) elems
1206+ => NP (Expression grp commons schemas params from) elems
1167− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1207+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1168jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1208jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1169
1209
1170unsafeRowFunction
1210unsafeRowFunction
1171 :: All Top elems
1211 :: All Top elems
1172− => NP (Aliased (Expression commons schemas params grp from)) elems
1212+ => NP (Aliased (Expression grp commons schemas params from)) elems
1173 -> [ByteString]
1213 -> [ByteString]
1174unsafeRowFunction =
1214unsafeRowFunction =
1175 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
1215 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1184,8 +1224,8 @@ unsafeRowFunction =
1184-- and values.
1224-- and values.
1185jsonBuildObject
1225jsonBuildObject
1186 :: All Top elems
1226 :: All Top elems
1187− => NP (Aliased (Expression commons schemas params grp from)) elems
1227+ => NP (Aliased (Expression grp commons schemas params from)) elems
1188− -> Expression commons schemas params grp from (nullity 'PGjson)
1228+ -> Expression grp commons schemas params from (nullity 'PGjson)
1189jsonBuildObject
1229jsonBuildObject
1190 = unsafeFunction "json_build_object"
1230 = unsafeFunction "json_build_object"
1191 . UnsafeExpression
1231 . UnsafeExpression
@@ -1197,8 +1237,8 @@ jsonBuildObject
1197-- between text and values.
1237-- between text and values.
1198jsonbBuildObject
1238jsonbBuildObject
1199 :: All Top elems
1239 :: All Top elems
1200− => NP (Aliased (Expression commons schemas params grp from)) elems
1240+ => NP (Aliased (Expression grp commons schemas params from)) elems
1201− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1241+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1202jsonbBuildObject
1242jsonbBuildObject
1203 = unsafeFunction "jsonb_build_object"
1243 = unsafeFunction "jsonb_build_object"
1204 . UnsafeExpression
1244 . UnsafeExpression
@@ -1211,8 +1251,8 @@ jsonbBuildObject
1211-- array has exactly two elements, which are taken as a key/value pair.
1251-- array has exactly two elements, which are taken as a key/value pair.
1212jsonObject
1252jsonObject
1213 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1253 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1214− => Expression commons schemas params grp from (nullity arr)
1254+ => Expression grp commons schemas params from (nullity arr)
1215− -> Expression commons schemas params grp from (nullity 'PGjson)
1255+ -> Expression grp commons schemas params from (nullity 'PGjson)
1216jsonObject = unsafeFunction "json_object"
1256jsonObject = unsafeFunction "json_object"
1217
1257
1218-- | Builds a binary JSON object out of a text array. The array must have either
1258-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1221,8 +1261,8 @@ jsonObject = unsafeFunction "json_object"
1221-- array has exactly two elements, which are taken as a key/value pair.
1261-- array has exactly two elements, which are taken as a key/value pair.
1222jsonbObject
1262jsonbObject
1223 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1263 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1224− => Expression commons schemas params grp from (nullity arr)
1264+ => Expression grp commons schemas params from (nullity arr)
1225− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1265+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1226jsonbObject = unsafeFunction "jsonb_object"
1266jsonbObject = unsafeFunction "jsonb_object"
1227
1267
1228-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1268-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1230,9 +1270,9 @@ jsonbObject = unsafeFunction "jsonb_object"
1230jsonZipObject
1270jsonZipObject
1231 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1271 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1232 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1272 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1233− => Expression commons schemas params grp from (nullity keysArray)
1273+ => Expression grp commons schemas params from (nullity keysArray)
1234− -> Expression commons schemas params grp from (nullity valuesArray)
1274+ -> Expression grp commons schemas params from (nullity valuesArray)
1235− -> Expression commons schemas params grp from (nullity 'PGjson)
1275+ -> Expression grp commons schemas params from (nullity 'PGjson)
1236jsonZipObject ks vs =
1276jsonZipObject ks vs =
1237 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1277 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1238
1278
@@ -1242,9 +1282,9 @@ jsonZipObject ks vs =
1242jsonbZipObject
1282jsonbZipObject
1243 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1283 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1244 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1284 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1245− => Expression commons schemas params grp from (nullity keysArray)
1285+ => Expression grp commons schemas params from (nullity keysArray)
1246− -> Expression commons schemas params grp from (nullity valuesArray)
1286+ -> Expression grp commons schemas params from (nullity valuesArray)
1247− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1287+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1248jsonbZipObject ks vs =
1288jsonbZipObject ks vs =
1249 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1289 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1250
1290
@@ -1254,23 +1294,23 @@ Table 9.46: JSON processing functions
1254
1294
1255-- | Returns the number of elements in the outermost JSON array.
1295-- | Returns the number of elements in the outermost JSON array.
1256jsonArrayLength
1296jsonArrayLength
1257− :: Expression commons schemas params grp from (nullity 'PGjson)
1297+ :: Expression grp commons schemas params from (nullity 'PGjson)
1258− -> Expression commons schemas params grp from (nullity 'PGint4)
1298+ -> Expression grp commons schemas params from (nullity 'PGint4)
1259jsonArrayLength = unsafeFunction "json_array_length"
1299jsonArrayLength = unsafeFunction "json_array_length"
1260
1300
1261-- | Returns the number of elements in the outermost binary JSON array.
1301-- | Returns the number of elements in the outermost binary JSON array.
1262jsonbArrayLength
1302jsonbArrayLength
1263− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1303+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1264− -> Expression commons schemas params grp from (nullity 'PGint4)
1304+ -> Expression grp commons schemas params from (nullity 'PGint4)
1265jsonbArrayLength = unsafeFunction "jsonb_array_length"
1305jsonbArrayLength = unsafeFunction "jsonb_array_length"
1266
1306
1267-- | Returns JSON value pointed to by the given path (equivalent to #>
1307-- | Returns JSON value pointed to by the given path (equivalent to #>
1268-- operator).
1308-- operator).
1269jsonExtractPath
1309jsonExtractPath
1270 :: SListI elems
1310 :: SListI elems
1271− => Expression commons schemas params grp from (nullity 'PGjson)
1311+ => Expression grp commons schemas params from (nullity 'PGjson)
1272− -> NP (Expression commons schemas params grp from) elems
1312+ -> NP (Expression grp commons schemas params from) elems
1273− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1313+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1274jsonExtractPath x xs =
1314jsonExtractPath x xs =
1275 unsafeVariadicFunction "json_extract_path" (x :* xs)
1315 unsafeVariadicFunction "json_extract_path" (x :* xs)
1276
1316
@@ -1278,9 +1318,9 @@ jsonExtractPath x xs =
1278-- operator).
1318-- operator).
1279jsonbExtractPath
1319jsonbExtractPath
1280 :: SListI elems
1320 :: SListI elems
1281− => Expression commons schemas params grp from (nullity 'PGjsonb)
1321+ => Expression grp commons schemas params from (nullity 'PGjsonb)
1282− -> NP (Expression commons schemas params grp from) elems
1322+ -> NP (Expression grp commons schemas params from) elems
1283− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1323+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1284jsonbExtractPath x xs =
1324jsonbExtractPath x xs =
1285 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1325 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1286
1326
@@ -1288,9 +1328,9 @@ jsonbExtractPath x xs =
1288-- operator), as text.
1328-- operator), as text.
1289jsonExtractPathAsText
1329jsonExtractPathAsText
1290 :: SListI elems
1330 :: SListI elems
1291− => Expression commons schemas params grp from (nullity 'PGjson)
1331+ => Expression grp commons schemas params from (nullity 'PGjson)
1292− -> NP (Expression commons schemas params grp from) elems
1332+ -> NP (Expression grp commons schemas params from) elems
1293− -> Expression commons schemas params grp from (nullity 'PGjson)
1333+ -> Expression grp commons schemas params from (nullity 'PGjson)
1294jsonExtractPathAsText x xs =
1334jsonExtractPathAsText x xs =
1295 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1335 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1296
1336
@@ -1298,38 +1338,38 @@ jsonExtractPathAsText x xs =
1298-- operator), as text.
1338-- operator), as text.
1299jsonbExtractPathAsText
1339jsonbExtractPathAsText
1300 :: SListI elems
1340 :: SListI elems
1301− => Expression commons schemas params grp from (nullity 'PGjsonb)
1341+ => Expression grp commons schemas params from (nullity 'PGjsonb)
1302− -> NP (Expression commons schemas params grp from) elems
1342+ -> NP (Expression grp commons schemas params from) elems
1303− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1343+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1304jsonbExtractPathAsText x xs =
1344jsonbExtractPathAsText x xs =
1305 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1345 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1306
1346
1307-- | Returns the type of the outermost JSON value as a text string. Possible
1347-- | Returns the type of the outermost JSON value as a text string. Possible
1308-- types are object, array, string, number, boolean, and null.
1348-- types are object, array, string, number, boolean, and null.
1309jsonTypeof
1349jsonTypeof
1310− :: Expression commons schemas params grp from (nullity 'PGjson)
1350+ :: Expression grp commons schemas params from (nullity 'PGjson)
1311− -> Expression commons schemas params grp from (nullity 'PGtext)
1351+ -> Expression grp commons schemas params from (nullity 'PGtext)
1312jsonTypeof = unsafeFunction "json_typeof"
1352jsonTypeof = unsafeFunction "json_typeof"
1313
1353
1314-- | Returns the type of the outermost binary JSON value as a text string.
1354-- | Returns the type of the outermost binary JSON value as a text string.
1315-- Possible types are object, array, string, number, boolean, and null.
1355-- Possible types are object, array, string, number, boolean, and null.
1316jsonbTypeof
1356jsonbTypeof
1317− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1357+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1318− -> Expression commons schemas params grp from (nullity 'PGtext)
1358+ -> Expression grp commons schemas params from (nullity 'PGtext)
1319jsonbTypeof = unsafeFunction "jsonb_typeof"
1359jsonbTypeof = unsafeFunction "jsonb_typeof"
1320
1360
1321-- | Returns its argument with all object fields that have null values omitted.
1361-- | Returns its argument with all object fields that have null values omitted.
1322-- Other null values are untouched.
1362-- Other null values are untouched.
1323jsonStripNulls
1363jsonStripNulls
1324− :: Expression commons schemas params grp from (nullity 'PGjson)
1364+ :: Expression grp commons schemas params from (nullity 'PGjson)
1325− -> Expression commons schemas params grp from (nullity 'PGjson)
1365+ -> Expression grp commons schemas params from (nullity 'PGjson)
1326jsonStripNulls = unsafeFunction "json_strip_nulls"
1366jsonStripNulls = unsafeFunction "json_strip_nulls"
1327
1367
1328-- | Returns its argument with all object fields that have null values omitted.
1368-- | Returns its argument with all object fields that have null values omitted.
1329-- Other null values are untouched.
1369-- Other null values are untouched.
1330jsonbStripNulls
1370jsonbStripNulls
1331− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1371+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1332− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1372+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1333jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1373jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1334
1374
1335-- | @ jsonbSet target path new_value create_missing @
1375-- | @ jsonbSet target path new_value create_missing @
@@ -1341,11 +1381,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1341-- arrays.
1381-- arrays.
1342jsonbSet
1382jsonbSet
1343 :: PGTextArray "jsonbSet" arr
1383 :: PGTextArray "jsonbSet" arr
1344− => Expression commons schemas params grp from (nullity 'PGjsonb)
1384+ => Expression grp commons schemas params from (nullity 'PGjsonb)
1345− -> Expression commons schemas params grp from (nullity arr)
1385+ -> Expression grp commons schemas params from (nullity arr)
1346− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1386+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1347− -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1387+ -> Maybe (Expression grp commons schemas params from (nullity 'PGbool))
1348− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1388+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1349jsonbSet tgt path val createMissing = case createMissing of
1389jsonbSet tgt path val createMissing = case createMissing of
1350 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1390 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1351 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
1391 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1360,267 +1400,411 @@ jsonbSet tgt path val createMissing = case createMissing of
1360-- in path count from the end of JSON arrays.
1400-- in path count from the end of JSON arrays.
1361jsonbInsert
1401jsonbInsert
1362 :: PGTextArray "jsonbInsert" arr
1402 :: PGTextArray "jsonbInsert" arr
1363− => Expression commons schemas params grp from (nullity 'PGjsonb)
1403+ => Expression grp commons schemas params from (nullity 'PGjsonb)
1364− -> Expression commons schemas params grp from (nullity arr)
1404+ -> Expression grp commons schemas params from (nullity arr)
1365− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1405+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1366− -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1406+ -> Maybe (Expression grp commons schemas params from (nullity 'PGbool))
1367− -> Expression commons schemas params grp from (nullity 'PGjsonb)
1407+ -> Expression grp commons schemas params from (nullity 'PGjsonb)
1368jsonbInsert tgt path val insertAfter = case insertAfter of
1408jsonbInsert tgt path val insertAfter = case insertAfter of
1369 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1409 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1370 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1410 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1371
1411
1372-- | Returns its argument as indented JSON text.
1412-- | Returns its argument as indented JSON text.
1373jsonbPretty
1413jsonbPretty
1374− :: Expression commons schemas params grp from (nullity 'PGjsonb)
1414+ :: Expression grp commons schemas params from (nullity 'PGjsonb)
1375− -> Expression commons schemas params grp from (nullity 'PGtext)
1415+ -> Expression grp commons schemas params from (nullity 'PGtext)
1376jsonbPretty = unsafeFunction "jsonb_pretty"
1416jsonbPretty = unsafeFunction "jsonb_pretty"
1377
1417
1378{-----------------------------------------
1418{-----------------------------------------
1379aggregation
1419aggregation
1380-----------------------------------------}
1420-----------------------------------------}
1381
1421
1422+class Aggregate expr1 expr2 aggr
1423+ | aggr -> expr1, aggr -> expr2 where
1424+
1425+ -- | A special aggregation that does not require an input
1426+ --
1427+ -- >>> :{
1428+ -- let
1429+ -- expression :: Expression (Grouped bys) commons schemas params from ('NotNull 'PGint8)
1430+ -- expression = countStar
1431+ -- in printSQL expression
1432+ -- :}
1433+ -- count(*)
1434+ countStar :: aggr ('NotNull 'PGint8)
1435+
1436+ -- | >>> :{
1437+ -- let
1438+ -- expression :: Expression (Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1439+ -- expression = count (All #col)
1440+ -- in printSQL expression
1441+ -- :}
1442+ -- count(ALL "col")
1443+ count
1444+ :: expr1 ty
1445+ -- ^ what to count
1446+ -> aggr ('NotNull 'PGint8)
1447+
1448+ -- | >>> :{
1449+ -- let
1450+ -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1451+ -- expression = sum_ (Distinct #col)
1452+ -- in printSQL expression
1453+ -- :}
1454+ -- sum(DISTINCT "col")
1455+ sum_
1456+ :: ty `In` PGNum
1457+ => expr1 (nullity ty)
1458+ -> aggr (nullity ty)
1459+
1460+ -- | >>> :{
1461+ -- let
1462+ -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1463+ -- expression = bitAnd (Distinct #col)
1464+ -- in printSQL expression
1465+ -- :}
1466+ -- bit_and(DISTINCT "col")
1467+ bitAnd
1468+ :: int `In` PGIntegral
1469+ => expr1 (nullity int)
1470+ -- ^ what to aggregate
1471+ -> aggr (nullity int)
1472+
1473+ -- | >>> :{
1474+ -- let
1475+ -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1476+ -- expression = bitOr (All #col)
1477+ -- in printSQL expression
1478+ -- :}
1479+ -- bit_or(ALL "col")
1480+ bitOr
1481+ :: int `In` PGIntegral
1482+ => expr1 (nullity int)
1483+ -- ^ what to aggregate
1484+ -> aggr (nullity int)
1485+
1486+ -- | >>> :{
1487+ -- let
1488+ -- winFun :: WindowFunction 'Ungrouped commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1489+ -- winFun = boolAnd #col
1490+ -- in printSQL winFun
1491+ -- :}
1492+ -- bool_and("col")
1493+ boolAnd
1494+ :: expr1 (nullity 'PGbool)
1495+ -- ^ what to aggregate
1496+ -> aggr (nullity 'PGbool)
1497+
1498+ -- | >>> :{
1499+ -- let
1500+ -- expression :: Expression (Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1501+ -- expression = boolOr (All #col)
1502+ -- in printSQL expression
1503+ -- :}
1504+ -- bool_or(ALL "col")
1505+ boolOr
1506+ :: expr1(nullity 'PGbool)
1507+ -- ^ what to aggregate
1508+ -> aggr (nullity 'PGbool)
1509+
1510+ -- | synonym for `boolAnd`
1511+ --
1512+ -- >>> :{
1513+ -- let
1514+ -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1515+ -- expression = every (Distinct #col)
1516+ -- in printSQL expression
1517+ -- :}
1518+ -- every(DISTINCT "col")
1519+ every
1520+ :: expr1 (nullity 'PGbool)
1521+ -- ^ what to aggregate
1522+ -> aggr (nullity 'PGbool)
1523+
1524+ -- | maximum value of expression across all input values
1525+ max_
1526+ :: expr1 (nullity ty)
1527+ -- ^ what to maximize
1528+ -> aggr (nullity ty)
1529+
1530+ -- | minimum value of expression across all input values
1531+ min_
1532+ :: expr1 (nullity ty)
1533+ -- ^ what to minimize
1534+ -> aggr (nullity ty)
1535+
1536+ -- | average aggregation
1537+ avg
1538+ :: expr1 (nullity ty)
1539+ -- ^ what to average
1540+ -> aggr (nullity (PGAvg ty))
1541+
1542+ {- | correlation coefficient
1543+ >>> :{
1544+ let
1545+ expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1546+ expression = corr (All (#y :*: #x))
1547+ in printSQL expression
1548+ :}
1549+ corr(ALL "y", "x")
1550+ -}
1551+ corr
1552+ :: expr2 (nullity 'PGfloat8)
1553+ -> aggr (nullity 'PGfloat8)
1554+
1555+ {- | population covariance
1556+ >>> :{
1557+ let
1558+ expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1559+ expression = covarPop (All (#y :*: #x))
1560+ in printSQL expression
1561+ :}
1562+ covar_pop(ALL "y", "x")
1563+ -}
1564+ covarPop
1565+ :: expr2 (nullity 'PGfloat8)
1566+ -> aggr (nullity 'PGfloat8)
1567+
1568+ {- | sample covariance
1569+ >>> :{
1570+ let
1571+ winFun :: WindowFunction 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1572+ winFun = covarSamp (#y :*: #x)
1573+ in printSQL winFun
1574+ :}
1575+ covar_samp("y", "x")
1576+ -}
1577+ covarSamp
1578+ :: expr2 (nullity 'PGfloat8)
1579+ -> aggr (nullity 'PGfloat8)
1580+
1581+ {- | average of the independent variable (sum(X)/N)
1582+ >>> :{
1583+ let
1584+ expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1585+ expression = regrAvgX (All (#y :*: #x))
1586+ in printSQL expression
1587+ :}
1588+ regr_avgx(ALL "y", "x")
1589+ -}
1590+ regrAvgX
1591+ :: expr2 (nullity 'PGfloat8)
1592+ -> aggr (nullity 'PGfloat8)
1593+
1594+ {- | average of the dependent variable (sum(Y)/N)
1595+ >>> :{
1596+ let
1597+ winFun :: WindowFunction 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1598+ winFun = regrAvgY (#y :*: #x)
1599+ in printSQL winFun
1600+ :}
1601+ regr_avgy("y", "x")
1602+ -}
1603+ regrAvgY
1604+ :: expr2 (nullity 'PGfloat8)
1605+ -> aggr (nullity 'PGfloat8)
1606+
1607+ {- | number of input rows in which both expressions are nonnull
1608+ >>> :{
1609+ let
1610+ winFun :: WindowFunction 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGint8)
1611+ winFun = regrCount (#y :*: #x)
1612+ in printSQL winFun
1613+ :}
1614+ regr_count("y", "x")
1615+ -}
1616+ regrCount
1617+ :: expr2 (nullity 'PGfloat8)
1618+ -> aggr (nullity 'PGint8)
1619+
1620+ {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
1621+ >>> :{
1622+ let
1623+ expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1624+ expression = regrIntercept (All (#y :*: #x))
1625+ in printSQL expression
1626+ :}
1627+ regr_intercept(ALL "y", "x")
1628+ -}
1629+ regrIntercept
1630+ :: expr2 (nullity 'PGfloat8)
1631+ -> aggr (nullity 'PGfloat8)
1632+
1633+ -- | @regr_r2(Y, X)@, square of the correlation coefficient
1634+ regrR2
1635+ :: expr2 (nullity 'PGfloat8)
1636+ -> aggr (nullity 'PGfloat8)
1637+
1638+ -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
1639+ -- determined by the (X, Y) pairs
1640+ regrSlope
1641+ :: expr2 (nullity 'PGfloat8)
1642+ -> aggr (nullity 'PGfloat8)
1643+
1644+ -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
1645+ -- (“sum of squares” of the independent variable)
1646+ regrSxx
1647+ :: expr2 (nullity 'PGfloat8)
1648+ -> aggr (nullity 'PGfloat8)
1649+
1650+ -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
1651+ -- (“sum of products” of independent times dependent variable)
1652+ regrSxy
1653+ :: expr2 (nullity 'PGfloat8)
1654+ -> aggr (nullity 'PGfloat8)
1655+
1656+ -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
1657+ -- (“sum of squares” of the dependent variable)
1658+ regrSyy
1659+ :: expr2 (nullity 'PGfloat8)
1660+ -> aggr (nullity 'PGfloat8)
1661+
1662+ -- | historical alias for `stddevSamp`
1663+ stddev
1664+ :: expr1 (nullity ty)
1665+ -> aggr (nullity (PGAvg ty))
1666+
1667+ -- | population standard deviation of the input values
1668+ stddevPop
1669+ :: expr1 (nullity ty)
1670+ -> aggr (nullity (PGAvg ty))
1671+
1672+ -- | sample standard deviation of the input values
1673+ stddevSamp
1674+ :: expr1 (nullity ty)
1675+ -> aggr (nullity (PGAvg ty))
1676+
1677+ -- | historical alias for `varSamp`
1678+ variance
1679+ :: expr1 (nullity ty)
1680+ -> aggr (nullity (PGAvg ty))
1681+
1682+ -- | population variance of the input values
1683+ -- (square of the population standard deviation)
1684+ varPop
1685+ :: expr1 (nullity ty)
1686+ -> aggr (nullity (PGAvg ty))
1687+
1688+ -- | sample variance of the input values
1689+ -- (square of the sample standard deviation)
1690+ varSamp
1691+ :: expr1 (nullity ty)
1692+ -> aggr (nullity (PGAvg ty))
1693+
1694+data Distinction expr ty
1695+ = All (expr ty)
1696+ | Distinct (expr ty)
1697+ deriving (GHC.Generic,Show,Eq,Ord)
1698+instance NFData (Distinction (Expression grp commons schemas params from) ty)
1699+instance RenderSQL (Distinction (Expression grp commons schemas params from) ty) where
1700+ renderSQL = \case
1701+ All x -> "ALL" <+> renderSQL x
1702+ Distinct x -> "DISTINCT" <+> renderSQL x
1703+instance RenderSQL
1704+ (Distinction
1705+ ( Expression grp commons schemas params from
1706+ :*:
1707+ Expression grp commons schemas params from) xty ) where
1708+ renderSQL = \case
1709+ All (x :*: x') ->
1710+ "ALL" <+> renderSQL x <> ", " <> renderSQL x'
1711+ Distinct (x :*: x') ->
1712+ "DISTINCT" <+> renderSQL x <> ", " <> renderSQL x'
1713+
1714+instance Aggregate
1715+ (Distinction (Expression 'Ungrouped commons schemas params from))
1716+ (Distinction (Expression 'Ungrouped commons schemas params from :*: Expression 'Ungrouped commons schemas params from))
1717+ (Expression ('Grouped bys) commons schemas params from) where
1718+ countStar = UnsafeExpression "count(*)"
1719+ count = unsafeAggregate1 "count"
1720+ sum_ = unsafeAggregate1 "sum"
1721+ bitAnd = unsafeAggregate1 "bit_and"
1722+ bitOr = unsafeAggregate1 "bit_or"
1723+ boolAnd = unsafeAggregate1 "bool_and"
1724+ boolOr = unsafeAggregate1 "bool_or"
1725+ every = unsafeAggregate1 "every"
1726+ max_ = unsafeAggregate1 "max"
1727+ min_ = unsafeAggregate1 "min"
1728+ avg = unsafeAggregate1 "avg"
1729+ corr = unsafeAggregate2 "corr"
1730+ covarPop = unsafeAggregate2 "covar_pop"
1731+ covarSamp = unsafeAggregate2 "covar_samp"
1732+ regrAvgX = unsafeAggregate2 "regr_avgx"
1733+ regrAvgY = unsafeAggregate2 "regr_avgy"
1734+ regrCount = unsafeAggregate2 "regr_count"
1735+ regrIntercept = unsafeAggregate2 "regr_intercept"
1736+ regrR2 = unsafeAggregate2 "regr_r2"
1737+ regrSlope = unsafeAggregate2 "regr_slope"
1738+ regrSxx = unsafeAggregate2 "regr_sxx"
1739+ regrSxy = unsafeAggregate2 "regr_sxy"
1740+ regrSyy = unsafeAggregate2 "regr_syy"
1741+ stddev = unsafeAggregate1 "stddev"
1742+ stddevPop = unsafeAggregate1 "stddev_pop"
1743+ stddevSamp = unsafeAggregate1 "stddev_samp"
1744+ variance = unsafeAggregate1 "variance"
1745+ varPop = unsafeAggregate1 "var_pop"
1746+ varSamp = unsafeAggregate1 "var_samp"
1747+instance Aggregate
1748+ (Expression grp commons schemas params from)
1749+ (Expression grp commons schemas params from :*: Expression grp commons schemas params from)
1750+ (WindowFunction grp commons schemas params from) where
1751+ countStar = UnsafeWindowFunction "count(*)"
1752+ count = unsafeWindowFunction1 "count"
1753+ sum_ = unsafeWindowFunction1 "sum"
1754+ bitAnd = unsafeWindowFunction1 "bit_and"
1755+ bitOr = unsafeWindowFunction1 "bit_or"
1756+ boolAnd = unsafeWindowFunction1 "bool_and"
1757+ boolOr = unsafeWindowFunction1 "bool_or"
1758+ every = unsafeWindowFunction1 "every"
1759+ max_ = unsafeWindowFunction1 "max"
1760+ min_ = unsafeWindowFunction1 "min"
1761+ avg = unsafeWindowFunction1 "avg"
1762+ corr = unsafeWindowFunction2 "corr"
1763+ covarPop = unsafeWindowFunction2 "covar_pop"
1764+ covarSamp = unsafeWindowFunction2 "covar_samp"
1765+ regrAvgX = unsafeWindowFunction2 "regr_avgx"
1766+ regrAvgY = unsafeWindowFunction2 "regr_avgy"
1767+ regrCount = unsafeWindowFunction2 "regr_count"
1768+ regrIntercept = unsafeWindowFunction2 "regr_intercept"
1769+ regrR2 = unsafeWindowFunction2 "regr_r2"
1770+ regrSlope = unsafeWindowFunction2 "regr_slope"
1771+ regrSxx = unsafeWindowFunction2 "regr_sxx"
1772+ regrSxy = unsafeWindowFunction2 "regr_sxy"
1773+ regrSyy = unsafeWindowFunction2 "regr_syy"
1774+ stddev = unsafeWindowFunction1 "stddev"
1775+ stddevPop = unsafeWindowFunction1 "stddev_pop"
1776+ stddevSamp = unsafeWindowFunction1 "stddev_samp"
1777+ variance = unsafeWindowFunction1 "variance"
1778+ varPop = unsafeWindowFunction1 "var_pop"
1779+ varSamp = unsafeWindowFunction1 "var_samp"
1780+
1382-- | escape hatch to define aggregate functions
1781-- | escape hatch to define aggregate functions
1383−unsafeAggregate
1782+unsafeAggregate1
1384 :: ByteString -- ^ aggregate function
1783 :: ByteString -- ^ aggregate function
1385− -> Expression commons schemas from 'Ungrouped params (xty)
1784+ -> Distinction (Expression 'Ungrouped commons schemas params from) xty
1386− -> Expression commons schemas from ('Grouped bys) params (yty)
1785+ -> Expression ('Grouped bys) commons schemas params from yty
1387−unsafeAggregate fun x = UnsafeExpression $ mconcat
1786+unsafeAggregate1 fun x = UnsafeExpression $ mconcat
1388 [fun, "(", renderSQL x, ")"]
1787 [fun, "(", renderSQL x, ")"]
1389
1788
1390−-- | escape hatch to define aggregate functions over distinct values
1789+-- | escape hatch to define aggregate binary functions
1391−unsafeAggregateDistinct
1790+unsafeAggregate2
1392 :: ByteString -- ^ aggregate function
1791 :: ByteString -- ^ aggregate function
1393− -> Expression commons schemas from 'Ungrouped params (xty)
1792+ -> Distinction (Expression 'Ungrouped commons schemas params from :*: Expression 'Ungrouped commons schemas params from) xty
1394− -> Expression commons schemas from ('Grouped bys) params (yty)
1793+ -> Expression ('Grouped bys) commons schemas params from yty
1395−unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1794+unsafeAggregate2 fun xx = UnsafeExpression $ mconcat
1396− [fun, "(DISTINCT ", renderSQL x, ")"]
1795+ [fun, "(", renderSQL xx, ")"]
1397−
1796+
1398−-- | >>> :{
1797+-- | A type family that calculates `PGAvg` type of a `PGType`.
1399−-- let
1798+type family PGAvg ty where
1400−-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1401−-- expression = sum_ #col
1402−-- in printSQL expression
1403−-- :}
1404−-- sum("col")
1405−sum_
1406− :: ty `In` PGNum
1407− => Expression commons schemas from 'Ungrouped params (nullity ty)
1408− -- ^ what to sum
1409− -> Expression commons schemas from ('Grouped bys) params (nullity ty)
1410−sum_ = unsafeAggregate "sum"
1411−
1412−-- | >>> :{
1413−-- let
1414−-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
1415−-- expression = sumDistinct #col
1416−-- in printSQL expression
1417−-- :}
1418−-- sum(DISTINCT "col")
1419−sumDistinct
1420− :: ty `In` PGNum
1421− => Expression commons schemas from 'Ungrouped params (nullity ty)
1422− -- ^ what to sum
1423− -> Expression commons schemas from ('Grouped bys) params (nullity ty)
1424−sumDistinct = unsafeAggregateDistinct "sum"
1425−
1426−-- | A constraint for `PGType`s that you can take averages of and the resulting
1427−-- `PGType`.
1428−class PGAvg ty avg | ty -> avg where
1429− avg, avgDistinct
1430− :: Expression commons schemas from 'Ungrouped params (nullity ty)
1431− -- ^ what to average
1432− -> Expression commons schemas from ('Grouped bys) params (nullity avg)
1433− avg = unsafeAggregate "avg"
1434− avgDistinct = unsafeAggregateDistinct "avg"
1435−instance PGAvg 'PGint2 'PGnumeric
1799+ PGAvg 'PGint2 = 'PGnumeric
1436−instance PGAvg 'PGint4 'PGnumeric
1800+ PGAvg 'PGint4 = 'PGnumeric
1437−instance PGAvg 'PGint8 'PGnumeric
1801+ PGAvg 'PGint8 = 'PGnumeric
1438−instance PGAvg 'PGnumeric 'PGnumeric
1802+ PGAvg 'PGnumeric = 'PGnumeric
1439−instance PGAvg 'PGfloat4 'PGfloat8
1803+ PGAvg 'PGfloat4 = 'PGfloat8
1440−instance PGAvg 'PGfloat8 'PGfloat8
1804+ PGAvg 'PGfloat8 = 'PGfloat8
1441−instance PGAvg 'PGinterval 'PGinterval
1805+ PGAvg 'PGinterval = 'PGinterval
1442−
1806+ PGAvg pg = TypeError
1443−-- | >>> :{
1807+ ('Text "Squeal type error: No average for " ':<>: 'ShowType pg)
1444−-- let
1445−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1446−-- expression = bitAnd #col
1447−-- in printSQL expression
1448−-- :}
1449−-- bit_and("col")
1450−bitAnd
1451− :: int `In` PGIntegral
1452− => Expression commons schemas from 'Ungrouped params (nullity int)
1453− -- ^ what to aggregate
1454− -> Expression commons schemas from ('Grouped bys) params (nullity int)
1455−bitAnd = unsafeAggregate "bit_and"
1456−
1457−-- | >>> :{
1458−-- let
1459−-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1460−-- expression = bitOr #col
1461−-- in printSQL expression
1462−-- :}
1463−-- bit_or("col")
1464−bitOr
1465− :: int `In` PGIntegral
1466− => Expression commons schemas from 'Ungrouped params (nullity int)
1467− -- ^ what to aggregate
1468− -> Expression commons schemas from ('Grouped bys) params (nullity int)
1469−bitOr = unsafeAggregate "bit_or"
1470−
1471−-- | >>> :{
1472−-- let
1473−-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1474−-- expression = bitAndDistinct #col
1475−-- in printSQL expression
1476−-- :}
1477−-- bit_and(DISTINCT "col")
1478−bitAndDistinct
1479− :: int `In` PGIntegral
1480− => Expression commons schemas from 'Ungrouped params (nullity int)
1481− -- ^ what to aggregate
1482− -> Expression commons schemas from ('Grouped bys) params (nullity int)
1483−bitAndDistinct = unsafeAggregateDistinct "bit_and"
1484−
1485−-- | >>> :{
1486−-- let
1487−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1488−-- expression = bitOrDistinct #col
1489−-- in printSQL expression
1490−-- :}
1491−-- bit_or(DISTINCT "col")
1492−bitOrDistinct
1493− :: int `In` PGIntegral
1494− => Expression commons schemas from 'Ungrouped params (nullity int)
1495− -- ^ what to aggregate
1496− -> Expression commons schemas from ('Grouped bys) params (nullity int)
1497−bitOrDistinct = unsafeAggregateDistinct "bit_or"
1498−
1499−-- | >>> :{
1500−-- let
1501−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1502−-- expression = boolAnd #col
1503−-- in printSQL expression
1504−-- :}
1505−-- bool_and("col")
1506−boolAnd
1507− :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1508− -- ^ what to aggregate
1509− -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1510−boolAnd = unsafeAggregate "bool_and"
1511−
1512−-- | >>> :{
1513−-- let
1514−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1515−-- expression = boolOr #col
1516−-- in printSQL expression
1517−-- :}
1518−-- bool_or("col")
1519−boolOr
1520− :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1521− -- ^ what to aggregate
1522− -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1523−boolOr = unsafeAggregate "bool_or"
1524−
1525−-- | >>> :{
1526−-- let
1527−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1528−-- expression = boolAndDistinct #col
1529−-- in printSQL expression
1530−-- :}
1531−-- bool_and(DISTINCT "col")
1532−boolAndDistinct
1533− :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1534− -- ^ what to aggregate
1535− -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1536−boolAndDistinct = unsafeAggregateDistinct "bool_and"
1537−
1538−-- | >>> :{
1539−-- let
1540−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1541−-- expression = boolOrDistinct #col
1542−-- in printSQL expression
1543−-- :}
1544−-- bool_or(DISTINCT "col")
1545−boolOrDistinct
1546− :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1547− -- ^ what to aggregate
1548− -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1549−boolOrDistinct = unsafeAggregateDistinct "bool_or"
1550−
1551−-- | A special aggregation that does not require an input
1552−--
1553−-- >>> printSQL countStar
1554−-- count(*)
1555−countStar
1556− :: Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
1557−countStar = UnsafeExpression $ "count(*)"
1558−
1559−-- | >>> :{
1560−-- let
1561−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1562−-- expression = count #col
1563−-- in printSQL expression
1564−-- :}
1565−-- count("col")
1566−count
1567− :: Expression commons schemas from 'Ungrouped params ty
1568− -- ^ what to count
1569− -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
1570−count = unsafeAggregate "count"
1571−
1572−-- | >>> :{
1573−-- let
1574−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1575−-- expression = countDistinct #col
1576−-- in printSQL expression
1577−-- :}
1578−-- count(DISTINCT "col")
1579−countDistinct
1580− :: Expression commons schemas from 'Ungrouped params ty
1581− -- ^ what to count
1582− -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
1583−countDistinct = unsafeAggregateDistinct "count"
1584−
1585−-- | synonym for `boolAnd`
1586−--
1587−-- >>> :{
1588−-- let
1589−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1590−-- expression = every #col
1591−-- in printSQL expression
1592−-- :}
1593−-- every("col")
1594−every
1595− :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1596− -- ^ what to aggregate
1597− -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1598−every = unsafeAggregate "every"
1599−
1600−-- | synonym for `boolAndDistinct`
1601−--
1602−-- >>> :{
1603−-- let
1604−-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1605−-- expression = everyDistinct #col
1606−-- in printSQL expression
1607−-- :}
1608−-- every(DISTINCT "col")
1609−everyDistinct
1610− :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1611− -- ^ what to aggregate
1612− -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1613−everyDistinct = unsafeAggregateDistinct "every"
1614−
1615−-- | minimum and maximum aggregation
1616−max_, min_, maxDistinct, minDistinct
1617− :: Expression commons schemas from 'Ungrouped params (nullity ty)
1618− -- ^ what to aggregate
1619− -> Expression commons schemas from ('Grouped bys) params (nullity ty)
1620−max_ = unsafeAggregate "max"
1621−min_ = unsafeAggregate "min"
1622−maxDistinct = unsafeAggregateDistinct "max"
1623−minDistinct = unsafeAggregateDistinct "min"
1624
1808
1625{-----------------------------------------
1809{-----------------------------------------
1626type expressions
1810type expressions
@@ -1789,3 +1973,219 @@ instance PGTyped schemas ty
1789instance (All KnownNat dims, PGTyped schemas ty)
1973instance (All KnownNat dims, PGTyped schemas ty)
1790 => PGTyped schemas (nullity ('PGfixarray dims ty)) where
1974 => PGTyped schemas (nullity ('PGfixarray dims ty)) where
1791 pgtype = fixarray @dims (pgtype @schemas @ty)
1975 pgtype = fixarray @dims (pgtype @schemas @ty)
1976+
1977+{-----------------------------------------
1978+Sorting
1979+-----------------------------------------}
1980+
1981+-- | `SortExpression`s are used by `sortBy` to optionally sort the results
1982+-- of a `Query`. `Asc` or `Desc` set the sort direction of a `NotNull` result
1983+-- column to ascending or descending. Ascending order puts smaller values
1984+-- first, where "smaller" is defined in terms of the `.<` operator. Similarly,
1985+-- descending order is determined with the `.>` operator. `AscNullsFirst`,
1986+-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
1987+-- determine whether nulls appear before or after non-null values in the sort
1988+-- ordering of a `Null` result column.
1989+data SortExpression grp commons schemas params from where
1990+ Asc
1991+ :: Expression grp commons schemas params from ('NotNull ty)
1992+ -> SortExpression grp commons schemas params from
1993+ Desc
1994+ :: Expression grp commons schemas params from ('NotNull ty)
1995+ -> SortExpression grp commons schemas params from
1996+ AscNullsFirst
1997+ :: Expression grp commons schemas params from ('Null ty)
1998+ -> SortExpression grp commons schemas params from
1999+ AscNullsLast
2000+ :: Expression grp commons schemas params from ('Null ty)
2001+ -> SortExpression grp commons schemas params from
2002+ DescNullsFirst
2003+ :: Expression grp commons schemas params from ('Null ty)
2004+ -> SortExpression grp commons schemas params from
2005+ DescNullsLast
2006+ :: Expression grp commons schemas params from ('Null ty)
2007+ -> SortExpression grp commons schemas params from
2008+deriving instance Show (SortExpression grp commons schemas params from)
2009+
2010+class OrderBy expr where
2011+ orderBy
2012+ :: [SortExpression grp commons schemas params from]
2013+ -> expr grp commons schemas params from
2014+ -> expr grp commons schemas params from
2015+
2016+-- | Render a `SortExpression`.
2017+instance RenderSQL (SortExpression grp commons schemas params from) where
2018+ renderSQL = \case
2019+ Asc expression -> renderSQL expression <+> "ASC"
2020+ Desc expression -> renderSQL expression <+> "DESC"
2021+ AscNullsFirst expression -> renderSQL expression
2022+ <+> "ASC NULLS FIRST"
2023+ DescNullsFirst expression -> renderSQL expression
2024+ <+> "DESC NULLS FIRST"
2025+ AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
2026+ DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
2027+
2028+data WindowDefinition grp commons schemas params from where
2029+ WindowDefinition
2030+ :: SListI bys
2031+ => NP (Expression grp commons schemas params from) bys
2032+ -> [SortExpression grp commons schemas params from]
2033+ -> WindowDefinition grp commons schemas params from
2034+
2035+instance OrderBy WindowDefinition where
2036+ orderBy sortsR (WindowDefinition parts sortsL)
2037+ = WindowDefinition parts (sortsL ++ sortsR)
2038+
2039+instance RenderSQL (WindowDefinition commons schemas from grp params) where
2040+ renderSQL (WindowDefinition part ord) =
2041+ renderPartitionByClause part <> renderOrderByClause ord
2042+ where
2043+ renderPartitionByClause = \case
2044+ Nil -> ""
2045+ parts -> "PARTITION" <+> "BY" <+> renderCommaSeparated renderExpression parts
2046+ renderOrderByClause = \case
2047+ [] -> ""
2048+ srts -> " ORDER" <+> "BY"
2049+ <+> commaSeparated (renderSQL <$> srts)
2050+
2051+partitionBy
2052+ :: SListI bys
2053+ => NP (Expression grp commons schemas params from) bys
2054+ -> WindowDefinition grp commons schemas params from
2055+partitionBy bys = WindowDefinition bys []
2056+
2057+newtype WindowFunction
2058+ (grp :: Grouping)
2059+ (commons :: FromType)
2060+ (schemas :: SchemasType)
2061+ (params :: [NullityType])
2062+ (from :: FromType)
2063+ (ty :: NullityType)
2064+ = UnsafeWindowFunction { renderWindowFunction :: ByteString }
2065+ deriving (GHC.Generic,Show,Eq,Ord,NFData)
2066+
2067+instance RenderSQL (WindowFunction grp commons schemas params from ty) where
2068+ renderSQL = renderWindowFunction
2069+
2070+unsafeWindowFunction1
2071+ :: ByteString
2072+ -> Expression grp commons schemas params from ty0
2073+ -> WindowFunction grp commons schemas params from ty1
2074+unsafeWindowFunction1 fun x
2075+ = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x)
2076+
2077+unsafeWindowFunction2
2078+ :: ByteString
2079+ -> (Expression grp commons schemas params from :*: Expression grp commons schemas params from) ty0
2080+ -> WindowFunction grp commons schemas params from ty1
2081+unsafeWindowFunction2 fun (x :*: x')
2082+ = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x <> ", " <> renderSQL x')
2083+
2084+{- | rank of the current row with gaps; same as `rowNumber` of its first peer
2085+>>> printSQL rank
2086+rank()
2087+-}
2088+rank :: WindowFunction grp commons schemas params from ('NotNull 'PGint8)
2089+rank = UnsafeWindowFunction "rank()"
2090+
2091+{- | number of the current row within its partition, counting from 1
2092+>>> printSQL rowNumber
2093+row_number()
2094+-}
2095+rowNumber :: WindowFunction grp commons schemas params from ('NotNull 'PGint8)
2096+rowNumber = UnsafeWindowFunction "row_number()"
2097+
2098+{- | rank of the current row without gaps; this function counts peer groups
2099+>>> printSQL denseRank
2100+dense_rank()
2101+-}
2102+denseRank :: WindowFunction grp commons schemas params from ('NotNull 'PGint8)
2103+denseRank = UnsafeWindowFunction "dense_rank()"
2104+
2105+{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
2106+>>> printSQL percentRank
2107+percent_rank()
2108+-}
2109+percentRank :: WindowFunction grp commons schemas params from ('NotNull 'PGfloat8)
2110+percentRank = UnsafeWindowFunction "percent_rank()"
2111+
2112+{- | cumulative distribution: (number of partition rows
2113+preceding or peer with current row) / total partition rows
2114+>>> printSQL cumeDist
2115+cume_dist()
2116+-}
2117+cumeDist :: WindowFunction grp commons schemas params from ('NotNull 'PGfloat8)
2118+cumeDist = UnsafeWindowFunction "cume_dist()"
2119+
2120+{- | integer ranging from 1 to the argument value,
2121+dividing the partition as equally as possible
2122+-}
2123+ntile
2124+ :: Expression grp commons schemas params from ('NotNull 'PGint4)
2125+ -- ^ num buckets
2126+ -> WindowFunction grp commons schemas params from ('NotNull 'PGint4)
2127+ntile = unsafeWindowFunction1 "ntile"
2128+
2129+{- | returns value evaluated at the row that is offset rows before the current
2130+row within the partition; if there is no such row, instead return default
2131+(which must be of the same type as value). Both offset and default are
2132+evaluated with respect to the current row.
2133+-}
2134+lag
2135+ :: Expression grp commons schemas params from ty
2136+ -- ^ value
2137+ -> Expression grp commons schemas params from ('NotNull 'PGint4)
2138+ -- ^ offset
2139+ -> Expression grp commons schemas params from ty
2140+ -- ^ default
2141+ -> WindowFunction grp commons schemas params from ty
2142+lag value offset def = UnsafeWindowFunction $ "lag"
2143+ <> parenthesized
2144+ (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
2145+
2146+{- | returns value evaluated at the row that is offset rows after the current
2147+row within the partition; if there is no such row, instead return default
2148+(which must be of the same type as value). Both offset and default are
2149+evaluated with respect to the current row.
2150+-}
2151+lead
2152+ :: Expression grp commons schemas params from ty
2153+ -- ^ value
2154+ -> Expression grp commons schemas params from ('NotNull 'PGint4)
2155+ -- ^ offset
2156+ -> Expression grp commons schemas params from ty
2157+ -- ^ default
2158+ -> WindowFunction grp commons schemas params from ty
2159+lead value offset def = UnsafeWindowFunction $ "lag"
2160+ <> parenthesized
2161+ (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
2162+
2163+{- | returns value evaluated at the row that is the
2164+first row of the window frame
2165+-}
2166+firstValue
2167+ :: Expression grp commons schemas params from ty
2168+ -- ^ value
2169+ -> WindowFunction grp commons schemas params from ty
2170+firstValue = unsafeWindowFunction1 "first_value"
2171+
2172+{- | returns value evaluated at the row that is the
2173+last row of the window frame
2174+-}
2175+lastValue
2176+ :: Expression grp commons schemas params from ty
2177+ -- ^ value
2178+ -> WindowFunction grp commons schemas params from ty
2179+lastValue = unsafeWindowFunction1 "last_value"
2180+
2181+{- | returns value evaluated at the row that is the nth
2182+row of the window frame (counting from 1); null if no such row
2183+-}
2184+nthValue
2185+ :: Expression grp commons schemas params from (nullity ty)
2186+ -- ^ value
2187+ -> Expression grp commons schemas params from ('NotNull 'PGint4)
2188+ -- ^ nth
2189+ -> WindowFunction grp commons schemas params from ('Null ty)
2190+nthValue value nth = UnsafeWindowFunction $ "nth_value"
2191+ <> parenthesized (commaSeparated [renderSQL value, renderSQL nth])
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+36−36
@@ -263,13 +263,13 @@ insertInto_ tab qry =
263data QueryClause commons schemas params columns where
263data QueryClause commons schemas params columns where
264 Values
264 Values
265 :: SOP.SListI columns
265 :: SOP.SListI columns
266− => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
266+ => NP (ColumnExpression 'Ungrouped schemas params '[]) columns
267− -> [NP (ColumnExpression schemas params 'Ungrouped '[]) columns]
267+ -> [NP (ColumnExpression 'Ungrouped schemas params '[]) columns]
268 -> QueryClause commons schemas params columns
268 -> QueryClause commons schemas params columns
269 Select
269 Select
270 :: SOP.SListI columns
270 :: SOP.SListI columns
271− => NP (ColumnExpression schemas params grp from) columns
271+ => NP (ColumnExpression grp schemas params from) columns
272− -> TableExpression commons schemas params grp from
272+ -> TableExpression grp commons schemas params from
273 -> QueryClause commons schemas params columns
273 -> QueryClause commons schemas params columns
274 Subquery
274 Subquery
275 :: ColumnsToRow columns ~ row
275 :: ColumnsToRow columns ~ row
@@ -292,7 +292,7 @@ instance RenderSQL (QueryClause commons schemas params columns) where
292 Subquery qry -> renderQuery qry
292 Subquery qry -> renderQuery qry
293 where
293 where
294 renderSQLPartMaybe, renderValuePartMaybe
294 renderSQLPartMaybe, renderValuePartMaybe
295− :: ColumnExpression schemas params grp from column -> Maybe ByteString
295+ :: ColumnExpression grp schemas params from column -> Maybe ByteString
296 renderSQLPartMaybe = \case
296 renderSQLPartMaybe = \case
297 DefaultAs _ -> Nothing
297 DefaultAs _ -> Nothing
298 Specific (_ `As` name) -> Just $ renderSQL name
298 Specific (_ `As` name) -> Just $ renderSQL name
@@ -300,7 +300,7 @@ instance RenderSQL (QueryClause commons schemas params columns) where
300 DefaultAs _ -> Nothing
300 DefaultAs _ -> Nothing
301 Specific (value `As` _) -> Just $ renderExpression value
301 Specific (value `As` _) -> Just $ renderExpression value
302 renderSQLPart, renderValuePart
302 renderSQLPart, renderValuePart
303− :: ColumnExpression schemas params grp from column -> ByteString
303+ :: ColumnExpression grp schemas params from column -> ByteString
304 renderSQLPart = \case
304 renderSQLPart = \case
305 DefaultAs name -> renderSQL name
305 DefaultAs name -> renderSQL name
306 Specific (_ `As` name) -> renderSQL name
306 Specific (_ `As` name) -> renderSQL name
@@ -310,49 +310,49 @@ instance RenderSQL (QueryClause commons schemas params columns) where
310
310
311pattern Values_
311pattern Values_
312 :: SOP.SListI columns
312 :: SOP.SListI columns
313− => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
313+ => NP (ColumnExpression 'Ungrouped schemas params '[]) columns
314 -> QueryClause commons schemas params columns
314 -> QueryClause commons schemas params columns
315pattern Values_ vals = Values vals []
315pattern Values_ vals = Values vals []
316
316
317−data ColumnExpression schemas params grp from column where
317+data ColumnExpression grp schemas params from column where
318 DefaultAs
318 DefaultAs
319 :: KnownSymbol col
319 :: KnownSymbol col
320 => Alias col
320 => Alias col
321− -> ColumnExpression schemas params grp from (col ::: 'Def :=> ty)
321+ -> ColumnExpression grp schemas params from (col ::: 'Def :=> ty)
322 Specific
322 Specific
323− :: Aliased (Expression '[] schemas params grp from) (col ::: ty)
323+ :: Aliased (Expression grp '[] schemas params from) (col ::: ty)
324− -> ColumnExpression schemas params grp from (col ::: defness :=> ty)
324+ -> ColumnExpression grp schemas params from (col ::: defness :=> ty)
325
325
326instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
326instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
327 => Aliasable col
327 => Aliasable col
328− (Expression '[] schemas params grp from ty)
328+ (Expression grp '[] schemas params from ty)
329− (ColumnExpression schemas params grp from column) where
329+ (ColumnExpression grp schemas params from column) where
330 expression `as` col = Specific (expression `As` col)
330 expression `as` col = Specific (expression `As` col)
331instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
331instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
332 => Aliasable col
332 => Aliasable col
333− (Expression '[] schemas params grp from ty)
333+ (Expression grp '[] schemas params from ty)
334− (NP (ColumnExpression schemas params grp from) columns) where
334+ (NP (ColumnExpression grp schemas params from) columns) where
335 expression `as` col = expression `as` col :* Nil
335 expression `as` col = expression `as` col :* Nil
336instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
336instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
337− => DefaultAliasable col (ColumnExpression schemas params grp from column) where
337+ => DefaultAliasable col (ColumnExpression grp schemas params from column) where
338 defaultAs = DefaultAs
338 defaultAs = DefaultAs
339instance (KnownSymbol col, columns ~ '[col ::: 'Def :=> ty])
339instance (KnownSymbol col, columns ~ '[col ::: 'Def :=> ty])
340− => DefaultAliasable col (NP (ColumnExpression schemas params grp from) columns) where
340+ => DefaultAliasable col (NP (ColumnExpression grp schemas params from) columns) where
341 defaultAs col = defaultAs col :* Nil
341 defaultAs col = defaultAs col :* Nil
342
342
343instance (HasUnique tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
343instance (HasUnique tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
344− => IsLabel col (ColumnExpression schemas params 'Ungrouped from column) where
344+ => IsLabel col (ColumnExpression 'Ungrouped schemas params from column) where
345 fromLabel = fromLabel @col `as` Alias
345 fromLabel = fromLabel @col `as` Alias
346instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
346instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
347 => IsLabel col
347 => IsLabel col
348− (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
348+ (NP (ColumnExpression 'Ungrouped schemas params from) columns) where
349 fromLabel = fromLabel @col `as` Alias
349 fromLabel = fromLabel @col `as` Alias
350
350
351instance (Has tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
351instance (Has tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
352− => IsQualified tab col (ColumnExpression schemas params 'Ungrouped from column) where
352+ => IsQualified tab col (ColumnExpression 'Ungrouped schemas params from column) where
353 tab ! col = tab ! col `as` col
353 tab ! col = tab ! col `as` col
354instance (Has tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
354instance (Has tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
355− => IsQualified tab col (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
355+ => IsQualified tab col (NP (ColumnExpression 'Ungrouped schemas params from) columns) where
356 tab ! col = tab ! col `as` col
356 tab ! col = tab ! col `as` col
357
357
358instance
358instance
@@ -361,7 +361,7 @@ instance
361 , GroupedBy tab col bys
361 , GroupedBy tab col bys
362 , column ~ (col ::: defness :=> ty)
362 , column ~ (col ::: defness :=> ty)
363 ) => IsLabel col
363 ) => IsLabel col
364− (ColumnExpression schemas params ('Grouped bys) from column) where
364+ (ColumnExpression ('Grouped bys) schemas params from column) where
365 fromLabel = fromLabel @col `as` Alias
365 fromLabel = fromLabel @col `as` Alias
366instance
366instance
367 ( HasUnique tab from row
367 ( HasUnique tab from row
@@ -369,7 +369,7 @@ instance
369 , GroupedBy tab col bys
369 , GroupedBy tab col bys
370 , columns ~ '[col ::: defness :=> ty]
370 , columns ~ '[col ::: defness :=> ty]
371 ) => IsLabel col
371 ) => IsLabel col
372− (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
372+ (NP (ColumnExpression ('Grouped bys) schemas params from) columns) where
373 fromLabel = fromLabel @col `as` Alias
373 fromLabel = fromLabel @col `as` Alias
374
374
375instance
375instance
@@ -378,7 +378,7 @@ instance
378 , GroupedBy tab col bys
378 , GroupedBy tab col bys
379 , column ~ (col ::: defness :=> ty)
379 , column ~ (col ::: defness :=> ty)
380 ) => IsQualified tab col
380 ) => IsQualified tab col
381− (ColumnExpression schemas params ('Grouped bys) from column) where
381+ (ColumnExpression ('Grouped bys) schemas params from column) where
382 tab ! col = tab ! col `as` col
382 tab ! col = tab ! col `as` col
383instance
383instance
384 ( Has tab from row
384 ( Has tab from row
@@ -386,10 +386,10 @@ instance
386 , GroupedBy tab col bys
386 , GroupedBy tab col bys
387 , columns ~ '[col ::: defness :=> ty]
387 , columns ~ '[col ::: defness :=> ty]
388 ) => IsQualified tab col
388 ) => IsQualified tab col
389− (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
389+ (NP (ColumnExpression ('Grouped bys) schemas params from) columns) where
390 tab ! col = tab ! col :* Nil
390 tab ! col = tab ! col :* Nil
391
391
392−instance RenderSQL (ColumnExpression schemas params grp from column) where
392+instance RenderSQL (ColumnExpression grp schemas params from column) where
393 renderSQL = \case
393 renderSQL = \case
394 DefaultAs col ->
394 DefaultAs col ->
395 renderSQL col <+> "=" <+> "DEFAULT"
395 renderSQL col <+> "=" <+> "DEFAULT"
@@ -407,7 +407,7 @@ instance RenderSQL (ColumnExpression schemas params grp from column) where
407-- in the row. Use @Returning Nil@ in the common case where no return
407-- in the row. Use @Returning Nil@ in the common case where no return
408-- values are desired.
408-- values are desired.
409newtype ReturningClause commons schemas params from row =
409newtype ReturningClause commons schemas params from row =
410− Returning (Selection commons schemas params 'Ungrouped from row)
410+ Returning (Selection 'Ungrouped commons schemas params from row)
411
411
412instance RenderSQL (ReturningClause commons schemas params from row) where
412instance RenderSQL (ReturningClause commons schemas params from row) where
413 renderSQL = \case
413 renderSQL = \case
@@ -416,7 +416,7 @@ instance RenderSQL (ReturningClause commons schemas params from row) where
416
416
417pattern Returning_
417pattern Returning_
418 :: SOP.SListI row
418 :: SOP.SListI row
419− => NP (Aliased (Expression commons schemas params 'Ungrouped from)) row
419+ => NP (Aliased (Expression 'Ungrouped commons schemas params from)) row
420 -> ReturningClause commons schemas params from row
420 -> ReturningClause commons schemas params from row
421pattern Returning_ list = Returning (List list)
421pattern Returning_ list = Returning (List list)
422
422
@@ -448,8 +448,8 @@ data ConflictAction tab commons schemas params columns where
448 , columns ~ (col0 ': cols)
448 , columns ~ (col0 ': cols)
449 , SOP.All (HasIn columns) subcolumns
449 , SOP.All (HasIn columns) subcolumns
450 , AllUnique subcolumns )
450 , AllUnique subcolumns )
451− => NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]) subcolumns
451+ => NP (ColumnExpression 'Ungrouped schemas params '[tab ::: row, "excluded" ::: row]) subcolumns
452− -> [Condition commons schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]]
452+ -> [Condition 'Ungrouped commons schemas params '[tab ::: row, "excluded" ::: row]]
453 -> ConflictAction tab commons schemas params columns
453 -> ConflictAction tab commons schemas params columns
454
454
455instance RenderSQL (ConflictAction tab commons schemas params columns) where
455instance RenderSQL (ConflictAction tab commons schemas params columns) where
@@ -492,9 +492,9 @@ update
492 , SOP.All (HasIn columns) subcolumns
492 , SOP.All (HasIn columns) subcolumns
493 , AllUnique subcolumns )
493 , AllUnique subcolumns )
494 => QualifiedAlias sch tab -- ^ table to update
494 => QualifiedAlias sch tab -- ^ table to update
495− -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row0]) subcolumns
495+ -> NP (ColumnExpression 'Ungrouped schemas params '[tab ::: row0]) subcolumns
496 -- ^ modified values to replace old values
496 -- ^ modified values to replace old values
497− -> Condition commons schemas params 'Ungrouped '[tab ::: row0]
497+ -> Condition 'Ungrouped commons schemas params '[tab ::: row0]
498 -- ^ condition under which to perform update on a row
498 -- ^ condition under which to perform update on a row
499 -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
499 -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
500 -> Manipulation commons schemas params row1
500 -> Manipulation commons schemas params row1
@@ -517,9 +517,9 @@ update_
517 , SOP.All (HasIn columns) subcolumns
517 , SOP.All (HasIn columns) subcolumns
518 , AllUnique subcolumns )
518 , AllUnique subcolumns )
519 => QualifiedAlias sch tab -- ^ table to update
519 => QualifiedAlias sch tab -- ^ table to update
520− -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row]) subcolumns
520+ -> NP (ColumnExpression 'Ungrouped schemas params '[tab ::: row]) subcolumns
521 -- ^ modified values to replace old values
521 -- ^ modified values to replace old values
522− -> Condition commons schemas params 'Ungrouped '[tab ::: row]
522+ -> Condition 'Ungrouped commons schemas params '[tab ::: row]
523 -- ^ condition under which to perform update on a row
523 -- ^ condition under which to perform update on a row
524 -> Manipulation commons schemas params '[]
524 -> Manipulation commons schemas params '[]
525update_ tab columns wh = update tab columns wh (Returning_ Nil)
525update_ tab columns wh = update tab columns wh (Returning_ Nil)
@@ -544,7 +544,7 @@ deleteFrom
544 , columns ~ TableToColumns table )
544 , columns ~ TableToColumns table )
545 => QualifiedAlias sch tab -- ^ table to delete from
545 => QualifiedAlias sch tab -- ^ table to delete from
546 -> UsingClause commons schemas params from
546 -> UsingClause commons schemas params from
547− -> Condition commons schemas params 'Ungrouped (tab ::: row0 ': from)
547+ -> Condition 'Ungrouped commons schemas params (tab ::: row0 ': from)
548 -- ^ condition under which to delete a row
548 -- ^ condition under which to delete a row
549 -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
549 -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
550 -> Manipulation commons schemas params row1
550 -> Manipulation commons schemas params row1
@@ -566,7 +566,7 @@ deleteFrom_
566 , columns ~ TableToColumns table )
566 , columns ~ TableToColumns table )
567 => QualifiedAlias sch tab -- ^ table to delete from
567 => QualifiedAlias sch tab -- ^ table to delete from
568 -> UsingClause commons schemas params from
568 -> UsingClause commons schemas params from
569− -> Condition commons schemas params 'Ungrouped (tab ::: row ': from)
569+ -> Condition 'Ungrouped commons schemas params (tab ::: row ': from)
570 -- ^ condition under which to delete a row
570 -- ^ condition under which to delete a row
571 -> Manipulation commons schemas params '[]
571 -> Manipulation commons schemas params '[]
572deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
572deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+175−201
@@ -74,7 +74,6 @@ module Squeal.PostgreSQL.Query
74 , where_
74 , where_
75 , groupBy
75 , groupBy
76 , having
76 , having
77− , orderBy
78 , limit
77 , limit
79 , offset
78 , offset
80 -- * From Clauses
79 -- * From Clauses
@@ -92,8 +91,6 @@ module Squeal.PostgreSQL.Query
92 , By (..)
91 , By (..)
93 , GroupByClause (..)
92 , GroupByClause (..)
94 , HavingClause (..)
93 , HavingClause (..)
95− -- * Sorting
96− , SortExpression (..)
97 -- * Subquery Expressions
94 -- * Subquery Expressions
98 , in_
95 , in_
99 , rowIn
96 , rowIn
@@ -203,13 +200,13 @@ aggregation query:
203let
200let
204 query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
201 query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
205 query =
202 query =
206− select_ (sum_ #col2 `as` #sum :* #col1)
203+ select_ (sum_ (All #col2) `as` #sum :* #col1)
207 ( from (table (#tab `as` #table1))
204 ( from (table (#tab `as` #table1))
208 & groupBy #col1
205 & groupBy #col1
209− & having (#col1 + sum_ #col2 .> 1) )
206+ & having (#col1 + sum_ (Distinct #col2) .> 1) )
210in printSQL query
207in printSQL query
211:}
208:}
212−SELECT sum("col2") AS "sum", "col1" AS "col1" FROM "tab" AS "table1" GROUP BY "col1" HAVING (("col1" + sum("col2")) > 1)
209+SELECT sum(ALL "col2") AS "sum", "col1" AS "col1" FROM "tab" AS "table1" GROUP BY "col1" HAVING (("col1" + sum(DISTINCT "col2")) > 1)
213
210
214sorted query:
211sorted query:
215
212
@@ -313,6 +310,18 @@ let
313in printSQL query
310in printSQL query
314:}
311:}
315WITH "cte1" AS (SELECT * FROM "tab" AS "tab"), "cte2" AS (SELECT * FROM "cte1" AS "cte1") SELECT * FROM "cte2" AS "cte2"
312WITH "cte1" AS (SELECT * FROM "tab" AS "tab"), "cte2" AS (SELECT * FROM "cte1" AS "cte1") SELECT * FROM "cte2" AS "cte2"
313+
314+window function queries
315+
316+>>> :{
317+let
318+ query :: Query '[] (Public Schema) '[] ["col1" ::: 'NotNull 'PGint4, "rank" ::: 'NotNull 'PGint8]
319+ query = select
320+ (#col1 & Also (rank `as` #rank `Over` (partitionBy #col1 & orderBy [#col2 & Asc])))
321+ (from (table #tab))
322+in printSQL query
323+:}
324+SELECT "col1" AS "col1", rank() OVER (PARTITION BY "col1" ORDER BY "col2" ASC) AS "rank" FROM "tab" AS "tab"
316-}
325-}
317newtype Query
326newtype Query
318 (commons :: FromType)
327 (commons :: FromType)
@@ -396,54 +405,69 @@ q1 `exceptAll` q2 = UnsafeQuery $
396SELECT queries
405SELECT queries
397-----------------------------------------}
406-----------------------------------------}
398
407
399−data Selection commons schemas params grp from row where
408+data Selection grp commons schemas params from row where
400 List
409 List
401 :: SListI row
410 :: SListI row
402− => NP (Aliased (Expression commons schemas params grp from)) row
411+ => NP (Aliased (Expression grp commons schemas params from)) row
403− -> Selection commons schemas params grp from row
412+ -> Selection grp commons schemas params from row
404 Star
413 Star
405 :: HasUnique tab from row
414 :: HasUnique tab from row
406− => Selection commons schemas params 'Ungrouped from row
415+ => Selection 'Ungrouped commons schemas params from row
407 DotStar
416 DotStar
408 :: Has tab from row
417 :: Has tab from row
409 => Alias tab
418 => Alias tab
410− -> Selection commons schemas params 'Ungrouped from row
419+ -> Selection 'Ungrouped commons schemas params from row
411 Also
420 Also
412− :: Selection commons schemas params grp from right
421+ :: Selection grp commons schemas params from right
413− -> Selection commons schemas params grp from left
422+ -> Selection grp commons schemas params from left
414− -> Selection commons schemas params grp from (Join left right)
423+ -> Selection grp commons schemas params from (Join left right)
424+ Over
425+ :: SListI row
426+ => NP (Aliased (WindowFunction grp commons schemas params from)) row
427+ -> WindowDefinition grp commons schemas params from
428+ -> Selection grp commons schemas params from row
415instance (KnownSymbol col, row ~ '[col ::: ty])
429instance (KnownSymbol col, row ~ '[col ::: ty])
416 => Aliasable col
430 => Aliasable col
417− (Expression commons schemas params grp from ty)
431+ (Expression grp commons schemas params from ty)
418− (Selection commons schemas params grp from row) where
432+ (Selection grp commons schemas params from row) where
419 expr `as` col = List (expr `as` col)
433 expr `as` col = List (expr `as` col)
420instance (Has tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
434instance (Has tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
421− => IsQualified tab col (Selection commons schemas params 'Ungrouped from row1) where
435+ => IsQualified tab col (Selection 'Ungrouped commons schemas params from row1) where
422 tab ! col = tab ! col `as` col
436 tab ! col = tab ! col `as` col
423instance
437instance
424 ( Has tab from row0
438 ( Has tab from row0
425 , Has col row0 ty
439 , Has col row0 ty
426 , row1 ~ '[col ::: ty]
440 , row1 ~ '[col ::: ty]
427 , GroupedBy tab col bys )
441 , GroupedBy tab col bys )
428− => IsQualified tab col (Selection commons schemas params ('Grouped bys) from row1) where
442+ => IsQualified tab col (Selection ('Grouped bys) commons schemas params from row1) where
429 tab ! col = tab ! col `as` col
443 tab ! col = tab ! col `as` col
430instance (HasUnique tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
444instance (HasUnique tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
431− => IsLabel col (Selection commons schemas params 'Ungrouped from row1) where
445+ => IsLabel col (Selection 'Ungrouped commons schemas params from row1) where
432 fromLabel = fromLabel @col `as` Alias
446 fromLabel = fromLabel @col `as` Alias
433instance
447instance
434 ( HasUnique tab from row0
448 ( HasUnique tab from row0
435 , Has col row0 ty
449 , Has col row0 ty
436 , row1 ~ '[col ::: ty]
450 , row1 ~ '[col ::: ty]
437 , GroupedBy tab col bys )
451 , GroupedBy tab col bys )
438− => IsLabel col (Selection commons schemas params ('Grouped bys) from row1) where
452+ => IsLabel col (Selection ('Grouped bys) commons schemas params from row1) where
439 fromLabel = fromLabel @col `as` Alias
453 fromLabel = fromLabel @col `as` Alias
440
454
441−instance RenderSQL (Selection commons schemas params grp from row) where
455+instance RenderSQL (Selection grp commons schemas params from row) where
442 renderSQL = \case
456 renderSQL = \case
443 List list -> renderCommaSeparated (renderAliased renderSQL) list
457 List list -> renderCommaSeparated (renderAliased renderSQL) list
444 Star -> "*"
458 Star -> "*"
445 DotStar tab -> renderSQL tab <> ".*"
459 DotStar tab -> renderSQL tab <> ".*"
446 Also right left -> renderSQL left <> ", " <> renderSQL right
460 Also right left -> renderSQL left <> ", " <> renderSQL right
461+ Over winFns winDef ->
462+ let
463+ renderOver
464+ :: Aliased (WindowFunction grp commons schemas params from) field
465+ -> ByteString
466+ renderOver (winFn `As` col) = renderSQL winFn
467+ <+> "OVER" <+> parenthesized (renderSQL winDef)
468+ <+> "AS" <+> renderSQL col
469+ in
470+ renderCommaSeparated renderOver winFns
447
471
448-- | the `TableExpression` in the `select` command constructs an intermediate
472-- | the `TableExpression` in the `select` command constructs an intermediate
449-- virtual table by possibly combining tables, views, eliminating rows,
473-- virtual table by possibly combining tables, views, eliminating rows,
@@ -452,9 +476,9 @@ instance RenderSQL (Selection commons schemas params grp from row) where
452-- the intermediate table are actually output.
476-- the intermediate table are actually output.
453select
477select
454 :: (SListI row, row ~ (x ': xs))
478 :: (SListI row, row ~ (x ': xs))
455− => Selection commons schemas params grp from row
479+ => Selection grp commons schemas params from row
456 -- ^ select list
480 -- ^ select list
457− -> TableExpression commons schemas params grp from
481+ -> TableExpression grp commons schemas params from
458 -- ^ intermediate virtual table
482 -- ^ intermediate virtual table
459 -> Query commons schemas params row
483 -> Query commons schemas params row
460select selection tabexpr = UnsafeQuery $
484select selection tabexpr = UnsafeQuery $
@@ -464,8 +488,8 @@ select selection tabexpr = UnsafeQuery $
464
488
465select_
489select_
466 :: (SListI row, row ~ (x ': xs))
490 :: (SListI row, row ~ (x ': xs))
467− => NP (Aliased (Expression commons schemas params grp from)) row
491+ => NP (Aliased (Expression grp commons schemas params from)) row
468− -> TableExpression commons schemas params grp from
492+ -> TableExpression grp commons schemas params from
469 -> Query commons schemas params row
493 -> Query commons schemas params row
470select_ list = select (List list)
494select_ list = select (List list)
471
495
@@ -473,9 +497,9 @@ select_ list = select (List list)
473-- be subject to the elimination of duplicate rows using `selectDistinct`.
497-- be subject to the elimination of duplicate rows using `selectDistinct`.
474selectDistinct
498selectDistinct
475 :: (SListI columns, columns ~ (col ': cols))
499 :: (SListI columns, columns ~ (col ': cols))
476− => Selection commons schemas params 'Ungrouped from columns
500+ => Selection 'Ungrouped commons schemas params from columns
477 -- ^ select list
501 -- ^ select list
478− -> TableExpression commons schemas params 'Ungrouped from
502+ -> TableExpression 'Ungrouped commons schemas params from
479 -- ^ intermediate virtual table
503 -- ^ intermediate virtual table
480 -> Query commons schemas params columns
504 -> Query commons schemas params columns
481selectDistinct selection tabexpr = UnsafeQuery $
505selectDistinct selection tabexpr = UnsafeQuery $
@@ -485,9 +509,9 @@ selectDistinct selection tabexpr = UnsafeQuery $
485
509
486selectDistinct_
510selectDistinct_
487 :: (SListI columns, columns ~ (col ': cols))
511 :: (SListI columns, columns ~ (col ': cols))
488− => NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns
512+ => NP (Aliased (Expression 'Ungrouped commons schemas params from)) columns
489 -- ^ select list
513 -- ^ select list
490− -> TableExpression commons schemas params 'Ungrouped from
514+ -> TableExpression 'Ungrouped commons schemas params from
491 -- ^ intermediate virtual table
515 -- ^ intermediate virtual table
492 -> Query commons schemas params columns
516 -> Query commons schemas params columns
493selectDistinct_ list = select (List list)
517selectDistinct_ list = select (List list)
@@ -503,8 +527,8 @@ selectDistinct_ list = select (List list)
503-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
527-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
504values
528values
505 :: SListI cols
529 :: SListI cols
506− => NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols
530+ => NP (Aliased (Expression 'Ungrouped commons schemas params '[] )) cols
507− -> [NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols]
531+ -> [NP (Aliased (Expression 'Ungrouped commons schemas params '[] )) cols]
508 -- ^ When more than one row is specified, all the rows must
532 -- ^ When more than one row is specified, all the rows must
509 -- must have the same number of elements
533 -- must have the same number of elements
510 -> Query commons schemas params cols
534 -> Query commons schemas params cols
@@ -518,7 +542,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
518 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
542 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
519 where
543 where
520 renderAliasPart, renderValuePart
544 renderAliasPart, renderValuePart
521− :: Aliased (Expression commons schemas params 'Ungrouped '[] ) ty -> ByteString
545+ :: Aliased (Expression 'Ungrouped commons schemas params '[] ) ty -> ByteString
522 renderAliasPart (_ `As` name) = renderSQL name
546 renderAliasPart (_ `As` name) = renderSQL name
523 renderValuePart (value `As` _) = renderSQL value
547 renderValuePart (value `As` _) = renderSQL value
524
548
@@ -526,7 +550,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
526-- specified by value expressions.
550-- specified by value expressions.
527values_
551values_
528 :: SListI cols
552 :: SListI cols
529− => NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols
553+ => NP (Aliased (Expression 'Ungrouped commons schemas params '[] )) cols
530 -- ^ one row of values
554 -- ^ one row of values
531 -> Query commons schemas params cols
555 -> Query commons schemas params cols
532values_ rw = values rw []
556values_ rw = values rw []
@@ -542,16 +566,16 @@ Table Expressions
542-- to a table on disk, a so-called base table, but more complex expressions
566-- to a table on disk, a so-called base table, but more complex expressions
543-- can be used to modify or combine base tables in various ways.
567-- can be used to modify or combine base tables in various ways.
544data TableExpression
568data TableExpression
569+ (grp :: Grouping)
545 (commons :: FromType)
570 (commons :: FromType)
546 (schemas :: SchemasType)
571 (schemas :: SchemasType)
547 (params :: [NullityType])
572 (params :: [NullityType])
548− (grp :: Grouping)
549 (from :: FromType)
573 (from :: FromType)
550 = TableExpression
574 = TableExpression
551 { fromClause :: FromClause commons schemas params from
575 { fromClause :: FromClause commons schemas params from
552 -- ^ A table reference that can be a table name, or a derived table such
576 -- ^ A table reference that can be a table name, or a derived table such
553 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
577 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
554− , whereClause :: [Condition commons schemas params 'Ungrouped from]
578+ , whereClause :: [Condition 'Ungrouped commons schemas params from]
555 -- ^ optional search coditions, combined with `.&&`. After the processing
579 -- ^ optional search coditions, combined with `.&&`. After the processing
556 -- of the `fromClause` is done, each row of the derived virtual table
580 -- of the `fromClause` is done, each row of the derived virtual table
557 -- is checked against the search condition. If the result of the
581 -- is checked against the search condition. If the result of the
@@ -567,13 +591,13 @@ data TableExpression
567 -- set of rows having common values into one group row that represents all
591 -- set of rows having common values into one group row that represents all
568 -- rows in the group. This is done to eliminate redundancy in the output
592 -- rows in the group. This is done to eliminate redundancy in the output
569 -- and/or compute aggregates that apply to these groups.
593 -- and/or compute aggregates that apply to these groups.
570− , havingClause :: HavingClause commons schemas params grp from
594+ , havingClause :: HavingClause grp commons schemas params from
571 -- ^ If a table has been grouped using `groupBy`, but only certain groups
595 -- ^ If a table has been grouped using `groupBy`, but only certain groups
572 -- are of interest, the `havingClause` can be used, much like a
596 -- are of interest, the `havingClause` can be used, much like a
573 -- `whereClause`, to eliminate groups from the result. Expressions in the
597 -- `whereClause`, to eliminate groups from the result. Expressions in the
574 -- `havingClause` can refer both to grouped expressions and to ungrouped
598 -- `havingClause` can refer both to grouped expressions and to ungrouped
575 -- expressions (which necessarily involve an aggregate function).
599 -- expressions (which necessarily involve an aggregate function).
576− , orderByClause :: [SortExpression commons schemas params grp from]
600+ , orderByClause :: [SortExpression grp commons schemas params from]
577 -- ^ The `orderByClause` is for optional sorting. When more than one
601 -- ^ The `orderByClause` is for optional sorting. When more than one
578 -- `SortExpression` is specified, the later (right) values are used to sort
602 -- `SortExpression` is specified, the later (right) values are used to sort
579 -- rows that are equal according to the earlier (left) values.
603 -- rows that are equal according to the earlier (left) values.
@@ -590,7 +614,7 @@ data TableExpression
590 }
614 }
591
615
592-- | Render a `TableExpression`
616-- | Render a `TableExpression`
593−instance RenderSQL (TableExpression commons schemas params grp from) where
617+instance RenderSQL (TableExpression grp commons schemas params from) where
594 renderSQL
618 renderSQL
595 (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
619 (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
596 [ "FROM ", renderSQL frm'
620 [ "FROM ", renderSQL frm'
@@ -624,15 +648,15 @@ instance RenderSQL (TableExpression commons schemas params grp from) where
624-- to match the left-to-right sequencing of their placement in SQL.
648-- to match the left-to-right sequencing of their placement in SQL.
625from
649from
626 :: FromClause commons schemas params from -- ^ table reference
650 :: FromClause commons schemas params from -- ^ table reference
627− -> TableExpression commons schemas params 'Ungrouped from
651+ -> TableExpression 'Ungrouped commons schemas params from
628from rels = TableExpression rels [] NoGroups NoHaving [] [] []
652from rels = TableExpression rels [] NoGroups NoHaving [] [] []
629
653
630-- | A `where_` is an endomorphism of `TableExpression`s which adds a
654-- | A `where_` is an endomorphism of `TableExpression`s which adds a
631-- search condition to the `whereClause`.
655-- search condition to the `whereClause`.
632where_
656where_
633− :: Condition commons schemas params 'Ungrouped from -- ^ filtering condition
657+ :: Condition 'Ungrouped commons schemas params from -- ^ filtering condition
634− -> TableExpression commons schemas params grp from
658+ -> TableExpression grp commons schemas params from
635− -> TableExpression commons schemas params grp from
659+ -> TableExpression grp commons schemas params from
636where_ wh rels = rels {whereClause = wh : whereClause rels}
660where_ wh rels = rels {whereClause = wh : whereClause rels}
637
661
638-- | A `groupBy` is a transformation of `TableExpression`s which switches
662-- | A `groupBy` is a transformation of `TableExpression`s which switches
@@ -641,8 +665,8 @@ where_ wh rels = rels {whereClause = wh : whereClause rels}
641groupBy
665groupBy
642 :: SListI bys
666 :: SListI bys
643 => NP (By from) bys -- ^ grouped columns
667 => NP (By from) bys -- ^ grouped columns
644− -> TableExpression commons schemas params 'Ungrouped from
668+ -> TableExpression 'Ungrouped commons schemas params from
645− -> TableExpression commons schemas params ('Grouped bys) from
669+ -> TableExpression ('Grouped bys) commons schemas params from
646groupBy bys rels = TableExpression
670groupBy bys rels = TableExpression
647 { fromClause = fromClause rels
671 { fromClause = fromClause rels
648 , whereClause = whereClause rels
672 , whereClause = whereClause rels
@@ -656,34 +680,29 @@ groupBy bys rels = TableExpression
656-- | A `having` is an endomorphism of `TableExpression`s which adds a
680-- | A `having` is an endomorphism of `TableExpression`s which adds a
657-- search condition to the `havingClause`.
681-- search condition to the `havingClause`.
658having
682having
659− :: Condition commons schemas params ('Grouped bys) from -- ^ having condition
683+ :: Condition ('Grouped bys) commons schemas params from -- ^ having condition
660− -> TableExpression commons schemas params ('Grouped bys) from
684+ -> TableExpression ('Grouped bys) commons schemas params from
661− -> TableExpression commons schemas params ('Grouped bys) from
685+ -> TableExpression ('Grouped bys) commons schemas params from
662having hv rels = rels
686having hv rels = rels
663 { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
687 { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
664
688
665−-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
689+instance OrderBy TableExpression where
666−-- ordering to the right of the `orderByClause`.
667−orderBy
668− :: [SortExpression commons schemas params grp from] -- ^ sort expressions
669− -> TableExpression commons schemas params grp from
670− -> TableExpression commons schemas params grp from
671−orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
690+ orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
672
691
673-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
692-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
674-- `limitClause`.
693-- `limitClause`.
675limit
694limit
676 :: Word64 -- ^ limit parameter
695 :: Word64 -- ^ limit parameter
677− -> TableExpression commons schemas params grp from
696+ -> TableExpression grp commons schemas params from
678− -> TableExpression commons schemas params grp from
697+ -> TableExpression grp commons schemas params from
679limit lim rels = rels {limitClause = lim : limitClause rels}
698limit lim rels = rels {limitClause = lim : limitClause rels}
680
699
681-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
700-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
682-- `offsetClause`.
701-- `offsetClause`.
683offset
702offset
684 :: Word64 -- ^ offset parameter
703 :: Word64 -- ^ offset parameter
685− -> TableExpression commons schemas params grp from
704+ -> TableExpression grp commons schemas params from
686− -> TableExpression commons schemas params grp from
705+ -> TableExpression grp commons schemas params from
687offset off rels = rels {offsetClause = off : offsetClause rels}
706offset off rels = rels {offsetClause = off : offsetClause rels}
688
707
689{-----------------------------------------
708{-----------------------------------------
@@ -692,55 +711,55 @@ JSON stuff
692
711
693unsafeSetOfFunction
712unsafeSetOfFunction
694 :: ByteString
713 :: ByteString
695− -> Expression commons schemas params 'Ungrouped '[] ty
714+ -> Expression 'Ungrouped commons schemas params '[] ty
696 -> Query commons schemas params row
715 -> Query commons schemas params row
697unsafeSetOfFunction fun expr = UnsafeQuery $
716unsafeSetOfFunction fun expr = UnsafeQuery $
698 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
717 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
699
718
700-- | 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.
701jsonEach
720jsonEach
702− :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
721+ :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
703 -> Query commons schemas params
722 -> Query commons schemas params
704 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
723 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
705jsonEach = unsafeSetOfFunction "json_each"
724jsonEach = unsafeSetOfFunction "json_each"
706
725
707-- | 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.
708jsonbEach
727jsonbEach
709− :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
728+ :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
710 -> Query commons schemas params
729 -> Query commons schemas params
711 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
730 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
712jsonbEach = unsafeSetOfFunction "jsonb_each"
731jsonbEach = unsafeSetOfFunction "jsonb_each"
713
732
714-- | 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.
715jsonEachAsText
734jsonEachAsText
716− :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
735+ :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
717 -> Query commons schemas params
736 -> Query commons schemas params
718 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
737 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
719jsonEachAsText = unsafeSetOfFunction "json_each_text"
738jsonEachAsText = unsafeSetOfFunction "json_each_text"
720
739
721-- | 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.
722jsonbEachAsText
741jsonbEachAsText
723− :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
742+ :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
724 -> Query commons schemas params
743 -> Query commons schemas params
725 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
744 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
726jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
745jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
727
746
728-- | Returns set of keys in the outermost JSON object.
747-- | Returns set of keys in the outermost JSON object.
729jsonObjectKeys
748jsonObjectKeys
730− :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
749+ :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
731 -> Query commons schemas params '["json_object_keys" ::: 'NotNull 'PGtext]
750 -> Query commons schemas params '["json_object_keys" ::: 'NotNull 'PGtext]
732jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
751jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
733
752
734-- | Returns set of keys in the outermost JSON object.
753-- | Returns set of keys in the outermost JSON object.
735jsonbObjectKeys
754jsonbObjectKeys
736− :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
755+ :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
737 -> Query commons schemas params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
756 -> Query commons schemas params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
738jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
757jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
739
758
740unsafePopulateFunction
759unsafePopulateFunction
741 :: ByteString
760 :: ByteString
742 -> TypeExpression schemas (nullity ('PGcomposite row))
761 -> TypeExpression schemas (nullity ('PGcomposite row))
743− -> Expression commons schemas params 'Ungrouped '[] ty
762+ -> Expression 'Ungrouped commons schemas params '[] ty
744 -> Query commons schemas params row
763 -> Query commons schemas params row
745unsafePopulateFunction fun ty expr = UnsafeQuery $
764unsafePopulateFunction fun ty expr = UnsafeQuery $
746 "SELECT * FROM " <> fun <> "("
765 "SELECT * FROM " <> fun <> "("
@@ -751,7 +770,7 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
751-- type defined by the given table.
770-- type defined by the given table.
752jsonPopulateRecord
771jsonPopulateRecord
753 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
772 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
754− -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
773+ -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
755 -> Query commons schemas params row
774 -> Query commons schemas params row
756jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
775jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
757
776
@@ -759,7 +778,7 @@ jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
759-- type defined by the given table.
778-- type defined by the given table.
760jsonbPopulateRecord
779jsonbPopulateRecord
761 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
780 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
762− -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
781+ -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
763 -> Query commons schemas params row
782 -> Query commons schemas params row
764jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
783jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
765
784
@@ -767,7 +786,7 @@ jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
767-- 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.
768jsonPopulateRecordSet
787jsonPopulateRecordSet
769 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
788 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
770− -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
789+ -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json array
771 -> Query commons schemas params row
790 -> Query commons schemas params row
772jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
791jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
773
792
@@ -776,14 +795,14 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
776-- table.
795-- table.
777jsonbPopulateRecordSet
796jsonbPopulateRecordSet
778 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
797 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
779− -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
798+ -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb array
780 -> Query commons schemas params row
799 -> Query commons schemas params row
781jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
800jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
782
801
783unsafeRecordFunction
802unsafeRecordFunction
784 :: (SListI record, json `In` PGJsonType)
803 :: (SListI record, json `In` PGJsonType)
785 => ByteString
804 => ByteString
786− -> Expression commons schemas params 'Ungrouped '[] (nullity json)
805+ -> Expression 'Ungrouped commons schemas params '[] (nullity json)
787 -> NP (Aliased (TypeExpression schemas)) record
806 -> NP (Aliased (TypeExpression schemas)) record
788 -> Query commons schemas params record
807 -> Query commons schemas params record
789unsafeRecordFunction fun expr types = UnsafeQuery $
808unsafeRecordFunction fun expr types = UnsafeQuery $
@@ -798,7 +817,7 @@ unsafeRecordFunction fun expr types = UnsafeQuery $
798-- | Builds an arbitrary record from a JSON object.
817-- | Builds an arbitrary record from a JSON object.
799jsonToRecord
818jsonToRecord
800 :: SListI record
819 :: SListI record
801− => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
820+ => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
802 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
821 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
803 -> Query commons schemas params record
822 -> Query commons schemas params record
804jsonToRecord = unsafeRecordFunction "json_to_record"
823jsonToRecord = unsafeRecordFunction "json_to_record"
@@ -806,7 +825,7 @@ jsonToRecord = unsafeRecordFunction "json_to_record"
806-- | Builds an arbitrary record from a binary JSON object.
825-- | Builds an arbitrary record from a binary JSON object.
807jsonbToRecord
826jsonbToRecord
808 :: SListI record
827 :: SListI record
809− => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
828+ => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
810 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
829 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
811 -> Query commons schemas params record
830 -> Query commons schemas params record
812jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
831jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
@@ -814,7 +833,7 @@ jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
814-- | 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.
815jsonToRecordSet
834jsonToRecordSet
816 :: SListI record
835 :: SListI record
817− => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
836+ => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json array
818 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
837 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
819 -> Query commons schemas params record
838 -> Query commons schemas params record
820jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
839jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
@@ -822,7 +841,7 @@ jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
822-- | Builds an arbitrary set of records from a binary JSON array of objects.
841-- | Builds an arbitrary set of records from a binary JSON array of objects.
823jsonbToRecordSet
842jsonbToRecordSet
824 :: SListI record
843 :: SListI record
825− => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
844+ => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb array
826 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
845 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
827 -> Query commons schemas params record
846 -> Query commons schemas params record
828jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
847jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
@@ -891,7 +910,7 @@ the @on@ condition.
891innerJoin
910innerJoin
892 :: FromClause commons schemas params right
911 :: FromClause commons schemas params right
893 -- ^ right
912 -- ^ right
894− -> Condition commons schemas params 'Ungrouped (Join left right)
913+ -> Condition 'Ungrouped commons schemas params (Join left right)
895 -- ^ @on@ condition
914 -- ^ @on@ condition
896 -> FromClause commons schemas params left
915 -> FromClause commons schemas params left
897 -- ^ left
916 -- ^ left
@@ -908,7 +927,7 @@ innerJoin right on left = UnsafeFromClause $
908leftOuterJoin
927leftOuterJoin
909 :: FromClause commons schemas params right
928 :: FromClause commons schemas params right
910 -- ^ right
929 -- ^ right
911− -> Condition commons schemas params 'Ungrouped (Join left right)
930+ -> Condition 'Ungrouped commons schemas params (Join left right)
912 -- ^ @on@ condition
931 -- ^ @on@ condition
913 -> FromClause commons schemas params left
932 -> FromClause commons schemas params left
914 -- ^ left
933 -- ^ left
@@ -926,7 +945,7 @@ leftOuterJoin right on left = UnsafeFromClause $
926rightOuterJoin
945rightOuterJoin
927 :: FromClause commons schemas params right
946 :: FromClause commons schemas params right
928 -- ^ right
947 -- ^ right
929− -> Condition commons schemas params 'Ungrouped (Join left right)
948+ -> Condition 'Ungrouped commons schemas params (Join left right)
930 -- ^ @on@ condition
949 -- ^ @on@ condition
931 -> FromClause commons schemas params left
950 -> FromClause commons schemas params left
932 -- ^ left
951 -- ^ left
@@ -945,7 +964,7 @@ rightOuterJoin right on left = UnsafeFromClause $
945fullOuterJoin
964fullOuterJoin
946 :: FromClause commons schemas params right
965 :: FromClause commons schemas params right
947 -- ^ right
966 -- ^ right
948− -> Condition commons schemas params 'Ungrouped (Join left right)
967+ -> Condition 'Ungrouped commons schemas params (Join left right)
949 -- ^ @on@ condition
968 -- ^ @on@ condition
950 -> FromClause commons schemas params left
969 -> FromClause commons schemas params left
951 -- ^ left
970 -- ^ left
@@ -1018,82 +1037,37 @@ instance RenderSQL (GroupByClause grp from) where
1018-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
1037-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
1019-- `TableExpression` must use `Having` whose conditions are combined with
1038-- `TableExpression` must use `Having` whose conditions are combined with
1020-- `.&&`.
1039-- `.&&`.
1021−data HavingClause commons schemas params grp from where
1040+data HavingClause grp commons schemas params from where
1022− NoHaving :: HavingClause commons schemas params 'Ungrouped from
1041+ NoHaving :: HavingClause 'Ungrouped commons schemas params from
1023 Having
1042 Having
1024− :: [Condition commons schemas params ('Grouped bys) from]
1043+ :: [Condition ('Grouped bys) commons schemas params from]
1025− -> HavingClause commons schemas params ('Grouped bys) from
1044+ -> HavingClause ('Grouped bys) commons schemas params from
1026−deriving instance Show (HavingClause commons schemas params grp from)
1045+deriving instance Show (HavingClause grp commons schemas params from)
1027−deriving instance Eq (HavingClause commons schemas params grp from)
1046+deriving instance Eq (HavingClause grp commons schemas params from)
1028−deriving instance Ord (HavingClause commons schemas params grp from)
1047+deriving instance Ord (HavingClause grp commons schemas params from)
1029
1048
1030-- | Render a `HavingClause`.
1049-- | Render a `HavingClause`.
1031−instance RenderSQL (HavingClause commons schemas params grp from) where
1050+instance RenderSQL (HavingClause grp commons schemas params from) where
1032 renderSQL = \case
1051 renderSQL = \case
1033 NoHaving -> ""
1052 NoHaving -> ""
1034 Having [] -> ""
1053 Having [] -> ""
1035 Having conditions ->
1054 Having conditions ->
1036 " HAVING" <+> commaSeparated (renderSQL <$> conditions)
1055 " HAVING" <+> commaSeparated (renderSQL <$> conditions)
1037
1056
1038−{-----------------------------------------
1039−Sorting
1040−-----------------------------------------}
1041−
1042−-- | `SortExpression`s are used by `sortBy` to optionally sort the results
1043−-- of a `Query`. `Asc` or `Desc` set the sort direction of a `NotNull` result
1044−-- column to ascending or descending. Ascending order puts smaller values
1045−-- first, where "smaller" is defined in terms of the `.<` operator. Similarly,
1046−-- descending order is determined with the `.>` operator. `AscNullsFirst`,
1047−-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
1048−-- determine whether nulls appear before or after non-null values in the sort
1049−-- ordering of a `Null` result column.
1050−data SortExpression commons schemas params grp from where
1051− Asc
1052− :: Expression commons schemas params grp from ('NotNull ty)
1053− -> SortExpression commons schemas params grp from
1054− Desc
1055− :: Expression commons schemas params grp from ('NotNull ty)
1056− -> SortExpression commons schemas params grp from
1057− AscNullsFirst
1058− :: Expression commons schemas params grp from ('Null ty)
1059− -> SortExpression commons schemas params grp from
1060− AscNullsLast
1061− :: Expression commons schemas params grp from ('Null ty)
1062− -> SortExpression commons schemas params grp from
1063− DescNullsFirst
1064− :: Expression commons schemas params grp from ('Null ty)
1065− -> SortExpression commons schemas params grp from
1066− DescNullsLast
1067− :: Expression commons schemas params grp from ('Null ty)
1068− -> SortExpression commons schemas params grp from
1069−deriving instance Show (SortExpression commons schemas params grp from)
1070−
1071−-- | Render a `SortExpression`.
1072−instance RenderSQL (SortExpression commons schemas params grp from) where
1073− renderSQL = \case
1074− Asc expression -> renderSQL expression <+> "ASC"
1075− Desc expression -> renderSQL expression <+> "DESC"
1076− AscNullsFirst expression -> renderSQL expression
1077− <+> "ASC NULLS FIRST"
1078− DescNullsFirst expression -> renderSQL expression
1079− <+> "DESC NULLS FIRST"
1080− AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
1081− DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
1082−
1083unsafeSubqueryExpression
1057unsafeSubqueryExpression
1084 :: ByteString
1058 :: ByteString
1085− -> Expression commons schemas params grp from ty
1059+ -> Expression grp commons schemas params from ty
1086 -> Query commons schemas params '[alias ::: ty]
1060 -> Query commons schemas params '[alias ::: ty]
1087− -> Expression commons schemas params grp from (nullity 'PGbool)
1061+ -> Expression grp commons schemas params from (nullity 'PGbool)
1088unsafeSubqueryExpression op x q = UnsafeExpression $
1062unsafeSubqueryExpression op x q = UnsafeExpression $
1089 renderSQL x <+> op <+> parenthesized (renderSQL q)
1063 renderSQL x <+> op <+> parenthesized (renderSQL q)
1090
1064
1091unsafeRowSubqueryExpression
1065unsafeRowSubqueryExpression
1092 :: SListI row
1066 :: SListI row
1093 => ByteString
1067 => ByteString
1094− -> NP (Aliased (Expression commons schemas params grp from)) row
1068+ -> NP (Aliased (Expression grp commons schemas params from)) row
1095 -> Query commons schemas params row
1069 -> Query commons schemas params row
1096− -> Expression commons schemas params grp from (nullity 'PGbool)
1070+ -> Expression grp commons schemas params from (nullity 'PGbool)
1097unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1071unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1098 renderSQL (row xs) <+> op <+> parenthesized (renderSQL q)
1072 renderSQL (row xs) <+> op <+> parenthesized (renderSQL q)
1099
1073
@@ -1106,9 +1080,9 @@ unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1106-- >>> printSQL $ true `in_` values_ (true `as` #foo)
1080-- >>> printSQL $ true `in_` values_ (true `as` #foo)
1107-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1081-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1108in_
1082in_
1109− :: Expression commons schemas params grp from ty -- ^ expression
1083+ :: Expression grp commons schemas params from ty -- ^ expression
1110 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1084 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1111− -> Expression commons schemas params grp from (nullity 'PGbool)
1085+ -> Expression grp commons schemas params from (nullity 'PGbool)
1112in_ = unsafeSubqueryExpression "IN"
1086in_ = unsafeSubqueryExpression "IN"
1113
1087
1114{- | The left-hand side of this form of `rowIn` is a row constructor.
1088{- | The left-hand side of this form of `rowIn` is a row constructor.
@@ -1121,231 +1095,231 @@ is `true` if any equal subquery row is found.
1121The result is `false` if no equal row is found
1095The result is `false` if no equal row is found
1122(including the case where the subquery returns no rows).
1096(including the case where the subquery returns no rows).
1123
1097
1124−>>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1098+>>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1125>>> printSQL $ myRow `rowIn` values_ myRow
1099>>> printSQL $ myRow `rowIn` values_ myRow
1126ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1100ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1127-}
1101-}
1128rowIn
1102rowIn
1129 :: SListI row
1103 :: SListI row
1130− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1104+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1131 -> Query commons schemas params row -- ^ subquery
1105 -> Query commons schemas params row -- ^ subquery
1132− -> Expression commons schemas params grp from (nullity 'PGbool)
1106+ -> Expression grp commons schemas params from (nullity 'PGbool)
1133rowIn = unsafeRowSubqueryExpression "IN"
1107rowIn = unsafeRowSubqueryExpression "IN"
1134
1108
1135-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
1109-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
1136-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1110-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1137eqAll
1111eqAll
1138− :: Expression commons schemas params grp from ty -- ^ expression
1112+ :: Expression grp commons schemas params from ty -- ^ expression
1139 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1113 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1140− -> Expression commons schemas params grp from (nullity 'PGbool)
1114+ -> Expression grp commons schemas params from (nullity 'PGbool)
1141eqAll = unsafeSubqueryExpression "= ALL"
1115eqAll = unsafeSubqueryExpression "= ALL"
1142
1116
1143−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1117+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1144-- >>> printSQL $ myRow `rowEqAll` values_ myRow
1118-- >>> printSQL $ myRow `rowEqAll` values_ myRow
1145-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1119-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1146rowEqAll
1120rowEqAll
1147 :: SListI row
1121 :: SListI row
1148− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1122+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1149 -> Query commons schemas params row -- ^ subquery
1123 -> Query commons schemas params row -- ^ subquery
1150− -> Expression commons schemas params grp from (nullity 'PGbool)
1124+ -> Expression grp commons schemas params from (nullity 'PGbool)
1151rowEqAll = unsafeRowSubqueryExpression "= ALL"
1125rowEqAll = unsafeRowSubqueryExpression "= ALL"
1152
1126
1153-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
1127-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
1154-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1128-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1155eqAny
1129eqAny
1156− :: Expression commons schemas params grp from ty -- ^ expression
1130+ :: Expression grp commons schemas params from ty -- ^ expression
1157 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1131 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1158− -> Expression commons schemas params grp from (nullity 'PGbool)
1132+ -> Expression grp commons schemas params from (nullity 'PGbool)
1159eqAny = unsafeSubqueryExpression "= ANY"
1133eqAny = unsafeSubqueryExpression "= ANY"
1160
1134
1161−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1135+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1162-- >>> printSQL $ myRow `rowEqAny` values_ myRow
1136-- >>> printSQL $ myRow `rowEqAny` values_ myRow
1163-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1137-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1164rowEqAny
1138rowEqAny
1165 :: SListI row
1139 :: SListI row
1166− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1140+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1167 -> Query commons schemas params row -- ^ subquery
1141 -> Query commons schemas params row -- ^ subquery
1168− -> Expression commons schemas params grp from (nullity 'PGbool)
1142+ -> Expression grp commons schemas params from (nullity 'PGbool)
1169rowEqAny = unsafeRowSubqueryExpression "= ANY"
1143rowEqAny = unsafeRowSubqueryExpression "= ANY"
1170
1144
1171-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
1145-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
1172-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1146-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1173neqAll
1147neqAll
1174− :: Expression commons schemas params grp from ty -- ^ expression
1148+ :: Expression grp commons schemas params from ty -- ^ expression
1175 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1149 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1176− -> Expression commons schemas params grp from (nullity 'PGbool)
1150+ -> Expression grp commons schemas params from (nullity 'PGbool)
1177neqAll = unsafeSubqueryExpression "<> ALL"
1151neqAll = unsafeSubqueryExpression "<> ALL"
1178
1152
1179−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1153+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1180-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
1154-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
1181-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1155-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1182rowNeqAll
1156rowNeqAll
1183 :: SListI row
1157 :: SListI row
1184− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1158+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1185 -> Query commons schemas params row -- ^ subquery
1159 -> Query commons schemas params row -- ^ subquery
1186− -> Expression commons schemas params grp from (nullity 'PGbool)
1160+ -> Expression grp commons schemas params from (nullity 'PGbool)
1187rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1161rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1188
1162
1189-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
1163-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
1190-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1164-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1191neqAny
1165neqAny
1192− :: Expression commons schemas params grp from ty -- ^ expression
1166+ :: Expression grp commons schemas params from ty -- ^ expression
1193 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1167 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1194− -> Expression commons schemas params grp from (nullity 'PGbool)
1168+ -> Expression grp commons schemas params from (nullity 'PGbool)
1195neqAny = unsafeSubqueryExpression "<> ANY"
1169neqAny = unsafeSubqueryExpression "<> ANY"
1196
1170
1197−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1171+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1198-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
1172-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
1199-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1173-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1200rowNeqAny
1174rowNeqAny
1201 :: SListI row
1175 :: SListI row
1202− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1176+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1203 -> Query commons schemas params row -- ^ subquery
1177 -> Query commons schemas params row -- ^ subquery
1204− -> Expression commons schemas params grp from (nullity 'PGbool)
1178+ -> Expression grp commons schemas params from (nullity 'PGbool)
1205rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1179rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1206
1180
1207-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
1181-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
1208-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1182-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1209allLt
1183allLt
1210− :: Expression commons schemas params grp from ty -- ^ expression
1184+ :: Expression grp commons schemas params from ty -- ^ expression
1211 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1185 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1212− -> Expression commons schemas params grp from (nullity 'PGbool)
1186+ -> Expression grp commons schemas params from (nullity 'PGbool)
1213allLt = unsafeSubqueryExpression "ALL <"
1187allLt = unsafeSubqueryExpression "ALL <"
1214
1188
1215−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1189+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1216-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1190-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1217-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1191-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1218rowLtAll
1192rowLtAll
1219 :: SListI row
1193 :: SListI row
1220− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1194+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1221 -> Query commons schemas params row -- ^ subquery
1195 -> Query commons schemas params row -- ^ subquery
1222− -> Expression commons schemas params grp from (nullity 'PGbool)
1196+ -> Expression grp commons schemas params from (nullity 'PGbool)
1223rowLtAll = unsafeRowSubqueryExpression "ALL <"
1197rowLtAll = unsafeRowSubqueryExpression "ALL <"
1224
1198
1225-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
1199-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
1226-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1200-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1227ltAny
1201ltAny
1228− :: Expression commons schemas params grp from ty -- ^ expression
1202+ :: Expression grp commons schemas params from ty -- ^ expression
1229 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1203 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1230− -> Expression commons schemas params grp from (nullity 'PGbool)
1204+ -> Expression grp commons schemas params from (nullity 'PGbool)
1231ltAny = unsafeSubqueryExpression "ANY <"
1205ltAny = unsafeSubqueryExpression "ANY <"
1232
1206
1233−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1207+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1234-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1208-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1235-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1209-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1236rowLtAny
1210rowLtAny
1237 :: SListI row
1211 :: SListI row
1238− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1212+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1239 -> Query commons schemas params row -- ^ subquery
1213 -> Query commons schemas params row -- ^ subquery
1240− -> Expression commons schemas params grp from (nullity 'PGbool)
1214+ -> Expression grp commons schemas params from (nullity 'PGbool)
1241rowLtAny = unsafeRowSubqueryExpression "ANY <"
1215rowLtAny = unsafeRowSubqueryExpression "ANY <"
1242
1216
1243-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
1217-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
1244-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1218-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1245lteAll
1219lteAll
1246− :: Expression commons schemas params grp from ty -- ^ expression
1220+ :: Expression grp commons schemas params from ty -- ^ expression
1247 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1221 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1248− -> Expression commons schemas params grp from (nullity 'PGbool)
1222+ -> Expression grp commons schemas params from (nullity 'PGbool)
1249lteAll = unsafeSubqueryExpression "<= ALL"
1223lteAll = unsafeSubqueryExpression "<= ALL"
1250
1224
1251−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1225+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1252-- >>> printSQL $ myRow `rowLteAll` values_ myRow
1226-- >>> printSQL $ myRow `rowLteAll` values_ myRow
1253-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1227-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1254rowLteAll
1228rowLteAll
1255 :: SListI row
1229 :: SListI row
1256− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1230+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1257 -> Query commons schemas params row -- ^ subquery
1231 -> Query commons schemas params row -- ^ subquery
1258− -> Expression commons schemas params grp from (nullity 'PGbool)
1232+ -> Expression grp commons schemas params from (nullity 'PGbool)
1259rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1233rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1260
1234
1261-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
1235-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
1262-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1236-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1263lteAny
1237lteAny
1264− :: Expression commons schemas params grp from ty -- ^ expression
1238+ :: Expression grp commons schemas params from ty -- ^ expression
1265 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1239 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1266− -> Expression commons schemas params grp from (nullity 'PGbool)
1240+ -> Expression grp commons schemas params from (nullity 'PGbool)
1267lteAny = unsafeSubqueryExpression "<= ANY"
1241lteAny = unsafeSubqueryExpression "<= ANY"
1268
1242
1269−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1243+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1270-- >>> printSQL $ myRow `rowLteAny` values_ myRow
1244-- >>> printSQL $ myRow `rowLteAny` values_ myRow
1271-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1245-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1272rowLteAny
1246rowLteAny
1273 :: SListI row
1247 :: SListI row
1274− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1248+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1275 -> Query commons schemas params row -- ^ subquery
1249 -> Query commons schemas params row -- ^ subquery
1276− -> Expression commons schemas params grp from (nullity 'PGbool)
1250+ -> Expression grp commons schemas params from (nullity 'PGbool)
1277rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1251rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1278
1252
1279-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
1253-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
1280-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1254-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1281gtAll
1255gtAll
1282− :: Expression commons schemas params grp from ty -- ^ expression
1256+ :: Expression grp commons schemas params from ty -- ^ expression
1283 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1257 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1284− -> Expression commons schemas params grp from (nullity 'PGbool)
1258+ -> Expression grp commons schemas params from (nullity 'PGbool)
1285gtAll = unsafeSubqueryExpression "> ALL"
1259gtAll = unsafeSubqueryExpression "> ALL"
1286
1260
1287−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1261+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1288-- >>> printSQL $ myRow `rowGtAll` values_ myRow
1262-- >>> printSQL $ myRow `rowGtAll` values_ myRow
1289-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1263-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1290rowGtAll
1264rowGtAll
1291 :: SListI row
1265 :: SListI row
1292− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1266+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1293 -> Query commons schemas params row -- ^ subquery
1267 -> Query commons schemas params row -- ^ subquery
1294− -> Expression commons schemas params grp from (nullity 'PGbool)
1268+ -> Expression grp commons schemas params from (nullity 'PGbool)
1295rowGtAll = unsafeRowSubqueryExpression "> ALL"
1269rowGtAll = unsafeRowSubqueryExpression "> ALL"
1296
1270
1297-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
1271-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
1298-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1272-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1299gtAny
1273gtAny
1300− :: Expression commons schemas params grp from ty -- ^ expression
1274+ :: Expression grp commons schemas params from ty -- ^ expression
1301 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1275 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1302− -> Expression commons schemas params grp from (nullity 'PGbool)
1276+ -> Expression grp commons schemas params from (nullity 'PGbool)
1303gtAny = unsafeSubqueryExpression "> ANY"
1277gtAny = unsafeSubqueryExpression "> ANY"
1304
1278
1305−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1279+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1306-- >>> printSQL $ myRow `rowGtAny` values_ myRow
1280-- >>> printSQL $ myRow `rowGtAny` values_ myRow
1307-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1281-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1308rowGtAny
1282rowGtAny
1309 :: SListI row
1283 :: SListI row
1310− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1284+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1311 -> Query commons schemas params row -- ^ subquery
1285 -> Query commons schemas params row -- ^ subquery
1312− -> Expression commons schemas params grp from (nullity 'PGbool)
1286+ -> Expression grp commons schemas params from (nullity 'PGbool)
1313rowGtAny = unsafeRowSubqueryExpression "> ANY"
1287rowGtAny = unsafeRowSubqueryExpression "> ANY"
1314
1288
1315-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
1289-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
1316-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1290-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1317gteAll
1291gteAll
1318− :: Expression commons schemas params grp from ty -- ^ expression
1292+ :: Expression grp commons schemas params from ty -- ^ expression
1319 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1293 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1320− -> Expression commons schemas params grp from (nullity 'PGbool)
1294+ -> Expression grp commons schemas params from (nullity 'PGbool)
1321gteAll = unsafeSubqueryExpression ">= ALL"
1295gteAll = unsafeSubqueryExpression ">= ALL"
1322
1296
1323−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1297+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1324-- >>> printSQL $ myRow `rowGteAll` values_ myRow
1298-- >>> printSQL $ myRow `rowGteAll` values_ myRow
1325-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1299-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1326rowGteAll
1300rowGteAll
1327 :: SListI row
1301 :: SListI row
1328− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1302+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1329 -> Query commons schemas params row -- ^ subquery
1303 -> Query commons schemas params row -- ^ subquery
1330− -> Expression commons schemas params grp from (nullity 'PGbool)
1304+ -> Expression grp commons schemas params from (nullity 'PGbool)
1331rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1305rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1332
1306
1333-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
1307-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
1334-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1308-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1335gteAny
1309gteAny
1336− :: Expression commons schemas params grp from ty -- ^ expression
1310+ :: Expression grp commons schemas params from ty -- ^ expression
1337 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1311 -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1338− -> Expression commons schemas params grp from (nullity 'PGbool)
1312+ -> Expression grp commons schemas params from (nullity 'PGbool)
1339gteAny = unsafeSubqueryExpression ">= ANY"
1313gteAny = unsafeSubqueryExpression ">= ANY"
1340
1314
1341−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1315+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1342-- >>> printSQL $ myRow `rowGteAny` values_ myRow
1316-- >>> printSQL $ myRow `rowGteAny` values_ myRow
1343-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1317-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1344rowGteAny
1318rowGteAny
1345 :: SListI row
1319 :: SListI row
1346− => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1320+ => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1347 -> Query commons schemas params row -- ^ subquery
1321 -> Query commons schemas params row -- ^ subquery
1348− -> Expression commons schemas params grp from (nullity 'PGbool)
1322+ -> Expression grp commons schemas params from (nullity 'PGbool)
1349rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1323rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1350
1324
1351-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1325-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.