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