on dev help sign in
correlated subquery scoping
commit3d6ddf84097a5094e372ac3e9127ce50302cbb45 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateWed 20 Feb 2019, 10:35 (8 years ago) parent0a95a9d
7 files changed+636−633
squeal-postgresql/exe/Example.hs+4−8 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+4−4 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+348−346 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+17−17 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+2−2 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+260−255
squeal-postgresql/exe/Example.hs+4−8
@@ -44,7 +44,7 @@ type Schema =
4444type Schemas = Public Schema
4545
4646setup :: Definition (Public '[]) Schemas
47−setup =
47+setup =
4848 createTable #users
4949 ( serial `as` #id :*
5050 (text & notNullable) `as` #name :*
@@ -62,20 +62,16 @@ setup =
6262teardown :: Definition Schemas (Public '[])
6363teardown = dropTable #emails >>> dropTable #users
6464
65−insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
66− '[ "fromOnly" ::: 'NotNull 'PGint4 ]
65+insertUser :: Manipulation_ Schemas (Text, VarArray (Vector (Maybe Int16))) (Only Int32)
6766insertUser = insertInto #users
6867 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))
6968 (OnConflict (OnConstraint #pk_users) DoNothing) (Returning_ (#id `as` #fromOnly))
7069
71−insertEmail :: Manipulation '[] Schemas '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
70+insertEmail :: Manipulation_ Schemas (Int32, Maybe Text) ()
7271insertEmail = insertInto_ #emails
7372 (Values_ (defaultAs #id :* param @1 `as` #user_id :* param @2 `as` #email))
7473
75−getUsers :: Query '[] Schemas '[]
76− '[ "userName" ::: 'NotNull 'PGtext
77− , "userEmail" ::: 'Null 'PGtext
78− , "userVec" ::: 'NotNull ('PGvararray ('Null 'PGint2))]
74+getUsers :: Query_ Schemas () User
7975getUsers = select_
8076 (#u ! #name `as` #userName :* #e ! #email `as` #userEmail :* #u ! #vec `as` #userVec)
8177 ( from (table (#users `as` #u)
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+4−4
@@ -297,7 +297,7 @@ check
297297 , HasAll aliases (TableToRow table) subcolumns )
298298 => NP Alias aliases
299299 -- ^ specify the subcolumns which are getting checked
300− -> (forall t. Condition 'Ungrouped '[] schemas '[] '[t ::: subcolumns])
300+ -> (forall t. Condition '[] 'Ungrouped '[] schemas '[] '[t ::: subcolumns])
301301 -- ^ a closed `Condition` on those subcolumns
302302 -> TableConstraintExpression sch tab schemas ('Check aliases)
303303check _cols condition = UnsafeTableConstraintExpression $
@@ -772,7 +772,7 @@ newtype AlterColumn (schemas :: SchemasType) (ty0 :: ColumnType) (ty1 :: ColumnT
772772-- :}
773773-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
774774setDefault
775− :: Expression 'Ungrouped '[] schemas '[] '[] ty -- ^ default value to set
775+ :: Expression '[] 'Ungrouped '[] schemas '[] '[] ty -- ^ default value to set
776776 -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
777777setDefault expression = UnsafeAlterColumn $
778778 "SET DEFAULT" <+> renderExpression expression
@@ -857,7 +857,7 @@ CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
857857createView
858858 :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
859859 => QualifiedAlias sch vw -- ^ the name of the view to add
860− -> Query '[] schemas '[] view -- ^ query
860+ -> Query '[] '[] schemas '[] view -- ^ query
861861 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
862862createView alias query = UnsafeDefinition $
863863 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
@@ -1023,7 +1023,7 @@ notNullable ty = UnsafeColumnTypeExpression $ renderSQL ty <+> "NOT NULL"
10231023
10241024-- | used in `createTable` commands as a column constraint to give a default
10251025default_
1026− :: Expression 'Ungrouped '[] schemas '[] '[] ty
1026+ :: Expression '[] 'Ungrouped '[] schemas '[] '[] ty
10271027 -> ColumnTypeExpression schemas ('NoDef :=> ty)
10281028 -> ColumnTypeExpression schemas ('Def :=> ty)
10291029default_ x ty = UnsafeColumnTypeExpression $
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+348−346
@@ -237,6 +237,7 @@ values from primitive expression using arithmetic, logical,
237237and other operations.
238238-}
239239newtype Expression
240+ (outer :: FromType)
240241 (grp :: Grouping)
241242 (commons :: FromType)
242243 (schemas :: SchemasType)
@@ -246,7 +247,7 @@ newtype Expression
246247 = UnsafeExpression { renderExpression :: ByteString }
247248 deriving (GHC.Generic,Show,Eq,Ord,NFData)
248249
249−instance RenderSQL (Expression grp commons schemas params from ty) where
250+instance RenderSQL (Expression outer grp commons schemas params from ty) where
250251 renderSQL = renderExpression
251252
252253{- | A `HasParameter` constraint is used to indicate a value that is
@@ -264,12 +265,12 @@ class KnownNat n => HasParameter
264265 | n params -> ty where
265266 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
266267 --
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)
268269 -- >>> printSQL expr
269270 -- ($1 :: int4)
270271 parameter
271272 :: TypeExpression schemas ty
272− -> Expression grp commons schemas params from ty
273+ -> Expression outer grp commons schemas params from ty
273274 parameter ty = UnsafeExpression $ parenthesized $
274275 "$" <> renderNat @n <+> "::"
275276 <+> renderSQL ty
@@ -280,116 +281,116 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
280281-- | `param` takes a `Nat` using type application and for basic types,
281282-- infers a `TypeExpression`.
282283--
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)
284285-- >>> printSQL expr
285286-- ($1 :: int4)
286287param
287− :: forall n commons schemas params from grp ty
288+ :: forall n outer commons schemas params from grp ty
288289 . (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
290291param = parameter @n (pgtype @schemas)
291292
292−instance (HasUnique tab from row, Has col row ty)
293− => IsLabel col (Expression 'Ungrouped commons schemas params from ty) where
293+instance (HasUnique tab (Join outer from) row, Has col row ty)
294+ => IsLabel col (Expression outer 'Ungrouped commons schemas params from ty) where
294295 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
295−instance (HasUnique tab from row, Has col row ty, tys ~ '[ty])
296− => IsLabel col (NP (Expression 'Ungrouped commons schemas params from) tys) where
296+instance (HasUnique tab (Join outer from) row, Has col row ty, tys ~ '[ty])
297+ => IsLabel col (NP (Expression outer 'Ungrouped commons schemas params from) tys) where
297298 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))
299300 => IsLabel col
300− (Aliased (Expression 'Ungrouped commons schemas params from) column) where
301+ (Aliased (Expression outer 'Ungrouped commons schemas params from) column) where
301302 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])
303304 => 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
305306 fromLabel = fromLabel @col :* Nil
306307
307−instance (Has tab from row, Has col row ty)
308− => IsQualified tab col (Expression 'Ungrouped commons schemas params from ty) where
308+instance (Has tab (Join outer from) row, Has col row ty)
309+ => IsQualified tab col (Expression outer 'Ungrouped commons schemas params from ty) where
309310 tab ! col = UnsafeExpression $
310311 renderSQL tab <> "." <> renderSQL col
311−instance (Has tab from row, Has col row ty, tys ~ '[ty])
312− => IsQualified tab col (NP (Expression 'Ungrouped commons schemas params from) tys) where
312+instance (Has tab (Join outer from) row, Has col row ty, tys ~ '[ty])
313+ => IsQualified tab col (NP (Expression outer 'Ungrouped commons schemas params from) tys) where
313314 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))
315316 => IsQualified tab col
316− (Aliased (Expression 'Ungrouped commons schemas params from) column) where
317+ (Aliased (Expression outer 'Ungrouped commons schemas params from) column) where
317318 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])
319320 => 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
321322 tab ! col = tab ! col :* Nil
322323
323324instance
324− ( HasUnique tab from row
325+ ( HasUnique tab (Join outer from) row
325326 , Has col row ty
326327 , GroupedBy tab col bys
327328 ) => IsLabel col
328− (Expression ('Grouped bys) commons schemas params from ty) where
329+ (Expression outer ('Grouped bys) commons schemas params from ty) where
329330 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
330331instance
331− ( HasUnique tab from row
332+ ( HasUnique tab (Join outer from) row
332333 , Has col row ty
333334 , GroupedBy tab col bys
334335 , tys ~ '[ty]
335336 ) => 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
337338 fromLabel = fromLabel @col :* Nil
338339instance
339− ( HasUnique tab from row
340+ ( HasUnique tab (Join outer from) row
340341 , Has col row ty
341342 , GroupedBy tab col bys
342343 , column ~ (col ::: ty)
343344 ) => 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
345346 fromLabel = fromLabel @col `As` Alias
346347instance
347− ( HasUnique tab from row
348+ ( HasUnique tab (Join outer from) row
348349 , Has col row ty
349350 , GroupedBy tab col bys
350351 , columns ~ '[col ::: ty]
351352 ) => 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
353354 fromLabel = fromLabel @col :* Nil
354355
355356instance
356− ( Has tab from row
357+ ( Has tab (Join outer from) row
357358 , Has col row ty
358359 , GroupedBy tab col bys
359360 ) => IsQualified tab col
360− (Expression ('Grouped bys) commons schemas params from ty) where
361+ (Expression outer ('Grouped bys) commons schemas params from ty) where
361362 tab ! col = UnsafeExpression $
362363 renderSQL tab <> "." <> renderSQL col
363364instance
364− ( Has tab from row
365+ ( Has tab (Join outer from) row
365366 , Has col row ty
366367 , GroupedBy tab col bys
367368 , tys ~ '[ty]
368369 ) => 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
370371 tab ! col = tab ! col :* Nil
371372instance
372− ( Has tab from row
373+ ( Has tab (Join outer from) row
373374 , Has col row ty
374375 , GroupedBy tab col bys
375376 , column ~ (col ::: ty)
376377 ) => 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
378379 tab ! col = tab ! col `As` col
379380instance
380− ( Has tab from row
381+ ( Has tab (Join outer from) row
381382 , Has col row ty
382383 , GroupedBy tab col bys
383384 , columns ~ '[col ::: ty]
384385 ) => 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
386387 tab ! col = tab ! col :* Nil
387388
388389-- | analagous to `Nothing`
389390--
390391-- >>> printSQL null_
391392-- NULL
392−null_ :: Expression commons schemas rels grouping params ('Null ty)
393+null_ :: Expression outer grp commons schemas params from ('Null ty)
393394null_ = UnsafeExpression "NULL"
394395
395396-- | analagous to `Just`
@@ -397,8 +398,8 @@ null_ = UnsafeExpression "NULL"
397398-- >>> printSQL $ notNull true
398399-- TRUE
399400notNull
400− :: Expression commons schemas rels grouping params ('NotNull ty)
401− -> Expression commons schemas rels grouping params ('Null ty)
401+ :: Expression outer grp commons schemas params from ('NotNull ty)
402+ -> Expression outer grp commons schemas params from ('Null ty)
402403notNull = UnsafeExpression . renderSQL
403404
404405-- | return the leftmost value which is not NULL
@@ -406,11 +407,11 @@ notNull = UnsafeExpression . renderSQL
406407-- >>> printSQL $ coalesce [null_, true] false
407408-- COALESCE(NULL, TRUE, FALSE)
408409coalesce
409− :: [Expression grp commons schemas params from ('Null ty)]
410+ :: [Expression outer grp commons schemas params from ('Null ty)]
410411 -- ^ @NULL@s may be present
411− -> Expression grp commons schemas params from ('NotNull ty)
412+ -> Expression outer grp commons schemas params from ('NotNull ty)
412413 -- ^ @NULL@ is absent
413− -> Expression grp commons schemas params from ('NotNull ty)
414+ -> Expression outer grp commons schemas params from ('NotNull ty)
414415coalesce nullxs notNullx = UnsafeExpression $
415416 "COALESCE" <> parenthesized (commaSeparated
416417 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
@@ -420,26 +421,26 @@ coalesce nullxs notNullx = UnsafeExpression $
420421-- >>> printSQL $ fromNull true null_
421422-- COALESCE(NULL, TRUE)
422423fromNull
423− :: Expression grp commons schemas params from ('NotNull ty)
424+ :: Expression outer grp commons schemas params from ('NotNull ty)
424425 -- ^ what to convert @NULL@ to
425− -> Expression grp commons schemas params from ('Null ty)
426− -> Expression grp commons schemas params from ('NotNull ty)
426+ -> Expression outer grp commons schemas params from ('Null ty)
427+ -> Expression outer grp commons schemas params from ('NotNull ty)
427428fromNull notNullx nullx = coalesce [nullx] notNullx
428429
429430-- | >>> printSQL $ null_ & isNull
430431-- NULL IS NULL
431432isNull
432− :: Expression grp commons schemas params from ('Null ty)
433+ :: Expression outer grp commons schemas params from ('Null ty)
433434 -- ^ possibly @NULL@
434− -> Condition grp commons schemas params from
435+ -> Condition outer grp commons schemas params from
435436isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
436437
437438-- | >>> printSQL $ null_ & isNotNull
438439-- NULL IS NOT NULL
439440isNotNull
440− :: Expression grp commons schemas params from ('Null ty)
441+ :: Expression outer grp commons schemas params from ('Null ty)
441442 -- ^ possibly @NULL@
442− -> Condition grp commons schemas params from
443+ -> Condition outer grp commons schemas params from
443444isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
444445
445446-- | analagous to `maybe` using @IS NULL@
@@ -447,13 +448,13 @@ isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
447448-- >>> printSQL $ matchNull true not_ null_
448449-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
449450matchNull
450− :: Expression grp commons schemas params from (nullty)
451+ :: Expression outer grp commons schemas params from (nullty)
451452 -- ^ what to convert @NULL@ to
452− -> ( Expression grp commons schemas params from ('NotNull ty)
453− -> Expression grp commons schemas params from (nullty) )
453+ -> ( Expression outer grp commons schemas params from ('NotNull ty)
454+ -> Expression outer grp commons schemas params from (nullty) )
454455 -- ^ function to perform when @NULL@ is absent
455− -> Expression grp commons schemas params from ('Null ty)
456− -> Expression grp commons schemas params from (nullty)
456+ -> Expression outer grp commons schemas params from ('Null ty)
457+ -> Expression outer grp commons schemas params from (nullty)
457458matchNull y f x = ifThenElse (isNull x) y
458459 (f (UnsafeExpression (renderSQL x)))
459460
@@ -461,25 +462,25 @@ matchNull y f x = ifThenElse (isNull x) y
461462`nullIf` gives @NULL@.
462463
463464>>> :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)
465466>>> printSQL expr
466467NULL IF (FALSE, ($1 :: bool))
467468-}
468469nullIf
469− :: Expression grp commons schemas params from ('NotNull ty)
470+ :: Expression outer grp commons schemas params from ('NotNull ty)
470471 -- ^ @NULL@ is absent
471− -> Expression grp commons schemas params from ('NotNull ty)
472+ -> Expression outer grp commons schemas params from ('NotNull ty)
472473 -- ^ @NULL@ is absent
473− -> Expression grp commons schemas params from ('Null ty)
474+ -> Expression outer grp commons schemas params from ('Null ty)
474475nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
475476 (renderSQL x <> ", " <> renderSQL y)
476477
477478-- | >>> printSQL $ array [null_, false, true]
478479-- ARRAY[NULL, FALSE, TRUE]
479480array
480− :: [Expression grp commons schemas params from ty]
481+ :: [Expression outer grp commons schemas params from ty]
481482 -- ^ array elements
482− -> Expression grp commons schemas params from (nullity ('PGvararray ty))
483+ -> Expression outer grp commons schemas params from (nullity ('PGvararray ty))
483484array xs = UnsafeExpression $
484485 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
485486
@@ -487,13 +488,13 @@ array xs = UnsafeExpression $
487488-- (ARRAY[NULL, FALSE, TRUE])[2]
488489index
489490 :: Word64 -- ^ index
490− -> Expression grp commons schemas params from (nullity ('PGvararray ty)) -- ^ array
491− -> Expression grp commons schemas params from (NullifyType ty)
491+ -> Expression outer grp commons schemas params from (nullity ('PGvararray ty)) -- ^ array
492+ -> Expression outer grp commons schemas params from (NullifyType ty)
492493index n expr = UnsafeExpression $
493494 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
494495
495496instance (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
497498 label = UnsafeExpression $ renderSQL (PGlabel @label)
498499
499500-- | A row constructor is an expression that builds a row value
@@ -505,14 +506,14 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
505506-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
506507-- :}
507508--
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)
509510-- >>> printSQL i
510511-- ROW(0, 1)
511512row
512513 :: SListI row
513− => NP (Aliased (Expression grp commons schemas params from)) row
514+ => NP (Aliased (Expression outer grp commons schemas params from)) row
514515 -- ^ 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))
516517row exprs = UnsafeExpression $ "ROW" <> parenthesized
517518 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
518519
@@ -523,7 +524,7 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
523524-- type Schema = '["complex" ::: 'Typedef Complex]
524525-- :}
525526--
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)
527528-- >>> printSQL $ i & field #complex #imaginary
528529-- (ROW(0, 1)::"complex")."imaginary"
529530field
@@ -532,41 +533,41 @@ field
532533 , Has field row ty)
533534 => QualifiedAlias sch tydef -- ^ row type
534535 -> Alias field -- ^ field name
535− -> Expression grp commons schemas params from ('NotNull ('PGcomposite row))
536− -> Expression grp commons schemas params from ty
536+ -> Expression outer grp commons schemas params from ('NotNull ('PGcomposite row))
537+ -> Expression outer grp commons schemas params from ty
537538field td fld expr = UnsafeExpression $
538539 parenthesized (renderSQL expr <> "::" <> renderSQL td)
539540 <> "." <> renderSQL fld
540541
541542instance Semigroup
542− (Expression grp commons schemas params from (nullity ('PGvararray ty))) where
543+ (Expression outer grp commons schemas params from (nullity ('PGvararray ty))) where
543544 (<>) = unsafeBinaryOp "||"
544545
545546instance Monoid
546− (Expression grp commons schemas params from (nullity ('PGvararray ty))) where
547+ (Expression outer grp commons schemas params from (nullity ('PGvararray ty))) where
547548 mempty = array []
548549 mappend = (<>)
549550
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)
551552-- >>> printSQL expr
552553-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
553554greatest
554− :: Expression grp commons schemas params from (nullty)
555+ :: Expression outer grp commons schemas params from (nullty)
555556 -- ^ needs at least 1 argument
556− -> [Expression grp commons schemas params from (nullty)]
557+ -> [Expression outer grp commons schemas params from (nullty)]
557558 -- ^ or more
558− -> Expression grp commons schemas params from (nullty)
559+ -> Expression outer grp commons schemas params from (nullty)
559560greatest x xs = UnsafeExpression $ "GREATEST("
560561 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
561562
562563-- | >>> printSQL $ least currentTimestamp [null_]
563564-- LEAST(CURRENT_TIMESTAMP, NULL)
564565least
565− :: Expression grp commons schemas params from (nullty)
566+ :: Expression outer grp commons schemas params from (nullty)
566567 -- ^ needs at least 1 argument
567− -> [Expression grp commons schemas params from (nullty)]
568+ -> [Expression outer grp commons schemas params from (nullty)]
568569 -- ^ or more
569− -> Expression grp commons schemas params from (nullty)
570+ -> Expression outer grp commons schemas params from (nullty)
570571least x xs = UnsafeExpression $ "LEAST("
571572 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
572573
@@ -575,9 +576,9 @@ least x xs = UnsafeExpression $ "LEAST("
575576unsafeBinaryOp
576577 :: ByteString
577578 -- ^ operator
578− -> Expression grp commons schemas params from (ty0)
579− -> Expression grp commons schemas params from (ty1)
580− -> Expression grp commons schemas params from (ty2)
579+ -> Expression outer grp commons schemas params from (ty0)
580+ -> Expression outer grp commons schemas params from (ty1)
581+ -> Expression outer grp commons schemas params from (ty2)
581582unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
582583 renderSQL x <+> op <+> renderSQL y
583584
@@ -586,8 +587,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
586587unsafeUnaryOp
587588 :: ByteString
588589 -- ^ operator
589− -> Expression grp commons schemas params from (ty0)
590− -> Expression grp commons schemas params from (ty1)
590+ -> Expression outer grp commons schemas params from (ty0)
591+ -> Expression outer grp commons schemas params from (ty1)
591592unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
592593 op <+> renderSQL x
593594
@@ -596,8 +597,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
596597unsafeFunction
597598 :: ByteString
598599 -- ^ function
599− -> Expression grp commons schemas params from (xty)
600− -> Expression grp commons schemas params from (yty)
600+ -> Expression outer grp commons schemas params from (xty)
601+ -> Expression outer grp commons schemas params from (yty)
601602unsafeFunction fun x = UnsafeExpression $
602603 fun <> parenthesized (renderSQL x)
603604
@@ -606,13 +607,13 @@ unsafeVariadicFunction
606607 :: SListI elems
607608 => ByteString
608609 -- ^ function
609− -> NP (Expression grp commons schemas params from) elems
610− -> Expression grp commons schemas params from ret
610+ -> NP (Expression outer grp commons schemas params from) elems
611+ -> Expression outer grp commons schemas params from ret
611612unsafeVariadicFunction fun x = UnsafeExpression $
612613 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
613614
614615instance 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
616617 (+) = unsafeBinaryOp "+"
617618 (-) = unsafeBinaryOp "-"
618619 (*) = unsafeBinaryOp "*"
@@ -624,12 +625,12 @@ instance ty `In` PGNum
624625 . show
625626
626627instance (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
628629 (/) = unsafeBinaryOp "/"
629630 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
630631
631632instance (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
633634 pi = UnsafeExpression "pi()"
634635 exp = unsafeFunction "exp"
635636 log = unsafeFunction "ln"
@@ -652,18 +653,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
652653
653654-- | >>> :{
654655-- let
655−-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
656+-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
656657-- expression = atan2_ pi 2
657658-- in printSQL expression
658659-- :}
659660-- atan2(pi(), 2)
660661atan2_
661662 :: float `In` PGFloating
662− => Expression grp commons schemas params from (nullity float)
663+ => Expression outer grp commons schemas params from (nullity float)
663664 -- ^ numerator
664− -> Expression grp commons schemas params from (nullity float)
665+ -> Expression outer grp commons schemas params from (nullity float)
665666 -- ^ denominator
666− -> Expression grp commons schemas params from (nullity float)
667+ -> Expression outer grp commons schemas params from (nullity float)
667668atan2_ y x = UnsafeExpression $
668669 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
669670
@@ -676,9 +677,9 @@ atan2_ y x = UnsafeExpression $
676677cast
677678 :: TypeExpression schemas ty1
678679 -- ^ type to cast as
679− -> Expression grp commons schemas params from ty0
680+ -> Expression outer grp commons schemas params from ty0
680681 -- ^ value to convert
681− -> Expression grp commons schemas params from ty1
682+ -> Expression outer grp commons schemas params from ty1
682683cast ty x = UnsafeExpression $ parenthesized $
683684 renderSQL x <+> "::" <+> renderSQL ty
684685
@@ -686,136 +687,136 @@ cast ty x = UnsafeExpression $ parenthesized $
686687--
687688-- >>> :{
688689-- let
689−-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
690+-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
690691-- expression = 5 `quot_` 2
691692-- in printSQL expression
692693-- :}
693694-- (5 / 2)
694695quot_
695696 :: int `In` PGIntegral
696− => Expression grp commons schemas params from (nullity int)
697+ => Expression outer grp commons schemas params from (nullity int)
697698 -- ^ numerator
698− -> Expression grp commons schemas params from (nullity int)
699+ -> Expression outer grp commons schemas params from (nullity int)
699700 -- ^ denominator
700− -> Expression grp commons schemas params from (nullity int)
701+ -> Expression outer grp commons schemas params from (nullity int)
701702quot_ = unsafeBinaryOp "/"
702703
703704-- | remainder upon integer division
704705--
705706-- >>> :{
706707-- let
707−-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
708+-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
708709-- expression = 5 `rem_` 2
709710-- in printSQL expression
710711-- :}
711712-- (5 % 2)
712713rem_
713714 :: int `In` PGIntegral
714− => Expression grp commons schemas params from (nullity int)
715+ => Expression outer grp commons schemas params from (nullity int)
715716 -- ^ numerator
716− -> Expression grp commons schemas params from (nullity int)
717+ -> Expression outer grp commons schemas params from (nullity int)
717718 -- ^ denominator
718− -> Expression grp commons schemas params from (nullity int)
719+ -> Expression outer grp commons schemas params from (nullity int)
719720rem_ = unsafeBinaryOp "%"
720721
721722-- | >>> :{
722723-- let
723−-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
724+-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
724725-- expression = trunc pi
725726-- in printSQL expression
726727-- :}
727728-- trunc(pi())
728729trunc
729730 :: frac `In` PGFloating
730− => Expression grp commons schemas params from (nullity frac)
731+ => Expression outer grp commons schemas params from (nullity frac)
731732 -- ^ fractional number
732− -> Expression grp commons schemas params from (nullity frac)
733+ -> Expression outer grp commons schemas params from (nullity frac)
733734trunc = unsafeFunction "trunc"
734735
735736-- | >>> :{
736737-- let
737−-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
738+-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
738739-- expression = round_ pi
739740-- in printSQL expression
740741-- :}
741742-- round(pi())
742743round_
743744 :: frac `In` PGFloating
744− => Expression grp commons schemas params from (nullity frac)
745+ => Expression outer grp commons schemas params from (nullity frac)
745746 -- ^ fractional number
746− -> Expression grp commons schemas params from (nullity frac)
747+ -> Expression outer grp commons schemas params from (nullity frac)
747748round_ = unsafeFunction "round"
748749
749750-- | >>> :{
750751-- let
751−-- expression :: Expression grp commons schemas params from (nullity 'PGfloat4)
752+-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
752753-- expression = ceiling_ pi
753754-- in printSQL expression
754755-- :}
755756-- ceiling(pi())
756757ceiling_
757758 :: frac `In` PGFloating
758− => Expression grp commons schemas params from (nullity frac)
759+ => Expression outer grp commons schemas params from (nullity frac)
759760 -- ^ fractional number
760− -> Expression grp commons schemas params from (nullity frac)
761+ -> Expression outer grp commons schemas params from (nullity frac)
761762ceiling_ = unsafeFunction "ceiling"
762763
763764-- | A `Condition` is an `Expression`, which can evaluate
764765-- to `true`, `false` or `null_`. This is because SQL uses
765766-- a three valued logic.
766−type Condition grp commons schemas params from =
767− Expression grp commons schemas params from ('Null 'PGbool)
767+type Condition outer grp commons schemas params from =
768+ Expression outer grp commons schemas params from ('Null 'PGbool)
768769
769770-- | >>> printSQL true
770771-- TRUE
771−true :: Expression grp commons schemas params from (nullity 'PGbool)
772+true :: Expression outer grp commons schemas params from (nullity 'PGbool)
772773true = UnsafeExpression "TRUE"
773774
774775-- | >>> printSQL false
775776-- FALSE
776−false :: Expression grp commons schemas params from (nullity 'PGbool)
777+false :: Expression outer grp commons schemas params from (nullity 'PGbool)
777778false = UnsafeExpression "FALSE"
778779
779780-- | >>> printSQL $ not_ true
780781-- (NOT TRUE)
781782not_
782− :: Expression grp commons schemas params from (nullity 'PGbool)
783− -> Expression grp commons schemas params from (nullity 'PGbool)
783+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
784+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
784785not_ = unsafeUnaryOp "NOT"
785786
786787-- | >>> printSQL $ true .&& false
787788-- (TRUE AND FALSE)
788789(.&&)
789− :: Expression grp commons schemas params from (nullity 'PGbool)
790− -> Expression grp commons schemas params from (nullity 'PGbool)
791− -> Expression grp commons schemas params from (nullity 'PGbool)
790+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
791+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
792+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
792793infixr 3 .&&
793794(.&&) = unsafeBinaryOp "AND"
794795
795796-- | >>> printSQL $ true .|| false
796797-- (TRUE OR FALSE)
797798(.||)
798− :: Expression grp commons schemas params from (nullity 'PGbool)
799− -> Expression grp commons schemas params from (nullity 'PGbool)
800− -> Expression grp commons schemas params from (nullity 'PGbool)
799+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
800+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
801+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
801802infixr 2 .||
802803(.||) = unsafeBinaryOp "OR"
803804
804805-- | >>> :{
805806-- let
806−-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
807+-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
807808-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
808809-- in printSQL expression
809810-- :}
810811-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
811812caseWhenThenElse
812− :: [ ( Condition grp commons schemas params from
813− , Expression grp commons schemas params from ty
813+ :: [ ( Condition outer grp commons schemas params from
814+ , Expression outer grp commons schemas params from ty
814815 ) ]
815816 -- ^ whens and thens
816− -> Expression grp commons schemas params from ty
817+ -> Expression outer grp commons schemas params from ty
817818 -- ^ else
818− -> Expression grp commons schemas params from ty
819+ -> Expression outer grp commons schemas params from ty
819820caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
820821 [ "CASE"
821822 , mconcat
@@ -831,16 +832,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
831832
832833-- | >>> :{
833834-- let
834−-- expression :: Expression grp commons schemas params from (nullity 'PGint2)
835+-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
835836-- expression = ifThenElse true 1 0
836837-- in printSQL expression
837838-- :}
838839-- CASE WHEN TRUE THEN 1 ELSE 0 END
839840ifThenElse
840− :: Condition grp commons schemas params from
841− -> Expression grp commons schemas params from ty -- ^ then
842− -> Expression grp commons schemas params from ty -- ^ else
843− -> Expression grp commons schemas params from ty
841+ :: Condition outer grp commons schemas params from
842+ -> Expression outer grp commons schemas params from ty -- ^ then
843+ -> Expression outer grp commons schemas params from ty -- ^ else
844+ -> Expression outer grp commons schemas params from ty
844845ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
845846
846847-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -849,85 +850,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
849850-- >>> printSQL $ true .== null_
850851-- (TRUE = NULL)
851852(.==)
852− :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
853− -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
854− -> Condition grp commons schemas params from
853+ :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
854+ -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
855+ -> Condition outer grp commons schemas params from
855856(.==) = unsafeBinaryOp "="
856857infix 4 .==
857858
858859-- | >>> printSQL $ true ./= null_
859860-- (TRUE <> NULL)
860861(./=)
861− :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
862− -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
863− -> Condition grp commons schemas params from
862+ :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
863+ -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
864+ -> Condition outer grp commons schemas params from
864865(./=) = unsafeBinaryOp "<>"
865866infix 4 ./=
866867
867868-- | >>> printSQL $ true .>= null_
868869-- (TRUE >= NULL)
869870(.>=)
870− :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
871− -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
872− -> Condition grp commons schemas params from
871+ :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
872+ -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
873+ -> Condition outer grp commons schemas params from
873874(.>=) = unsafeBinaryOp ">="
874875infix 4 .>=
875876
876877-- | >>> printSQL $ true .< null_
877878-- (TRUE < NULL)
878879(.<)
879− :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
880− -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
881− -> Condition grp commons schemas params from
880+ :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
881+ -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
882+ -> Condition outer grp commons schemas params from
882883(.<) = unsafeBinaryOp "<"
883884infix 4 .<
884885
885886-- | >>> printSQL $ true .<= null_
886887-- (TRUE <= NULL)
887888(.<=)
888− :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
889− -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
890− -> Condition grp commons schemas params from
889+ :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
890+ -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
891+ -> Condition outer grp commons schemas params from
891892(.<=) = unsafeBinaryOp "<="
892893infix 4 .<=
893894
894895-- | >>> printSQL $ true .> null_
895896-- (TRUE > NULL)
896897(.>)
897− :: Expression grp commons schemas params from (nullity0 ty) -- ^ lhs
898− -> Expression grp commons schemas params from (nullity1 ty) -- ^ rhs
899− -> Condition grp commons schemas params from
898+ :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
899+ -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
900+ -> Condition outer grp commons schemas params from
900901(.>) = unsafeBinaryOp ">"
901902infix 4 .>
902903
903904-- | >>> printSQL currentDate
904905-- CURRENT_DATE
905906currentDate
906− :: Expression grp commons schemas params from (nullity 'PGdate)
907+ :: Expression outer grp commons schemas params from (nullity 'PGdate)
907908currentDate = UnsafeExpression "CURRENT_DATE"
908909
909910-- | >>> printSQL currentTime
910911-- CURRENT_TIME
911912currentTime
912− :: Expression grp commons schemas params from (nullity 'PGtimetz)
913+ :: Expression outer grp commons schemas params from (nullity 'PGtimetz)
913914currentTime = UnsafeExpression "CURRENT_TIME"
914915
915916-- | >>> printSQL currentTimestamp
916917-- CURRENT_TIMESTAMP
917918currentTimestamp
918− :: Expression grp commons schemas params from (nullity 'PGtimestamptz)
919+ :: Expression outer grp commons schemas params from (nullity 'PGtimestamptz)
919920currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
920921
921922-- | >>> printSQL localTime
922923-- LOCALTIME
923924localTime
924− :: Expression grp commons schemas params from (nullity 'PGtime)
925+ :: Expression outer grp commons schemas params from (nullity 'PGtime)
925926localTime = UnsafeExpression "LOCALTIME"
926927
927928-- | >>> printSQL localTimestamp
928929-- LOCALTIMESTAMP
929930localTimestamp
930− :: Expression grp commons schemas params from (nullity 'PGtimestamp)
931+ :: Expression outer grp commons schemas params from (nullity 'PGtimestamp)
931932localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
932933
933934{-----------------------------------------
@@ -935,7 +936,7 @@ text
935936-----------------------------------------}
936937
937938instance IsString
938− (Expression grp commons schemas params from (nullity 'PGtext)) where
939+ (Expression outer grp commons schemas params from (nullity 'PGtext)) where
939940 fromString str = UnsafeExpression $
940941 "E\'" <> fromString (escape =<< str) <> "\'"
941942 where
@@ -951,36 +952,36 @@ instance IsString
951952 c -> [c]
952953
953954instance Semigroup
954− (Expression grp commons schemas params from (nullity 'PGtext)) where
955+ (Expression outer grp commons schemas params from (nullity 'PGtext)) where
955956 (<>) = unsafeBinaryOp "||"
956957
957958instance Monoid
958− (Expression grp commons schemas params from (nullity 'PGtext)) where
959+ (Expression outer grp commons schemas params from (nullity 'PGtext)) where
959960 mempty = fromString ""
960961 mappend = (<>)
961962
962963-- | >>> printSQL $ lower "ARRRGGG"
963964-- lower(E'ARRRGGG')
964965lower
965− :: Expression grp commons schemas params from (nullity 'PGtext)
966+ :: Expression outer grp commons schemas params from (nullity 'PGtext)
966967 -- ^ string to lower case
967− -> Expression grp commons schemas params from (nullity 'PGtext)
968+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
968969lower = unsafeFunction "lower"
969970
970971-- | >>> printSQL $ upper "eeee"
971972-- upper(E'eeee')
972973upper
973− :: Expression grp commons schemas params from (nullity 'PGtext)
974+ :: Expression outer grp commons schemas params from (nullity 'PGtext)
974975 -- ^ string to upper case
975− -> Expression grp commons schemas params from (nullity 'PGtext)
976+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
976977upper = unsafeFunction "upper"
977978
978979-- | >>> printSQL $ charLength "four"
979980-- char_length(E'four')
980981charLength
981− :: Expression grp commons schemas params from (nullity 'PGtext)
982+ :: Expression outer grp commons schemas params from (nullity 'PGtext)
982983 -- ^ string to measure
983− -> Expression grp commons schemas params from (nullity 'PGint4)
984+ -> Expression outer grp commons schemas params from (nullity 'PGint4)
984985charLength = unsafeFunction "char_length"
985986
986987-- | The `like` expression returns true if the @string@ matches
@@ -993,11 +994,11 @@ charLength = unsafeFunction "char_length"
993994-- >>> printSQL $ "abc" `like` "a%"
994995-- (E'abc' LIKE E'a%')
995996like
996− :: Expression grp commons schemas params from (nullity 'PGtext)
997+ :: Expression outer grp commons schemas params from (nullity 'PGtext)
997998 -- ^ string
998− -> Expression grp commons schemas params from (nullity 'PGtext)
999+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
9991000 -- ^ pattern
1000− -> Expression grp commons schemas params from (nullity 'PGbool)
1001+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
10011002like = unsafeBinaryOp "LIKE"
10021003
10031004-- | The key word ILIKE can be used instead of LIKE to make the
@@ -1006,11 +1007,11 @@ like = unsafeBinaryOp "LIKE"
10061007-- >>> printSQL $ "abc" `ilike` "a%"
10071008-- (E'abc' ILIKE E'a%')
10081009ilike
1009− :: Expression grp commons schemas params from (nullity 'PGtext)
1010+ :: Expression outer grp commons schemas params from (nullity 'PGtext)
10101011 -- ^ string
1011− -> Expression grp commons schemas params from (nullity 'PGtext)
1012+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
10121013 -- ^ pattern
1013− -> Expression grp commons schemas params from (nullity 'PGbool)
1014+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
10141015ilike = unsafeBinaryOp "ILIKE"
10151016
10161017{-----------------------------------------
@@ -1025,36 +1026,36 @@ Table 9.44: json and jsonb operators
10251026-- | Get JSON value (object field or array element) at a key.
10261027(.->)
10271028 :: (json `In` PGJsonType, key `In` PGJsonKey)
1028− => Expression grp commons schemas params from (nullity json)
1029− -> Expression grp commons schemas params from (nullity key)
1030− -> Expression grp commons schemas params from ('Null json)
1029+ => Expression outer grp commons schemas params from (nullity json)
1030+ -> Expression outer grp commons schemas params from (nullity key)
1031+ -> Expression outer grp commons schemas params from ('Null json)
10311032infixl 8 .->
10321033(.->) = unsafeBinaryOp "->"
10331034
10341035-- | Get JSON value (object field or array element) at a key, as text.
10351036(.->>)
10361037 :: (json `In` PGJsonType, key `In` PGJsonKey)
1037− => Expression grp commons schemas params from (nullity json)
1038− -> Expression grp commons schemas params from (nullity key)
1039− -> Expression grp commons schemas params from ('Null 'PGtext)
1038+ => Expression outer grp commons schemas params from (nullity json)
1039+ -> Expression outer grp commons schemas params from (nullity key)
1040+ -> Expression outer grp commons schemas params from ('Null 'PGtext)
10401041infixl 8 .->>
10411042(.->>) = unsafeBinaryOp "->>"
10421043
10431044-- | Get JSON value at a specified path.
10441045(.#>)
10451046 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1046− => Expression grp commons schemas params from (nullity json)
1047− -> Expression grp commons schemas params from (nullity path)
1048− -> Expression grp commons schemas params from ('Null json)
1047+ => Expression outer grp commons schemas params from (nullity json)
1048+ -> Expression outer grp commons schemas params from (nullity path)
1049+ -> Expression outer grp commons schemas params from ('Null json)
10491050infixl 8 .#>
10501051(.#>) = unsafeBinaryOp "#>"
10511052
10521053-- | Get JSON value at a specified path as text.
10531054(.#>>)
10541055 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1055− => Expression grp commons schemas params from (nullity json)
1056− -> Expression grp commons schemas params from (nullity path)
1057− -> Expression grp commons schemas params from ('Null 'PGtext)
1056+ => Expression outer grp commons schemas params from (nullity json)
1057+ -> Expression outer grp commons schemas params from (nullity path)
1058+ -> Expression outer grp commons schemas params from ('Null 'PGtext)
10581059infixl 8 .#>>
10591060(.#>>) = unsafeBinaryOp "#>>"
10601061
@@ -1063,49 +1064,49 @@ infixl 8 .#>>
10631064-- | Does the left JSON value contain the right JSON path/value entries at the
10641065-- top level?
10651066(.@>)
1066− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1067− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1068− -> Condition grp commons schemas params from
1067+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1068+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1069+ -> Condition outer grp commons schemas params from
10691070infixl 9 .@>
10701071(.@>) = unsafeBinaryOp "@>"
10711072
10721073-- | Are the left JSON path/value entries contained at the top level within the
10731074-- right JSON value?
10741075(.<@)
1075− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1076− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1077− -> Condition grp commons schemas params from
1076+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1077+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1078+ -> Condition outer grp commons schemas params from
10781079infixl 9 .<@
10791080(.<@) = unsafeBinaryOp "<@"
10801081
10811082-- | Does the string exist as a top-level key within the JSON value?
10821083(.?)
1083− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1084− -> Expression grp commons schemas params from (nullity 'PGtext)
1085− -> Condition grp commons schemas params from
1084+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1085+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
1086+ -> Condition outer grp commons schemas params from
10861087infixl 9 .?
10871088(.?) = unsafeBinaryOp "?"
10881089
10891090-- | Do any of these array strings exist as top-level keys?
10901091(.?|)
1091− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1092− -> Expression grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1093− -> Condition grp commons schemas params from
1092+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1093+ -> Expression outer grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1094+ -> Condition outer grp commons schemas params from
10941095infixl 9 .?|
10951096(.?|) = unsafeBinaryOp "?|"
10961097
10971098-- | Do all of these array strings exist as top-level keys?
10981099(.?&)
1099− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1100− -> Expression grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1101− -> Condition grp commons schemas params from
1100+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1101+ -> Expression outer grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1102+ -> Condition outer grp commons schemas params from
11021103infixl 9 .?&
11031104(.?&) = unsafeBinaryOp "?&"
11041105
11051106-- | Concatenate two jsonb values into a new jsonb value.
1106−instance
1107− Semigroup (Expression commons schemas from grouping param (nullity 'PGjsonb)) where
1108− (<>) = unsafeBinaryOp "||"
1107+instance Semigroup
1108+ (Expression outer grp commons schemas params from (nullity 'PGjsonb)) where
1109+ (<>) = unsafeBinaryOp "||"
11091110
11101111-- | Delete a key or keys from a JSON object, or remove an array element.
11111112--
@@ -1121,9 +1122,9 @@ instance
11211122-- count from the end). Throws an error if top level container is not an array.
11221123(.-.)
11231124 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1124− => Expression grp commons schemas params from (nullity 'PGjsonb)
1125− -> Expression grp commons schemas params from (nullity key)
1126− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1125+ => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1126+ -> Expression outer grp commons schemas params from (nullity key)
1127+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
11271128infixl 6 .-.
11281129(.-.) = unsafeBinaryOp "-"
11291130
@@ -1131,9 +1132,9 @@ infixl 6 .-.
11311132-- integers count from the end)
11321133(#-.)
11331134 :: PGTextArray "(#-.)" arrayty
1134− => Expression grp commons schemas params from (nullity 'PGjsonb)
1135− -> Expression grp commons schemas params from (nullity arrayty)
1136− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1135+ => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1136+ -> Expression outer grp commons schemas params from (nullity arrayty)
1137+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
11371138infixl 6 #-.
11381139(#-.) = unsafeBinaryOp "#-"
11391140
@@ -1144,14 +1145,14 @@ Table 9.45: JSON creation functions
11441145-- | Literal binary JSON
11451146jsonbLit
11461147 :: JSON.ToJSON x
1147− => x -> Expression grp commons schemas params from (nullity 'PGjsonb)
1148+ => x -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
11481149jsonbLit = cast jsonb . UnsafeExpression
11491150 . singleQuotedUtf8 . toStrict . JSON.encode
11501151
11511152-- | Literal JSON
11521153jsonLit
11531154 :: JSON.ToJSON x
1154− => x -> Expression grp commons schemas params from (nullity 'PGjson)
1155+ => x -> Expression outer grp commons schemas params from (nullity 'PGjson)
11551156jsonLit = cast json . UnsafeExpression
11561157 . singleQuotedUtf8 . toStrict . JSON.encode
11571158
@@ -1162,8 +1163,8 @@ jsonLit = cast json . UnsafeExpression
11621163-- number, a Boolean, or a null value, the text representation will be used, in
11631164-- such a fashion that it is a valid json value.
11641165toJson
1165− :: Expression grp commons schemas params from (nullity ty)
1166− -> Expression grp commons schemas params from (nullity 'PGjson)
1166+ :: Expression outer grp commons schemas params from (nullity ty)
1167+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
11671168toJson = unsafeFunction "to_json"
11681169
11691170-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1173,43 +1174,43 @@ toJson = unsafeFunction "to_json"
11731174-- number, a Boolean, or a null value, the text representation will be used, in
11741175-- such a fashion that it is a valid jsonb value.
11751176toJsonb
1176− :: Expression grp commons schemas params from (nullity ty)
1177− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1177+ :: Expression outer grp commons schemas params from (nullity ty)
1178+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
11781179toJsonb = unsafeFunction "to_jsonb"
11791180
11801181-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11811182-- becomes a JSON array of arrays.
11821183arrayToJson
11831184 :: PGArray "arrayToJson" arr
1184− => Expression grp commons schemas params from (nullity arr)
1185− -> Expression grp commons schemas params from (nullity 'PGjson)
1185+ => Expression outer grp commons schemas params from (nullity arr)
1186+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
11861187arrayToJson = unsafeFunction "array_to_json"
11871188
11881189-- | Returns the row as a JSON object.
11891190rowToJson
1190− :: Expression grp commons schemas params from (nullity ('PGcomposite ty))
1191− -> Expression grp commons schemas params from (nullity 'PGjson)
1191+ :: Expression outer grp commons schemas params from (nullity ('PGcomposite ty))
1192+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
11921193rowToJson = unsafeFunction "row_to_json"
11931194
11941195-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11951196-- argument list.
11961197jsonBuildArray
11971198 :: SListI elems
1198− => NP (Expression grp commons schemas params from) elems
1199− -> Expression grp commons schemas params from (nullity 'PGjson)
1199+ => NP (Expression outer grp commons schemas params from) elems
1200+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
12001201jsonBuildArray = unsafeVariadicFunction "json_build_array"
12011202
12021203-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
12031204-- variadic argument list.
12041205jsonbBuildArray
12051206 :: SListI elems
1206− => NP (Expression grp commons schemas params from) elems
1207− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1207+ => NP (Expression outer grp commons schemas params from) elems
1208+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
12081209jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
12091210
12101211unsafeRowFunction
12111212 :: All Top elems
1212− => NP (Aliased (Expression grp commons schemas params from)) elems
1213+ => NP (Aliased (Expression outer grp commons schemas params from)) elems
12131214 -> [ByteString]
12141215unsafeRowFunction =
12151216 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1224,8 +1225,8 @@ unsafeRowFunction =
12241225-- and values.
12251226jsonBuildObject
12261227 :: All Top elems
1227− => NP (Aliased (Expression grp commons schemas params from)) elems
1228− -> Expression grp commons schemas params from (nullity 'PGjson)
1228+ => NP (Aliased (Expression outer grp commons schemas params from)) elems
1229+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
12291230jsonBuildObject
12301231 = unsafeFunction "json_build_object"
12311232 . UnsafeExpression
@@ -1237,8 +1238,8 @@ jsonBuildObject
12371238-- between text and values.
12381239jsonbBuildObject
12391240 :: All Top elems
1240− => NP (Aliased (Expression grp commons schemas params from)) elems
1241− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1241+ => NP (Aliased (Expression outer grp commons schemas params from)) elems
1242+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
12421243jsonbBuildObject
12431244 = unsafeFunction "jsonb_build_object"
12441245 . UnsafeExpression
@@ -1251,8 +1252,8 @@ jsonbBuildObject
12511252-- array has exactly two elements, which are taken as a key/value pair.
12521253jsonObject
12531254 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1254− => Expression grp commons schemas params from (nullity arr)
1255− -> Expression grp commons schemas params from (nullity 'PGjson)
1255+ => Expression outer grp commons schemas params from (nullity arr)
1256+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
12561257jsonObject = unsafeFunction "json_object"
12571258
12581259-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1261,8 +1262,8 @@ jsonObject = unsafeFunction "json_object"
12611262-- array has exactly two elements, which are taken as a key/value pair.
12621263jsonbObject
12631264 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1264− => Expression grp commons schemas params from (nullity arr)
1265− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1265+ => Expression outer grp commons schemas params from (nullity arr)
1266+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
12661267jsonbObject = unsafeFunction "jsonb_object"
12671268
12681269-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1270,9 +1271,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12701271jsonZipObject
12711272 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12721273 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1273− => Expression grp commons schemas params from (nullity keysArray)
1274− -> Expression grp commons schemas params from (nullity valuesArray)
1275− -> Expression grp commons schemas params from (nullity 'PGjson)
1274+ => Expression outer grp commons schemas params from (nullity keysArray)
1275+ -> Expression outer grp commons schemas params from (nullity valuesArray)
1276+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
12761277jsonZipObject ks vs =
12771278 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12781279
@@ -1282,9 +1283,9 @@ jsonZipObject ks vs =
12821283jsonbZipObject
12831284 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12841285 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1285− => Expression grp commons schemas params from (nullity keysArray)
1286− -> Expression grp commons schemas params from (nullity valuesArray)
1287− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1286+ => Expression outer grp commons schemas params from (nullity keysArray)
1287+ -> Expression outer grp commons schemas params from (nullity valuesArray)
1288+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
12881289jsonbZipObject ks vs =
12891290 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12901291
@@ -1294,23 +1295,23 @@ Table 9.46: JSON processing functions
12941295
12951296-- | Returns the number of elements in the outermost JSON array.
12961297jsonArrayLength
1297− :: Expression grp commons schemas params from (nullity 'PGjson)
1298− -> Expression grp commons schemas params from (nullity 'PGint4)
1298+ :: Expression outer grp commons schemas params from (nullity 'PGjson)
1299+ -> Expression outer grp commons schemas params from (nullity 'PGint4)
12991300jsonArrayLength = unsafeFunction "json_array_length"
13001301
13011302-- | Returns the number of elements in the outermost binary JSON array.
13021303jsonbArrayLength
1303− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1304− -> Expression grp commons schemas params from (nullity 'PGint4)
1304+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1305+ -> Expression outer grp commons schemas params from (nullity 'PGint4)
13051306jsonbArrayLength = unsafeFunction "jsonb_array_length"
13061307
13071308-- | Returns JSON value pointed to by the given path (equivalent to #>
13081309-- operator).
13091310jsonExtractPath
13101311 :: SListI elems
1311− => Expression grp commons schemas params from (nullity 'PGjson)
1312− -> NP (Expression grp commons schemas params from) elems
1313− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1312+ => Expression outer grp commons schemas params from (nullity 'PGjson)
1313+ -> NP (Expression outer grp commons schemas params from) elems
1314+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
13141315jsonExtractPath x xs =
13151316 unsafeVariadicFunction "json_extract_path" (x :* xs)
13161317
@@ -1318,9 +1319,9 @@ jsonExtractPath x xs =
13181319-- operator).
13191320jsonbExtractPath
13201321 :: SListI elems
1321− => Expression grp commons schemas params from (nullity 'PGjsonb)
1322− -> NP (Expression grp commons schemas params from) elems
1323− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1322+ => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1323+ -> NP (Expression outer grp commons schemas params from) elems
1324+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
13241325jsonbExtractPath x xs =
13251326 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
13261327
@@ -1328,9 +1329,9 @@ jsonbExtractPath x xs =
13281329-- operator), as text.
13291330jsonExtractPathAsText
13301331 :: SListI elems
1331− => Expression grp commons schemas params from (nullity 'PGjson)
1332− -> NP (Expression grp commons schemas params from) elems
1333− -> Expression grp commons schemas params from (nullity 'PGjson)
1332+ => Expression outer grp commons schemas params from (nullity 'PGjson)
1333+ -> NP (Expression outer grp commons schemas params from) elems
1334+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
13341335jsonExtractPathAsText x xs =
13351336 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
13361337
@@ -1338,38 +1339,38 @@ jsonExtractPathAsText x xs =
13381339-- operator), as text.
13391340jsonbExtractPathAsText
13401341 :: SListI elems
1341− => Expression grp commons schemas params from (nullity 'PGjsonb)
1342− -> NP (Expression grp commons schemas params from) elems
1343− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1342+ => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1343+ -> NP (Expression outer grp commons schemas params from) elems
1344+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
13441345jsonbExtractPathAsText x xs =
13451346 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
13461347
13471348-- | Returns the type of the outermost JSON value as a text string. Possible
13481349-- types are object, array, string, number, boolean, and null.
13491350jsonTypeof
1350− :: Expression grp commons schemas params from (nullity 'PGjson)
1351− -> Expression grp commons schemas params from (nullity 'PGtext)
1351+ :: Expression outer grp commons schemas params from (nullity 'PGjson)
1352+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
13521353jsonTypeof = unsafeFunction "json_typeof"
13531354
13541355-- | Returns the type of the outermost binary JSON value as a text string.
13551356-- Possible types are object, array, string, number, boolean, and null.
13561357jsonbTypeof
1357− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1358− -> Expression grp commons schemas params from (nullity 'PGtext)
1358+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1359+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
13591360jsonbTypeof = unsafeFunction "jsonb_typeof"
13601361
13611362-- | Returns its argument with all object fields that have null values omitted.
13621363-- Other null values are untouched.
13631364jsonStripNulls
1364− :: Expression grp commons schemas params from (nullity 'PGjson)
1365− -> Expression grp commons schemas params from (nullity 'PGjson)
1365+ :: Expression outer grp commons schemas params from (nullity 'PGjson)
1366+ -> Expression outer grp commons schemas params from (nullity 'PGjson)
13661367jsonStripNulls = unsafeFunction "json_strip_nulls"
13671368
13681369-- | Returns its argument with all object fields that have null values omitted.
13691370-- Other null values are untouched.
13701371jsonbStripNulls
1371− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1372− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1372+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1373+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
13731374jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13741375
13751376-- | @ jsonbSet target path new_value create_missing @
@@ -1381,11 +1382,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13811382-- arrays.
13821383jsonbSet
13831384 :: PGTextArray "jsonbSet" arr
1384− => Expression grp commons schemas params from (nullity 'PGjsonb)
1385− -> Expression grp commons schemas params from (nullity arr)
1386− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1387− -> Maybe (Expression grp commons schemas params from (nullity 'PGbool))
1388− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1385+ => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1386+ -> Expression outer grp commons schemas params from (nullity arr)
1387+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1388+ -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1389+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
13891390jsonbSet tgt path val createMissing = case createMissing of
13901391 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13911392 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1400,19 +1401,19 @@ jsonbSet tgt path val createMissing = case createMissing of
14001401-- in path count from the end of JSON arrays.
14011402jsonbInsert
14021403 :: PGTextArray "jsonbInsert" arr
1403− => Expression grp commons schemas params from (nullity 'PGjsonb)
1404− -> Expression grp commons schemas params from (nullity arr)
1405− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1406− -> Maybe (Expression grp commons schemas params from (nullity 'PGbool))
1407− -> Expression grp commons schemas params from (nullity 'PGjsonb)
1404+ => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1405+ -> Expression outer grp commons schemas params from (nullity arr)
1406+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1407+ -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1408+ -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
14081409jsonbInsert tgt path val insertAfter = case insertAfter of
14091410 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
14101411 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
14111412
14121413-- | Returns its argument as indented JSON text.
14131414jsonbPretty
1414− :: Expression grp commons schemas params from (nullity 'PGjsonb)
1415− -> Expression grp commons schemas params from (nullity 'PGtext)
1415+ :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1416+ -> Expression outer grp commons schemas params from (nullity 'PGtext)
14161417jsonbPretty = unsafeFunction "jsonb_pretty"
14171418
14181419{-----------------------------------------
@@ -1447,7 +1448,7 @@ class Aggregate expr1 expr2 aggr
14471448
14481449 -- | >>> :{
14491450 -- let
1450− -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1451+ -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
14511452 -- expression = sum_ (Distinct #col)
14521453 -- in printSQL expression
14531454 -- :}
@@ -1464,7 +1465,7 @@ class Aggregate expr1 expr2 aggr
14641465
14651466 -- | >>> :{
14661467 -- let
1467− -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1468+ -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14681469 -- expression = bitAnd (Distinct #col)
14691470 -- in printSQL expression
14701471 -- :}
@@ -1477,7 +1478,7 @@ class Aggregate expr1 expr2 aggr
14771478
14781479 -- | >>> :{
14791480 -- let
1480− -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1481+ -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14811482 -- expression = bitOr (All #col)
14821483 -- in printSQL expression
14831484 -- :}
@@ -1516,7 +1517,7 @@ class Aggregate expr1 expr2 aggr
15161517 --
15171518 -- >>> :{
15181519 -- let
1519− -- expression :: Expression ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1520+ -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15201521 -- expression = every (Distinct #col)
15211522 -- in printSQL expression
15221523 -- :}
@@ -1700,16 +1701,16 @@ data Distinction expr ty
17001701 = All (expr ty)
17011702 | Distinct (expr ty)
17021703 deriving (GHC.Generic,Show,Eq,Ord)
1703−instance NFData (Distinction (Expression grp commons schemas params from) ty)
1704−instance RenderSQL (Distinction (Expression grp commons schemas params from) ty) where
1704+instance NFData (Distinction (Expression outer grp commons schemas params from) ty)
1705+instance RenderSQL (Distinction (Expression outer grp commons schemas params from) ty) where
17051706 renderSQL = \case
17061707 All x -> "ALL" <+> renderSQL x
17071708 Distinct x -> "DISTINCT" <+> renderSQL x
17081709instance RenderSQL
17091710 (Distinction
1710− ( Expression grp commons schemas params from
1711+ ( Expression outer grp commons schemas params from
17111712 :*:
1712− Expression grp commons schemas params from) xty ) where
1713+ Expression outer grp commons schemas params from) xty ) where
17131714 renderSQL = \case
17141715 All (x :*: x') ->
17151716 "ALL" <+> renderSQL x <> ", " <> renderSQL x'
@@ -1717,9 +1718,9 @@ instance RenderSQL
17171718 "DISTINCT" <+> renderSQL x <> ", " <> renderSQL x'
17181719
17191720instance Aggregate
1720− (Distinction (Expression 'Ungrouped commons schemas params from))
1721− (Distinction (Expression 'Ungrouped commons schemas params from :*: Expression 'Ungrouped commons schemas params from))
1722− (Expression ('Grouped bys) commons schemas params from) where
1721+ (Distinction (Expression outer 'Ungrouped commons schemas params from))
1722+ (Distinction (Expression outer 'Ungrouped commons schemas params from :*: Expression outer 'Ungrouped commons schemas params from))
1723+ (Expression outer ('Grouped bys) commons schemas params from) where
17231724 countStar = UnsafeExpression "count(*)"
17241725 count = unsafeAggregate1 "count"
17251726 sum_ = unsafeAggregate1 "sum"
@@ -1751,9 +1752,9 @@ instance Aggregate
17511752 varPop = unsafeAggregate1 "var_pop"
17521753 varSamp = unsafeAggregate1 "var_samp"
17531754instance Aggregate
1754− (Expression grp commons schemas params from)
1755− (Expression grp commons schemas params from :*: Expression grp commons schemas params from)
1756− (WindowFunction grp commons schemas params from) where
1755+ (Expression outer grp commons schemas params from)
1756+ (Expression outer grp commons schemas params from :*: Expression outer grp commons schemas params from)
1757+ (WindowFunction outer grp commons schemas params from) where
17571758 countStar = UnsafeWindowFunction "count(*)"
17581759 count = unsafeWindowFunction1 "count"
17591760 sum_ = unsafeWindowFunction1 "sum"
@@ -1788,16 +1789,16 @@ instance Aggregate
17881789-- | escape hatch to define aggregate functions
17891790unsafeAggregate1
17901791 :: ByteString -- ^ aggregate function
1791− -> Distinction (Expression 'Ungrouped commons schemas params from) xty
1792− -> Expression ('Grouped bys) commons schemas params from yty
1792+ -> Distinction (Expression outer 'Ungrouped commons schemas params from) xty
1793+ -> Expression outer ('Grouped bys) commons schemas params from yty
17931794unsafeAggregate1 fun x = UnsafeExpression $ mconcat
17941795 [fun, "(", renderSQL x, ")"]
17951796
17961797-- | escape hatch to define aggregate binary functions
17971798unsafeAggregate2
17981799 :: ByteString -- ^ aggregate function
1799− -> Distinction (Expression 'Ungrouped commons schemas params from :*: Expression 'Ungrouped commons schemas params from) xty
1800− -> Expression ('Grouped bys) commons schemas params from yty
1800+ -> Distinction (Expression outer 'Ungrouped commons schemas params from :*: Expression outer 'Ungrouped commons schemas params from) xty
1801+ -> Expression outer ('Grouped bys) commons schemas params from yty
18011802unsafeAggregate2 fun xx = UnsafeExpression $ mconcat
18021803 [fun, "(", renderSQL xx, ")"]
18031804
@@ -1993,35 +1994,35 @@ Sorting
19931994-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
19941995-- determine whether nulls appear before or after non-null values in the sort
19951996-- ordering of a `Null` result column.
1996−data SortExpression grp commons schemas params from where
1997+data SortExpression outer grp commons schemas params from where
19971998 Asc
1998− :: Expression grp commons schemas params from ('NotNull ty)
1999− -> SortExpression grp commons schemas params from
1999+ :: Expression outer grp commons schemas params from ('NotNull ty)
2000+ -> SortExpression outer grp commons schemas params from
20002001 Desc
2001− :: Expression grp commons schemas params from ('NotNull ty)
2002− -> SortExpression grp commons schemas params from
2002+ :: Expression outer grp commons schemas params from ('NotNull ty)
2003+ -> SortExpression outer grp commons schemas params from
20032004 AscNullsFirst
2004− :: Expression grp commons schemas params from ('Null ty)
2005− -> SortExpression grp commons schemas params from
2005+ :: Expression outer grp commons schemas params from ('Null ty)
2006+ -> SortExpression outer grp commons schemas params from
20062007 AscNullsLast
2007− :: Expression grp commons schemas params from ('Null ty)
2008− -> SortExpression grp commons schemas params from
2008+ :: Expression outer grp commons schemas params from ('Null ty)
2009+ -> SortExpression outer grp commons schemas params from
20092010 DescNullsFirst
2010− :: Expression grp commons schemas params from ('Null ty)
2011− -> SortExpression grp commons schemas params from
2011+ :: Expression outer grp commons schemas params from ('Null ty)
2012+ -> SortExpression outer grp commons schemas params from
20122013 DescNullsLast
2013− :: Expression grp commons schemas params from ('Null ty)
2014− -> SortExpression grp commons schemas params from
2015−deriving instance Show (SortExpression grp commons schemas params from)
2014+ :: Expression outer grp commons schemas params from ('Null ty)
2015+ -> SortExpression outer grp commons schemas params from
2016+deriving instance Show (SortExpression outer grp commons schemas params from)
20162017
20172018class OrderBy expr where
20182019 orderBy
2019− :: [SortExpression grp commons schemas params from]
2020− -> expr grp commons schemas params from
2021− -> expr grp commons schemas params from
2020+ :: [SortExpression outer grp commons schemas params from]
2021+ -> expr outer grp commons schemas params from
2022+ -> expr outer grp commons schemas params from
20222023
20232024-- | Render a `SortExpression`.
2024−instance RenderSQL (SortExpression grp commons schemas params from) where
2025+instance RenderSQL (SortExpression outer grp commons schemas params from) where
20252026 renderSQL = \case
20262027 Asc expression -> renderSQL expression <+> "ASC"
20272028 Desc expression -> renderSQL expression <+> "DESC"
@@ -2032,18 +2033,18 @@ instance RenderSQL (SortExpression grp commons schemas params from) where
20322033 AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
20332034 DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
20342035
2035−data WindowDefinition grp commons schemas params from where
2036+data WindowDefinition outer grp commons schemas params from where
20362037 WindowDefinition
20372038 :: SListI bys
2038− => NP (Expression grp commons schemas params from) bys
2039− -> [SortExpression grp commons schemas params from]
2040− -> WindowDefinition grp commons schemas params from
2039+ => NP (Expression outer grp commons schemas params from) bys
2040+ -> [SortExpression outer grp commons schemas params from]
2041+ -> WindowDefinition outer grp commons schemas params from
20412042
20422043instance OrderBy WindowDefinition where
20432044 orderBy sortsR (WindowDefinition parts sortsL)
20442045 = WindowDefinition parts (sortsL ++ sortsR)
20452046
2046−instance RenderSQL (WindowDefinition commons schemas from grp params) where
2047+instance RenderSQL (WindowDefinition outer commons schemas from grp params) where
20472048 renderSQL (WindowDefinition part ord) =
20482049 renderPartitionByClause part <> renderOrderByClause ord
20492050 where
@@ -2057,11 +2058,12 @@ instance RenderSQL (WindowDefinition commons schemas from grp params) where
20572058
20582059partitionBy
20592060 :: SListI bys
2060− => NP (Expression grp commons schemas params from) bys
2061− -> WindowDefinition grp commons schemas params from
2061+ => NP (Expression outer grp commons schemas params from) bys
2062+ -> WindowDefinition outer grp commons schemas params from
20622063partitionBy bys = WindowDefinition bys []
20632064
20642065newtype WindowFunction
2066+ (outer :: FromType)
20652067 (grp :: Grouping)
20662068 (commons :: FromType)
20672069 (schemas :: SchemasType)
@@ -2071,20 +2073,20 @@ newtype WindowFunction
20712073 = UnsafeWindowFunction { renderWindowFunction :: ByteString }
20722074 deriving (GHC.Generic,Show,Eq,Ord,NFData)
20732075
2074−instance RenderSQL (WindowFunction grp commons schemas params from ty) where
2076+instance RenderSQL (WindowFunction outer grp commons schemas params from ty) where
20752077 renderSQL = renderWindowFunction
20762078
20772079unsafeWindowFunction1
20782080 :: ByteString
2079− -> Expression grp commons schemas params from ty0
2080− -> WindowFunction grp commons schemas params from ty1
2081+ -> Expression outer grp commons schemas params from ty0
2082+ -> WindowFunction outer grp commons schemas params from ty1
20812083unsafeWindowFunction1 fun x
20822084 = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x)
20832085
20842086unsafeWindowFunction2
20852087 :: ByteString
2086− -> (Expression grp commons schemas params from :*: Expression grp commons schemas params from) ty0
2087− -> WindowFunction grp commons schemas params from ty1
2088+ -> (Expression outer grp commons schemas params from :*: Expression outer grp commons schemas params from) ty0
2089+ -> WindowFunction outer grp commons schemas params from ty1
20882090unsafeWindowFunction2 fun (x :*: x')
20892091 = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x <> ", " <> renderSQL x')
20902092
@@ -2092,28 +2094,28 @@ unsafeWindowFunction2 fun (x :*: x')
20922094>>> printSQL rank
20932095rank()
20942096-}
2095−rank :: WindowFunction grp commons schemas params from ('NotNull 'PGint8)
2097+rank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
20962098rank = UnsafeWindowFunction "rank()"
20972099
20982100{- | number of the current row within its partition, counting from 1
20992101>>> printSQL rowNumber
21002102row_number()
21012103-}
2102−rowNumber :: WindowFunction grp commons schemas params from ('NotNull 'PGint8)
2104+rowNumber :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
21032105rowNumber = UnsafeWindowFunction "row_number()"
21042106
21052107{- | rank of the current row without gaps; this function counts peer groups
21062108>>> printSQL denseRank
21072109dense_rank()
21082110-}
2109−denseRank :: WindowFunction grp commons schemas params from ('NotNull 'PGint8)
2111+denseRank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
21102112denseRank = UnsafeWindowFunction "dense_rank()"
21112113
21122114{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
21132115>>> printSQL percentRank
21142116percent_rank()
21152117-}
2116−percentRank :: WindowFunction grp commons schemas params from ('NotNull 'PGfloat8)
2118+percentRank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGfloat8)
21172119percentRank = UnsafeWindowFunction "percent_rank()"
21182120
21192121{- | cumulative distribution: (number of partition rows
@@ -2121,16 +2123,16 @@ preceding or peer with current row) / total partition rows
21212123>>> printSQL cumeDist
21222124cume_dist()
21232125-}
2124−cumeDist :: WindowFunction grp commons schemas params from ('NotNull 'PGfloat8)
2126+cumeDist :: WindowFunction outer grp commons schemas params from ('NotNull 'PGfloat8)
21252127cumeDist = UnsafeWindowFunction "cume_dist()"
21262128
21272129{- | integer ranging from 1 to the argument value,
21282130dividing the partition as equally as possible
21292131-}
21302132ntile
2131− :: Expression grp commons schemas params from ('NotNull 'PGint4)
2133+ :: Expression outer grp commons schemas params from ('NotNull 'PGint4)
21322134 -- ^ num buckets
2133− -> WindowFunction grp commons schemas params from ('NotNull 'PGint4)
2135+ -> WindowFunction outer grp commons schemas params from ('NotNull 'PGint4)
21342136ntile = unsafeWindowFunction1 "ntile"
21352137
21362138{- | returns value evaluated at the row that is offset rows before the current
@@ -2139,13 +2141,13 @@ row within the partition; if there is no such row, instead return default
21392141evaluated with respect to the current row.
21402142-}
21412143lag
2142− :: Expression grp commons schemas params from ty
2144+ :: Expression outer grp commons schemas params from ty
21432145 -- ^ value
2144− -> Expression grp commons schemas params from ('NotNull 'PGint4)
2146+ -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
21452147 -- ^ offset
2146− -> Expression grp commons schemas params from ty
2148+ -> Expression outer grp commons schemas params from ty
21472149 -- ^ default
2148− -> WindowFunction grp commons schemas params from ty
2150+ -> WindowFunction outer grp commons schemas params from ty
21492151lag value offset def = UnsafeWindowFunction $ "lag"
21502152 <> parenthesized
21512153 (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
@@ -2156,13 +2158,13 @@ row within the partition; if there is no such row, instead return default
21562158evaluated with respect to the current row.
21572159-}
21582160lead
2159− :: Expression grp commons schemas params from ty
2161+ :: Expression outer grp commons schemas params from ty
21602162 -- ^ value
2161− -> Expression grp commons schemas params from ('NotNull 'PGint4)
2163+ -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
21622164 -- ^ offset
2163− -> Expression grp commons schemas params from ty
2165+ -> Expression outer grp commons schemas params from ty
21642166 -- ^ default
2165− -> WindowFunction grp commons schemas params from ty
2167+ -> WindowFunction outer grp commons schemas params from ty
21662168lead value offset def = UnsafeWindowFunction $ "lag"
21672169 <> parenthesized
21682170 (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
@@ -2171,28 +2173,28 @@ lead value offset def = UnsafeWindowFunction $ "lag"
21712173first row of the window frame
21722174-}
21732175firstValue
2174− :: Expression grp commons schemas params from ty
2176+ :: Expression outer grp commons schemas params from ty
21752177 -- ^ value
2176− -> WindowFunction grp commons schemas params from ty
2178+ -> WindowFunction outer grp commons schemas params from ty
21772179firstValue = unsafeWindowFunction1 "first_value"
21782180
21792181{- | returns value evaluated at the row that is the
21802182last row of the window frame
21812183-}
21822184lastValue
2183− :: Expression grp commons schemas params from ty
2185+ :: Expression outer grp commons schemas params from ty
21842186 -- ^ value
2185− -> WindowFunction grp commons schemas params from ty
2187+ -> WindowFunction outer grp commons schemas params from ty
21862188lastValue = unsafeWindowFunction1 "last_value"
21872189
21882190{- | returns value evaluated at the row that is the nth
21892191row of the window frame (counting from 1); null if no such row
21902192-}
21912193nthValue
2192− :: Expression grp commons schemas params from (nullity ty)
2194+ :: Expression outer grp commons schemas params from (nullity ty)
21932195 -- ^ value
2194− -> Expression grp commons schemas params from ('NotNull 'PGint4)
2196+ -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
21952197 -- ^ nth
2196− -> WindowFunction grp commons schemas params from ('Null ty)
2198+ -> WindowFunction outer grp commons schemas params from ('Null ty)
21972199nthValue value nth = UnsafeWindowFunction $ "nth_value"
21982200 <> parenthesized (commaSeparated [renderSQL value, renderSQL nth])
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+17−17
@@ -214,7 +214,7 @@ type family Manipulation_ (schemas :: SchemasType) (params :: Type) (row :: Type
214214
215215-- | Convert a `Query` into a `Manipulation`.
216216queryStatement
217− :: Query commons schemas params columns
217+ :: Query '[] commons schemas params columns
218218 -> Manipulation commons schemas params columns
219219queryStatement q = UnsafeManipulation $ renderSQL q
220220
@@ -268,11 +268,11 @@ data QueryClause commons schemas params columns where
268268 Select
269269 :: SOP.SListI columns
270270 => NP (ColumnExpression grp schemas params from) columns
271− -> TableExpression grp commons schemas params from
271+ -> TableExpression '[] grp commons schemas params from
272272 -> QueryClause commons schemas params columns
273273 Subquery
274274 :: ColumnsToRow columns ~ row
275− => Query commons schemas params row
275+ => Query '[] commons schemas params row
276276 -> QueryClause commons schemas params columns
277277
278278instance RenderSQL (QueryClause commons schemas params columns) where
@@ -319,17 +319,17 @@ data ColumnExpression grp schemas params from column where
319319 => Alias col
320320 -> ColumnExpression grp schemas params from (col ::: 'Def :=> ty)
321321 Specific
322− :: Aliased (Expression grp '[] schemas params from) (col ::: ty)
322+ :: Aliased (Expression '[] grp '[] schemas params from) (col ::: ty)
323323 -> ColumnExpression grp schemas params from (col ::: defness :=> ty)
324324
325325instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
326326 => Aliasable col
327− (Expression grp '[] schemas params from ty)
327+ (Expression '[] grp '[] schemas params from ty)
328328 (ColumnExpression grp schemas params from column) where
329329 expression `as` col = Specific (expression `As` col)
330330instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
331331 => Aliasable col
332− (Expression grp '[] schemas params from ty)
332+ (Expression '[] grp '[] schemas params from ty)
333333 (NP (ColumnExpression grp schemas params from) columns) where
334334 expression `as` col = expression `as` col :* Nil
335335instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
@@ -406,7 +406,7 @@ instance RenderSQL (ColumnExpression grp schemas params from column) where
406406-- in the row. Use @Returning Nil@ in the common case where no return
407407-- values are desired.
408408newtype ReturningClause commons schemas params from row =
409− Returning (Selection 'Ungrouped commons schemas params from row)
409+ Returning (Selection '[] 'Ungrouped commons schemas params from row)
410410
411411instance RenderSQL (ReturningClause commons schemas params from row) where
412412 renderSQL = \case
@@ -415,7 +415,7 @@ instance RenderSQL (ReturningClause commons schemas params from row) where
415415
416416pattern Returning_
417417 :: SOP.SListI row
418− => NP (Aliased (Expression 'Ungrouped commons schemas params from)) row
418+ => NP (Aliased (Expression '[] 'Ungrouped commons schemas params from)) row
419419 -> ReturningClause commons schemas params from row
420420pattern Returning_ list = Returning (List list)
421421
@@ -448,7 +448,7 @@ data ConflictAction tab commons schemas params columns where
448448 , SOP.All (HasIn columns) subcolumns
449449 , AllUnique subcolumns )
450450 => NP (ColumnExpression 'Ungrouped schemas params '[tab ::: row, "excluded" ::: row]) subcolumns
451− -> [Condition 'Ungrouped commons schemas params '[tab ::: row, "excluded" ::: row]]
451+ -> [Condition '[] 'Ungrouped commons schemas params '[tab ::: row, "excluded" ::: row]]
452452 -> ConflictAction tab commons schemas params columns
453453
454454instance RenderSQL (ConflictAction tab commons schemas params columns) where
@@ -493,7 +493,7 @@ update
493493 => QualifiedAlias sch tab -- ^ table to update
494494 -> NP (ColumnExpression 'Ungrouped schemas params '[tab ::: row0]) subcolumns
495495 -- ^ modified values to replace old values
496− -> Condition 'Ungrouped commons schemas params '[tab ::: row0]
496+ -> Condition '[] 'Ungrouped commons schemas params '[tab ::: row0]
497497 -- ^ condition under which to perform update on a row
498498 -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
499499 -> Manipulation commons schemas params row1
@@ -518,7 +518,7 @@ update_
518518 => QualifiedAlias sch tab -- ^ table to update
519519 -> NP (ColumnExpression 'Ungrouped schemas params '[tab ::: row]) subcolumns
520520 -- ^ modified values to replace old values
521− -> Condition 'Ungrouped commons schemas params '[tab ::: row]
521+ -> Condition '[] 'Ungrouped commons schemas params '[tab ::: row]
522522 -- ^ condition under which to perform update on a row
523523 -> Manipulation commons schemas params '[]
524524update_ tab columns wh = update tab columns wh (Returning_ Nil)
@@ -530,7 +530,7 @@ DELETE statements
530530data UsingClause commons schemas params from where
531531 NoUsing :: UsingClause commons schemas params '[]
532532 Using
533− :: FromClause commons schemas params from
533+ :: FromClause '[] commons schemas params from
534534 -> UsingClause commons schemas params from
535535
536536-- | Delete rows from a table.
@@ -543,7 +543,7 @@ deleteFrom
543543 , columns ~ TableToColumns table )
544544 => QualifiedAlias sch tab -- ^ table to delete from
545545 -> UsingClause commons schemas params from
546− -> Condition 'Ungrouped commons schemas params (tab ::: row0 ': from)
546+ -> Condition '[] 'Ungrouped commons schemas params (tab ::: row0 ': from)
547547 -- ^ condition under which to delete a row
548548 -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
549549 -> Manipulation commons schemas params row1
@@ -564,7 +564,7 @@ deleteFrom_
564564 , row ~ TableToRow table
565565 , columns ~ TableToColumns table )
566566 => QualifiedAlias sch tab -- ^ table to delete from
567− -> Condition 'Ungrouped commons schemas params '[tab ::: row]
567+ -> Condition '[] 'Ungrouped commons schemas params '[tab ::: row]
568568 -- ^ condition under which to delete a row
569569 -> Manipulation commons schemas params '[]
570570deleteFrom_ tab wh = deleteFrom tab NoUsing wh (Returning_ Nil)
@@ -575,10 +575,10 @@ deleteFrom_ tab wh = deleteFrom tab NoUsing wh (Returning_ Nil)
575575-- a comma separated list of tables. Typical case is the `USING` clause
576576-- of a DELETE query.
577577also
578− :: FromClause commons schemas params right
578+ :: FromClause outer commons schemas params right
579579 -- ^ right
580− -> FromClause commons schemas params left
580+ -> FromClause outer commons schemas params left
581581 -- ^ left
582− -> FromClause commons schemas params (Join left right)
582+ -> FromClause outer commons schemas params (Join left right)
583583also right left = UnsafeFromClause $
584584 renderSQL left <> "," <+> renderSQL right
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+1−1
@@ -289,7 +289,7 @@ deleteMigration = deleteFrom_ (#migrations ! #schema_migrations) (#name .== para
289289-- the time at which it was executed.
290290selectMigration
291291 :: Has "migrations" schemas MigrationsSchema
292− => Query '[] schemas '[ 'NotNull 'PGtext ]
292+ => Query '[] '[] schemas '[ 'NotNull 'PGtext ]
293293 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
294294selectMigration = select_
295295 (#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
333333
334334 runQueryParams
335335 :: ToParams x params
336− => Query '[] schemas params ys
336+ => Query '[] '[] schemas params ys
337337 -- ^ `select` and friends
338338 -> x -> pq (K LibPQ.Result ys)
339339 runQueryParams = manipulateParams . queryStatement
340340
341341 runQuery
342− :: Query '[] schemas '[] ys
342+ :: Query '[] '[] schemas '[] ys
343343 -- ^ `select` and friends
344344 -> pq (K LibPQ.Result ys)
345345 runQuery q = runQueryParams q ()
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+260−255
@@ -281,7 +281,7 @@ value queries:
281281
282282>>> :{
283283let
284− query :: Query commons schemas '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
284+ query :: Query outer commons schemas '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
285285 query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]
286286in printSQL query
287287:}
@@ -323,23 +323,24 @@ in printSQL query
323323SELECT "col1" AS "col1", rank() OVER (PARTITION BY "col1" ORDER BY "col2" ASC) AS "rank" FROM "tab" AS "tab"
324324-}
325325newtype Query
326+ (outer :: FromType)
326327 (commons :: FromType)
327328 (schemas :: SchemasType)
328329 (params :: [NullityType])
329330 (row :: RowType)
330331 = UnsafeQuery { renderQuery :: ByteString }
331332 deriving (GHC.Generic,Show,Eq,Ord,NFData)
332−instance RenderSQL (Query commons schemas params row) where renderSQL = renderQuery
333+instance RenderSQL (Query outer commons schemas params row) where renderSQL = renderQuery
333334
334335type family Query_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
335− Query_ schemas params row = Query '[] schemas (TuplePG params) (RowPG row)
336+ Query_ schemas params row = Query '[] '[] schemas (TuplePG params) (RowPG row)
336337
337338-- | The results of two queries can be combined using the set operation
338339-- `union`. Duplicate rows are eliminated.
339340union
340− :: Query commons schemas params columns
341− -> Query commons schemas params columns
342− -> Query commons schemas params columns
341+ :: Query outer commons schemas params columns
342+ -> Query outer commons schemas params columns
343+ -> Query outer commons schemas params columns
343344q1 `union` q2 = UnsafeQuery $
344345 parenthesized (renderSQL q1)
345346 <+> "UNION"
@@ -348,9 +349,9 @@ q1 `union` q2 = UnsafeQuery $
348349-- | The results of two queries can be combined using the set operation
349350-- `unionAll`, the disjoint union. Duplicate rows are retained.
350351unionAll
351− :: Query commons schemas params columns
352− -> Query commons schemas params columns
353− -> Query commons schemas params columns
352+ :: Query outer commons schemas params columns
353+ -> Query outer commons schemas params columns
354+ -> Query outer commons schemas params columns
354355q1 `unionAll` q2 = UnsafeQuery $
355356 parenthesized (renderSQL q1)
356357 <+> "UNION" <+> "ALL"
@@ -359,9 +360,9 @@ q1 `unionAll` q2 = UnsafeQuery $
359360-- | The results of two queries can be combined using the set operation
360361-- `intersect`, the intersection. Duplicate rows are eliminated.
361362intersect
362− :: Query commons schemas params columns
363− -> Query commons schemas params columns
364− -> Query commons schemas params columns
363+ :: Query outer commons schemas params columns
364+ -> Query outer commons schemas params columns
365+ -> Query outer commons schemas params columns
365366q1 `intersect` q2 = UnsafeQuery $
366367 parenthesized (renderSQL q1)
367368 <+> "INTERSECT"
@@ -370,9 +371,9 @@ q1 `intersect` q2 = UnsafeQuery $
370371-- | The results of two queries can be combined using the set operation
371372-- `intersectAll`, the intersection. Duplicate rows are retained.
372373intersectAll
373− :: Query commons schemas params columns
374− -> Query commons schemas params columns
375− -> Query commons schemas params columns
374+ :: Query outer commons schemas params columns
375+ -> Query outer commons schemas params columns
376+ -> Query outer commons schemas params columns
376377q1 `intersectAll` q2 = UnsafeQuery $
377378 parenthesized (renderSQL q1)
378379 <+> "INTERSECT" <+> "ALL"
@@ -381,9 +382,9 @@ q1 `intersectAll` q2 = UnsafeQuery $
381382-- | The results of two queries can be combined using the set operation
382383-- `except`, the set difference. Duplicate rows are eliminated.
383384except
384− :: Query commons schemas params columns
385− -> Query commons schemas params columns
386− -> Query commons schemas params columns
385+ :: Query outer commons schemas params columns
386+ -> Query outer commons schemas params columns
387+ -> Query outer commons schemas params columns
387388q1 `except` q2 = UnsafeQuery $
388389 parenthesized (renderSQL q1)
389390 <+> "EXCEPT"
@@ -392,9 +393,9 @@ q1 `except` q2 = UnsafeQuery $
392393-- | The results of two queries can be combined using the set operation
393394-- `exceptAll`, the set difference. Duplicate rows are retained.
394395exceptAll
395− :: Query commons schemas params columns
396− -> Query commons schemas params columns
397− -> Query commons schemas params columns
396+ :: Query outer commons schemas params columns
397+ -> Query outer commons schemas params columns
398+ -> Query outer commons schemas params columns
398399q1 `exceptAll` q2 = UnsafeQuery $
399400 parenthesized (renderSQL q1)
400401 <+> "EXCEPT" <+> "ALL"
@@ -404,54 +405,58 @@ q1 `exceptAll` q2 = UnsafeQuery $
404405SELECT queries
405406-----------------------------------------}
406407
407−data Selection grp commons schemas params from row where
408+data Selection outer grp commons schemas params from row where
408409 List
409410 :: SListI row
410− => NP (Aliased (Expression grp commons schemas params from)) row
411− -> Selection grp commons schemas params from row
411+ => NP (Aliased (Expression outer grp commons schemas params from)) row
412+ -> Selection outer grp commons schemas params from row
412413 Star
413414 :: HasUnique tab from row
414− => Selection 'Ungrouped commons schemas params from row
415+ => Selection outer 'Ungrouped commons schemas params from row
415416 DotStar
416417 :: Has tab from row
417418 => Alias tab
418− -> Selection 'Ungrouped commons schemas params from row
419+ -> Selection outer 'Ungrouped commons schemas params from row
419420 Also
420− :: Selection grp commons schemas params from right
421− -> Selection grp commons schemas params from left
422− -> Selection grp commons schemas params from (Join left right)
421+ :: Selection outer grp commons schemas params from right
422+ -> Selection outer grp commons schemas params from left
423+ -> Selection outer grp commons schemas params from (Join left right)
423424 Over
424425 :: SListI row
425− => NP (Aliased (WindowFunction grp commons schemas params from)) row
426− -> WindowDefinition grp commons schemas params from
427− -> Selection grp commons schemas params from row
426+ => NP (Aliased (WindowFunction outer grp commons schemas params from)) row
427+ -> WindowDefinition outer grp commons schemas params from
428+ -> Selection outer grp commons schemas params from row
428429instance (KnownSymbol col, row ~ '[col ::: ty])
429430 => Aliasable col
430− (Expression grp commons schemas params from ty)
431− (Selection grp commons schemas params from row) where
431+ (Expression outer grp commons schemas params from ty)
432+ (Selection outer grp commons schemas params from row) where
432433 expr `as` col = List (expr `as` col)
433−instance (Has tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
434− => IsQualified tab col (Selection 'Ungrouped commons schemas params from row1) where
435− tab ! col = tab ! col `as` col
434+instance (Has tab (Join outer from) row0, Has col row0 ty, row1 ~ '[col ::: ty])
435+ => IsQualified tab col
436+ (Selection outer 'Ungrouped commons schemas params from row1) where
437+ tab ! col = tab ! col `as` col
436438instance
437− ( Has tab from row0
439+ ( Has tab (Join outer from) row0
438440 , Has col row0 ty
439441 , row1 ~ '[col ::: ty]
440442 , GroupedBy tab col bys )
441− => IsQualified tab col (Selection ('Grouped bys) commons schemas params from row1) where
442− tab ! col = tab ! col `as` col
443−instance (HasUnique tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
444− => IsLabel col (Selection 'Ungrouped commons schemas params from row1) where
445− fromLabel = fromLabel @col `as` Alias
443+ => IsQualified tab col
444+ (Selection outer ('Grouped bys) commons schemas params from row1) where
445+ tab ! col = tab ! col `as` col
446+instance (HasUnique tab (Join outer from) row0, Has col row0 ty, row1 ~ '[col ::: ty])
447+ => IsLabel col
448+ (Selection outer 'Ungrouped commons schemas params from row1) where
449+ fromLabel = fromLabel @col `as` Alias
446450instance
447− ( HasUnique tab from row0
451+ ( HasUnique tab (Join outer from) row0
448452 , Has col row0 ty
449453 , row1 ~ '[col ::: ty]
450454 , GroupedBy tab col bys )
451− => IsLabel col (Selection ('Grouped bys) commons schemas params from row1) where
452− fromLabel = fromLabel @col `as` Alias
455+ => IsLabel col
456+ (Selection outer ('Grouped bys) commons schemas params from row1) where
457+ fromLabel = fromLabel @col `as` Alias
453458
454−instance RenderSQL (Selection grp commons schemas params from row) where
459+instance RenderSQL (Selection outer grp commons schemas params from row) where
455460 renderSQL = \case
456461 List list -> renderCommaSeparated (renderAliased renderSQL) list
457462 Star -> "*"
@@ -460,7 +465,7 @@ instance RenderSQL (Selection grp commons schemas params from row) where
460465 Over winFns winDef ->
461466 let
462467 renderOver
463− :: Aliased (WindowFunction grp commons schemas params from) field
468+ :: Aliased (WindowFunction outer grp commons schemas params from) field
464469 -> ByteString
465470 renderOver (winFn `As` col) = renderSQL winFn
466471 <+> "OVER" <+> parenthesized (renderSQL winDef)
@@ -475,11 +480,11 @@ instance RenderSQL (Selection grp commons schemas params from row) where
475480-- the intermediate table are actually output.
476481select
477482 :: (SListI row, row ~ (x ': xs))
478− => Selection grp commons schemas params from row
483+ => Selection outer grp commons schemas params from row
479484 -- ^ select list
480− -> TableExpression grp commons schemas params from
485+ -> TableExpression outer grp commons schemas params from
481486 -- ^ intermediate virtual table
482− -> Query commons schemas params row
487+ -> Query outer commons schemas params row
483488select selection tabexpr = UnsafeQuery $
484489 "SELECT"
485490 <+> renderSQL selection
@@ -487,20 +492,20 @@ select selection tabexpr = UnsafeQuery $
487492
488493select_
489494 :: (SListI row, row ~ (x ': xs))
490− => NP (Aliased (Expression grp commons schemas params from)) row
491− -> TableExpression grp commons schemas params from
492− -> Query commons schemas params row
495+ => NP (Aliased (Expression outer grp commons schemas params from)) row
496+ -> TableExpression outer grp commons schemas params from
497+ -> Query outer commons schemas params row
493498select_ list = select (List list)
494499
495500-- | After the select list has been processed, the result table can
496501-- be subject to the elimination of duplicate rows using `selectDistinct`.
497502selectDistinct
498503 :: (SListI columns, columns ~ (col ': cols))
499− => Selection 'Ungrouped commons schemas params from columns
504+ => Selection outer 'Ungrouped commons schemas params from columns
500505 -- ^ select list
501− -> TableExpression 'Ungrouped commons schemas params from
506+ -> TableExpression outer 'Ungrouped commons schemas params from
502507 -- ^ intermediate virtual table
503− -> Query commons schemas params columns
508+ -> Query outer commons schemas params columns
504509selectDistinct selection tabexpr = UnsafeQuery $
505510 "SELECT DISTINCT"
506511 <+> renderSQL selection
@@ -508,11 +513,11 @@ selectDistinct selection tabexpr = UnsafeQuery $
508513
509514selectDistinct_
510515 :: (SListI columns, columns ~ (col ': cols))
511− => NP (Aliased (Expression 'Ungrouped commons schemas params from)) columns
516+ => NP (Aliased (Expression outer 'Ungrouped commons schemas params from)) columns
512517 -- ^ select list
513− -> TableExpression 'Ungrouped commons schemas params from
518+ -> TableExpression outer 'Ungrouped commons schemas params from
514519 -- ^ intermediate virtual table
515− -> Query commons schemas params columns
520+ -> Query outer commons schemas params columns
516521selectDistinct_ list = select (List list)
517522
518523-- | `values` computes a row value or set of row values
@@ -521,16 +526,16 @@ selectDistinct_ list = select (List list)
521526-- but it can be used on its own.
522527--
523528-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
524−-- >>> let query = values (1 `as` #a :* "one" `as` #b) [] :: Query commons schemas '[] Row
529+-- >>> let query = values (1 `as` #a :* "one" `as` #b) [] :: Query outer commons schemas '[] Row
525530-- >>> printSQL query
526531-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
527532values
528533 :: SListI cols
529− => NP (Aliased (Expression 'Ungrouped commons schemas params '[] )) cols
530− -> [NP (Aliased (Expression 'Ungrouped commons schemas params '[] )) cols]
534+ => NP (Aliased (Expression outer 'Ungrouped commons schemas params '[] )) cols
535+ -> [NP (Aliased (Expression outer 'Ungrouped commons schemas params '[] )) cols]
531536 -- ^ When more than one row is specified, all the rows must
532537 -- must have the same number of elements
533− -> Query commons schemas params cols
538+ -> Query outer commons schemas params cols
534539values rw rws = UnsafeQuery $ "SELECT * FROM"
535540 <+> parenthesized (
536541 "VALUES"
@@ -541,7 +546,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
541546 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
542547 where
543548 renderAliasPart, renderValuePart
544− :: Aliased (Expression 'Ungrouped commons schemas params '[] ) ty -> ByteString
549+ :: Aliased (Expression outer 'Ungrouped commons schemas params '[] ) ty -> ByteString
545550 renderAliasPart (_ `As` name) = renderSQL name
546551 renderValuePart (value `As` _) = renderSQL value
547552
@@ -549,9 +554,9 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
549554-- specified by value expressions.
550555values_
551556 :: SListI cols
552− => NP (Aliased (Expression 'Ungrouped commons schemas params '[] )) cols
557+ => NP (Aliased (Expression outer 'Ungrouped commons schemas params '[] )) cols
553558 -- ^ one row of values
554− -> Query commons schemas params cols
559+ -> Query outer commons schemas params cols
555560values_ rw = values rw []
556561
557562{-----------------------------------------
@@ -565,16 +570,17 @@ Table Expressions
565570-- to a table on disk, a so-called base table, but more complex expressions
566571-- can be used to modify or combine base tables in various ways.
567572data TableExpression
573+ (outer :: FromType)
568574 (grp :: Grouping)
569575 (commons :: FromType)
570576 (schemas :: SchemasType)
571577 (params :: [NullityType])
572578 (from :: FromType)
573579 = TableExpression
574− { fromClause :: FromClause commons schemas params from
580+ { fromClause :: FromClause outer commons schemas params from
575581 -- ^ A table reference that can be a table name, or a derived table such
576582 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
577− , whereClause :: [Condition 'Ungrouped commons schemas params from]
583+ , whereClause :: [Condition outer 'Ungrouped commons schemas params from]
578584 -- ^ optional search coditions, combined with `.&&`. After the processing
579585 -- of the `fromClause` is done, each row of the derived virtual table
580586 -- is checked against the search condition. If the result of the
@@ -590,13 +596,13 @@ data TableExpression
590596 -- set of rows having common values into one group row that represents all
591597 -- rows in the group. This is done to eliminate redundancy in the output
592598 -- and/or compute aggregates that apply to these groups.
593− , havingClause :: HavingClause grp commons schemas params from
599+ , havingClause :: HavingClause outer grp commons schemas params from
594600 -- ^ If a table has been grouped using `groupBy`, but only certain groups
595601 -- are of interest, the `havingClause` can be used, much like a
596602 -- `whereClause`, to eliminate groups from the result. Expressions in the
597603 -- `havingClause` can refer both to grouped expressions and to ungrouped
598604 -- expressions (which necessarily involve an aggregate function).
599− , orderByClause :: [SortExpression grp commons schemas params from]
605+ , orderByClause :: [SortExpression outer grp commons schemas params from]
600606 -- ^ The `orderByClause` is for optional sorting. When more than one
601607 -- `SortExpression` is specified, the later (right) values are used to sort
602608 -- rows that are equal according to the earlier (left) values.
@@ -613,7 +619,7 @@ data TableExpression
613619 }
614620
615621-- | Render a `TableExpression`
616−instance RenderSQL (TableExpression grp commons schemas params from) where
622+instance RenderSQL (TableExpression outer grp commons schemas params from) where
617623 renderSQL
618624 (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
619625 [ "FROM ", renderSQL frm'
@@ -622,8 +628,7 @@ instance RenderSQL (TableExpression grp commons schemas params from) where
622628 , renderSQL hvs'
623629 , renderOrderByClause srts'
624630 , renderLimits lims'
625− , renderOffsets offs'
626− ]
631+ , renderOffsets offs' ]
627632 where
628633 renderWheres = \case
629634 [] -> ""
@@ -646,16 +651,16 @@ instance RenderSQL (TableExpression grp commons schemas params from) where
646651-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
647652-- to match the left-to-right sequencing of their placement in SQL.
648653from
649− :: FromClause commons schemas params from -- ^ table reference
650− -> TableExpression 'Ungrouped commons schemas params from
651−from rels = TableExpression rels [] NoGroups NoHaving [] [] []
654+ :: FromClause outer commons schemas params from -- ^ table reference
655+ -> TableExpression outer 'Ungrouped commons schemas params from
656+from tab = TableExpression tab [] NoGroups NoHaving [] [] []
652657
653658-- | A `where_` is an endomorphism of `TableExpression`s which adds a
654659-- search condition to the `whereClause`.
655660where_
656− :: Condition 'Ungrouped commons schemas params from -- ^ filtering condition
657− -> TableExpression grp commons schemas params from
658− -> TableExpression grp commons schemas params from
661+ :: Condition outer 'Ungrouped commons schemas params from -- ^ filtering condition
662+ -> TableExpression outer grp commons schemas params from
663+ -> TableExpression outer grp commons schemas params from
659664where_ wh rels = rels {whereClause = wh : whereClause rels}
660665
661666-- | A `groupBy` is a transformation of `TableExpression`s which switches
@@ -664,8 +669,8 @@ where_ wh rels = rels {whereClause = wh : whereClause rels}
664669groupBy
665670 :: SListI bys
666671 => NP (By from) bys -- ^ grouped columns
667− -> TableExpression 'Ungrouped commons schemas params from
668− -> TableExpression ('Grouped bys) commons schemas params from
672+ -> TableExpression outer 'Ungrouped commons schemas params from
673+ -> TableExpression outer ('Grouped bys) commons schemas params from
669674groupBy bys rels = TableExpression
670675 { fromClause = fromClause rels
671676 , whereClause = whereClause rels
@@ -679,9 +684,9 @@ groupBy bys rels = TableExpression
679684-- | A `having` is an endomorphism of `TableExpression`s which adds a
680685-- search condition to the `havingClause`.
681686having
682− :: Condition ('Grouped bys) commons schemas params from -- ^ having condition
683− -> TableExpression ('Grouped bys) commons schemas params from
684− -> TableExpression ('Grouped bys) commons schemas params from
687+ :: Condition outer ('Grouped bys) commons schemas params from -- ^ having condition
688+ -> TableExpression outer ('Grouped bys) commons schemas params from
689+ -> TableExpression outer ('Grouped bys) commons schemas params from
685690having hv rels = rels
686691 { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
687692
@@ -692,16 +697,16 @@ instance OrderBy TableExpression where
692697-- `limitClause`.
693698limit
694699 :: Word64 -- ^ limit parameter
695− -> TableExpression grp commons schemas params from
696− -> TableExpression grp commons schemas params from
700+ -> TableExpression outer grp commons schemas params from
701+ -> TableExpression outer grp commons schemas params from
697702limit lim rels = rels {limitClause = lim : limitClause rels}
698703
699704-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
700705-- `offsetClause`.
701706offset
702707 :: Word64 -- ^ offset parameter
703− -> TableExpression grp commons schemas params from
704− -> TableExpression grp commons schemas params from
708+ -> TableExpression outer grp commons schemas params from
709+ -> TableExpression outer grp commons schemas params from
705710offset off rels = rels {offsetClause = off : offsetClause rels}
706711
707712{-----------------------------------------
@@ -710,56 +715,56 @@ JSON stuff
710715
711716unsafeSetOfFunction
712717 :: ByteString
713− -> Expression 'Ungrouped commons schemas params '[] ty
714− -> Query commons schemas params row
718+ -> Expression outer 'Ungrouped commons schemas params '[] ty
719+ -> Query outer commons schemas params row
715720unsafeSetOfFunction fun expr = UnsafeQuery $
716721 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
717722
718723-- | Expands the outermost JSON object into a set of key/value pairs.
719724jsonEach
720− :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
721− -> Query commons schemas params
725+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
726+ -> Query outer commons schemas params
722727 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
723728jsonEach = unsafeSetOfFunction "json_each"
724729
725730-- | Expands the outermost binary JSON object into a set of key/value pairs.
726731jsonbEach
727− :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
728− -> Query commons schemas params
732+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
733+ -> Query outer commons schemas params
729734 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
730735jsonbEach = unsafeSetOfFunction "jsonb_each"
731736
732737-- | Expands the outermost JSON object into a set of key/value pairs.
733738jsonEachAsText
734− :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
735− -> Query commons schemas params
739+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
740+ -> Query outer commons schemas params
736741 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
737742jsonEachAsText = unsafeSetOfFunction "json_each_text"
738743
739744-- | Expands the outermost binary JSON object into a set of key/value pairs.
740745jsonbEachAsText
741− :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
742− -> Query commons schemas params
746+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
747+ -> Query outer commons schemas params
743748 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
744749jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
745750
746751-- | Returns set of keys in the outermost JSON object.
747752jsonObjectKeys
748− :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
749− -> Query commons schemas params '["json_object_keys" ::: 'NotNull 'PGtext]
753+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
754+ -> Query outer commons schemas params '["json_object_keys" ::: 'NotNull 'PGtext]
750755jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
751756
752757-- | Returns set of keys in the outermost JSON object.
753758jsonbObjectKeys
754− :: Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
755− -> Query commons schemas params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
759+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
760+ -> Query outer commons schemas params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
756761jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
757762
758763unsafePopulateFunction
759764 :: ByteString
760765 -> TypeExpression schemas (nullity ('PGcomposite row))
761− -> Expression 'Ungrouped commons schemas params '[] ty
762− -> Query commons schemas params row
766+ -> Expression outer 'Ungrouped commons schemas params '[] ty
767+ -> Query outer commons schemas params row
763768unsafePopulateFunction fun ty expr = UnsafeQuery $
764769 "SELECT * FROM " <> fun <> "("
765770 <> "null::" <> renderSQL ty <> ", "
@@ -769,24 +774,24 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
769774-- type defined by the given table.
770775jsonPopulateRecord
771776 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
772− -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
773− -> Query commons schemas params row
777+ -> Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
778+ -> Query outer commons schemas params row
774779jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
775780
776781-- | Expands the binary JSON expression to a row whose columns match the record
777782-- type defined by the given table.
778783jsonbPopulateRecord
779784 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
780− -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
781− -> Query commons schemas params row
785+ -> Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
786+ -> Query outer commons schemas params row
782787jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
783788
784789-- | Expands the outermost array of objects in the given JSON expression to a
785790-- set of rows whose columns match the record type defined by the given table.
786791jsonPopulateRecordSet
787792 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
788− -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json array
789− -> Query commons schemas params row
793+ -> Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json array
794+ -> Query outer commons schemas params row
790795jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
791796
792797-- | Expands the outermost array of objects in the given binary JSON expression
@@ -794,16 +799,16 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
794799-- table.
795800jsonbPopulateRecordSet
796801 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
797− -> Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb array
798− -> Query commons schemas params row
802+ -> Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb array
803+ -> Query outer commons schemas params row
799804jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
800805
801806unsafeRecordFunction
802807 :: (SListI record, json `In` PGJsonType)
803808 => ByteString
804− -> Expression 'Ungrouped commons schemas params '[] (nullity json)
809+ -> Expression outer 'Ungrouped commons schemas params '[] (nullity json)
805810 -> NP (Aliased (TypeExpression schemas)) record
806− -> Query commons schemas params record
811+ -> Query outer commons schemas params record
807812unsafeRecordFunction fun expr types = UnsafeQuery $
808813 "SELECT * FROM " <> fun <> "("
809814 <> renderSQL expr <> ")"
@@ -816,33 +821,33 @@ unsafeRecordFunction fun expr types = UnsafeQuery $
816821-- | Builds an arbitrary record from a JSON object.
817822jsonToRecord
818823 :: SListI record
819− => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
824+ => Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
820825 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
821− -> Query commons schemas params record
826+ -> Query outer commons schemas params record
822827jsonToRecord = unsafeRecordFunction "json_to_record"
823828
824829-- | Builds an arbitrary record from a binary JSON object.
825830jsonbToRecord
826831 :: SListI record
827− => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
832+ => Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb object
828833 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
829− -> Query commons schemas params record
834+ -> Query outer commons schemas params record
830835jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
831836
832837-- | Builds an arbitrary set of records from a JSON array of objects.
833838jsonToRecordSet
834839 :: SListI record
835− => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json array
840+ => Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json array
836841 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
837− -> Query commons schemas params record
842+ -> Query outer commons schemas params record
838843jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
839844
840845-- | Builds an arbitrary set of records from a binary JSON array of objects.
841846jsonbToRecordSet
842847 :: SListI record
843− => Expression 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb array
848+ => Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjsonb) -- ^ jsonb array
844849 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
845− -> Query commons schemas params record
850+ -> Query outer commons schemas params record
846851jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
847852
848853{-----------------------------------------
@@ -853,38 +858,38 @@ FROM clauses
853858A `FromClause` can be a table name, or a derived table such
854859as a subquery, a @JOIN@ construct, or complex combinations of these.
855860-}
856−newtype FromClause commons schemas params from
861+newtype FromClause outer commons schemas params from
857862 = UnsafeFromClause { renderFromClause :: ByteString }
858863 deriving (GHC.Generic,Show,Eq,Ord,NFData)
859−instance RenderSQL (FromClause commons schemas params from) where
864+instance RenderSQL (FromClause outer commons schemas params from) where
860865 renderSQL = renderFromClause
861866
862867-- | A real `table` is a table from the database.
863868table
864869 :: (Has sch schemas schema, Has tab schema ('Table table))
865870 => Aliased (QualifiedAlias sch) (alias ::: tab)
866− -> FromClause commons schemas params '[alias ::: TableToRow table]
871+ -> FromClause outer commons schemas params '[alias ::: TableToRow table]
867872table (tab `As` alias) = UnsafeFromClause $
868873 renderSQL tab <+> "AS" <+> renderSQL alias
869874
870875-- | `subquery` derives a table from a `Query`.
871876subquery
872− :: Aliased (Query commons schemas params) query
873− -> FromClause commons schemas params '[query]
877+ :: Aliased (Query outer commons schemas params) query
878+ -> FromClause outer commons schemas params '[query]
874879subquery = UnsafeFromClause . renderAliased (parenthesized . renderQuery)
875880
876881-- | `view` derives a table from a `View`.
877882view
878883 :: (Has sch schemas schema, Has vw schema ('View view))
879884 => Aliased (QualifiedAlias sch) (alias ::: vw)
880− -> FromClause commons schemas params '[alias ::: view]
885+ -> FromClause outer commons schemas params '[alias ::: view]
881886view (vw `As` alias) = UnsafeFromClause $
882887 renderSQL vw <+> "AS" <+> renderSQL alias
883888
884889common
885890 :: Has cte commons common
886891 => Aliased Alias (alias ::: cte)
887− -> FromClause commons schemas params '[alias ::: common]
892+ -> FromClause outer commons schemas params '[alias ::: common]
888893common (cte `As` alias) = UnsafeFromClause $
889894 renderSQL cte <+> "AS" <+> renderSQL alias
890895
@@ -895,11 +900,11 @@ common (cte `As` alias) = UnsafeFromClause $
895900 have @n * m@ rows.
896901-}
897902crossJoin
898− :: FromClause commons schemas params right
903+ :: FromClause outer commons schemas params right
899904 -- ^ right
900− -> FromClause commons schemas params left
905+ -> FromClause outer commons schemas params left
901906 -- ^ left
902− -> FromClause commons schemas params (Join left right)
907+ -> FromClause outer commons schemas params (Join left right)
903908crossJoin right left = UnsafeFromClause $
904909 renderSQL left <+> "CROSS JOIN" <+> renderSQL right
905910
@@ -907,13 +912,13 @@ crossJoin right left = UnsafeFromClause $
907912the @on@ condition.
908913-}
909914innerJoin
910− :: FromClause commons schemas params right
915+ :: FromClause outer commons schemas params right
911916 -- ^ right
912− -> Condition 'Ungrouped commons schemas params (Join left right)
917+ -> Condition outer 'Ungrouped commons schemas params (Join left right)
913918 -- ^ @on@ condition
914− -> FromClause commons schemas params left
919+ -> FromClause outer commons schemas params left
915920 -- ^ left
916− -> FromClause commons schemas params (Join left right)
921+ -> FromClause outer commons schemas params (Join left right)
917922innerJoin right on left = UnsafeFromClause $
918923 renderSQL left <+> "INNER JOIN" <+> renderSQL right
919924 <+> "ON" <+> renderSQL on
@@ -924,13 +929,13 @@ innerJoin right on left = UnsafeFromClause $
924929 Thus, the joined table always has at least one row for each row in @left@.
925930-}
926931leftOuterJoin
927− :: FromClause commons schemas params right
932+ :: FromClause outer commons schemas params right
928933 -- ^ right
929− -> Condition 'Ungrouped commons schemas params (Join left right)
934+ -> Condition outer 'Ungrouped commons schemas params (Join left right)
930935 -- ^ @on@ condition
931− -> FromClause commons schemas params left
936+ -> FromClause outer commons schemas params left
932937 -- ^ left
933− -> FromClause commons schemas params (Join left (NullifyFrom right))
938+ -> FromClause outer commons schemas params (Join left (NullifyFrom right))
934939leftOuterJoin right on left = UnsafeFromClause $
935940 renderSQL left <+> "LEFT OUTER JOIN" <+> renderSQL right
936941 <+> "ON" <+> renderSQL on
@@ -942,13 +947,13 @@ leftOuterJoin right on left = UnsafeFromClause $
942947 have a row for each row in @right@.
943948-}
944949rightOuterJoin
945− :: FromClause commons schemas params right
950+ :: FromClause outer commons schemas params right
946951 -- ^ right
947− -> Condition 'Ungrouped commons schemas params (Join left right)
952+ -> Condition outer 'Ungrouped commons schemas params (Join left right)
948953 -- ^ @on@ condition
949− -> FromClause commons schemas params left
954+ -> FromClause outer commons schemas params left
950955 -- ^ left
951− -> FromClause commons schemas params (Join (NullifyFrom left) right)
956+ -> FromClause outer commons schemas params (Join (NullifyFrom left) right)
952957rightOuterJoin right on left = UnsafeFromClause $
953958 renderSQL left <+> "RIGHT OUTER JOIN" <+> renderSQL right
954959 <+> "ON" <+> renderSQL on
@@ -961,13 +966,13 @@ rightOuterJoin right on left = UnsafeFromClause $
961966 is added.
962967-}
963968fullOuterJoin
964− :: FromClause commons schemas params right
969+ :: FromClause outer commons schemas params right
965970 -- ^ right
966− -> Condition 'Ungrouped commons schemas params (Join left right)
971+ -> Condition outer 'Ungrouped commons schemas params (Join left right)
967972 -- ^ @on@ condition
968− -> FromClause commons schemas params left
973+ -> FromClause outer commons schemas params left
969974 -- ^ left
970− -> FromClause commons schemas params
975+ -> FromClause outer commons schemas params
971976 (Join (NullifyFrom left) (NullifyFrom right))
972977fullOuterJoin right on left = UnsafeFromClause $
973978 renderSQL left <+> "FULL OUTER JOIN" <+> renderSQL right
@@ -1036,17 +1041,17 @@ instance RenderSQL (GroupByClause grp from) where
10361041-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
10371042-- `TableExpression` must use `Having` whose conditions are combined with
10381043-- `.&&`.
1039−data HavingClause grp commons schemas params from where
1040− NoHaving :: HavingClause 'Ungrouped commons schemas params from
1044+data HavingClause outer grp commons schemas params from where
1045+ NoHaving :: HavingClause outer 'Ungrouped commons schemas params from
10411046 Having
1042− :: [Condition ('Grouped bys) commons schemas params from]
1043− -> HavingClause ('Grouped bys) commons schemas params from
1044−deriving instance Show (HavingClause grp commons schemas params from)
1045−deriving instance Eq (HavingClause grp commons schemas params from)
1046−deriving instance Ord (HavingClause grp commons schemas params from)
1047+ :: [Condition outer ('Grouped bys) commons schemas params from]
1048+ -> HavingClause outer ('Grouped bys) commons schemas params from
1049+deriving instance Show (HavingClause outer grp commons schemas params from)
1050+deriving instance Eq (HavingClause outer grp commons schemas params from)
1051+deriving instance Ord (HavingClause outer grp commons schemas params from)
10471052
10481053-- | Render a `HavingClause`.
1049−instance RenderSQL (HavingClause grp commons schemas params from) where
1054+instance RenderSQL (HavingClause outer grp commons schemas params from) where
10501055 renderSQL = \case
10511056 NoHaving -> ""
10521057 Having [] -> ""
@@ -1055,18 +1060,18 @@ instance RenderSQL (HavingClause grp commons schemas params from) where
10551060
10561061unsafeSubqueryExpression
10571062 :: ByteString
1058− -> Expression grp commons schemas params from ty
1059− -> Query commons schemas params '[alias ::: ty]
1060− -> Expression grp commons schemas params from (nullity 'PGbool)
1063+ -> Expression outer grp commons schemas params from ty
1064+ -> Query from commons schemas params '[alias ::: ty]
1065+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
10611066unsafeSubqueryExpression op x q = UnsafeExpression $
10621067 renderSQL x <+> op <+> parenthesized (renderSQL q)
10631068
10641069unsafeRowSubqueryExpression
10651070 :: SListI row
10661071 => ByteString
1067− -> NP (Aliased (Expression grp commons schemas params from)) row
1068− -> Query commons schemas params row
1069− -> Expression grp commons schemas params from (nullity 'PGbool)
1072+ -> NP (Aliased (Expression outer grp commons schemas params from)) row
1073+ -> Query from commons schemas params row
1074+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
10701075unsafeRowSubqueryExpression op xs q = UnsafeExpression $
10711076 renderSQL (row xs) <+> op <+> parenthesized (renderSQL q)
10721077
@@ -1079,9 +1084,9 @@ unsafeRowSubqueryExpression op xs q = UnsafeExpression $
10791084-- >>> printSQL $ true `in_` values_ (true `as` #foo)
10801085-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
10811086in_
1082− :: Expression grp commons schemas params from ty -- ^ expression
1083− -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1084− -> Expression grp commons schemas params from (nullity 'PGbool)
1087+ :: Expression outer grp commons schemas params from ty -- ^ expression
1088+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1089+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
10851090in_ = unsafeSubqueryExpression "IN"
10861091
10871092{- | The left-hand side of this form of `rowIn` is a row constructor.
@@ -1094,231 +1099,231 @@ is `true` if any equal subquery row is found.
10941099The result is `false` if no equal row is found
10951100(including the case where the subquery returns no rows).
10961101
1097−>>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1102+>>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
10981103>>> printSQL $ myRow `rowIn` values_ myRow
10991104ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11001105-}
11011106rowIn
11021107 :: SListI row
1103− => NP (Aliased (Expression grp commons schemas params from)) row -- ^ row constructor
1104− -> Query commons schemas params row -- ^ subquery
1105− -> Expression grp commons schemas params from (nullity 'PGbool)
1108+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1109+ -> Query from commons schemas params row -- ^ subquery
1110+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11061111rowIn = unsafeRowSubqueryExpression "IN"
11071112
11081113-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
11091114-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11101115eqAll
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)
1116+ :: Expression outer grp commons schemas params from ty -- ^ expression
1117+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1118+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11141119eqAll = unsafeSubqueryExpression "= ALL"
11151120
1116−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1121+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11171122-- >>> printSQL $ myRow `rowEqAll` values_ myRow
11181123-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11191124rowEqAll
11201125 :: 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)
1126+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1127+ -> Query from commons schemas params row -- ^ subquery
1128+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11241129rowEqAll = unsafeRowSubqueryExpression "= ALL"
11251130
11261131-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
11271132-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11281133eqAny
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)
1134+ :: Expression outer grp commons schemas params from ty -- ^ expression
1135+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1136+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11321137eqAny = unsafeSubqueryExpression "= ANY"
11331138
1134−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1139+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11351140-- >>> printSQL $ myRow `rowEqAny` values_ myRow
11361141-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11371142rowEqAny
11381143 :: 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)
1144+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1145+ -> Query from commons schemas params row -- ^ subquery
1146+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11421147rowEqAny = unsafeRowSubqueryExpression "= ANY"
11431148
11441149-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
11451150-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11461151neqAll
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)
1152+ :: Expression outer grp commons schemas params from ty -- ^ expression
1153+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1154+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11501155neqAll = unsafeSubqueryExpression "<> ALL"
11511156
1152−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1157+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11531158-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
11541159-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11551160rowNeqAll
11561161 :: 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)
1162+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1163+ -> Query from commons schemas params row -- ^ subquery
1164+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11601165rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
11611166
11621167-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
11631168-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11641169neqAny
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)
1170+ :: Expression outer grp commons schemas params from ty -- ^ expression
1171+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1172+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11681173neqAny = unsafeSubqueryExpression "<> ANY"
11691174
1170−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1175+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11711176-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
11721177-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11731178rowNeqAny
11741179 :: 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)
1180+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1181+ -> Query from commons schemas params row -- ^ subquery
1182+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11781183rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
11791184
11801185-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
11811186-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11821187allLt
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)
1188+ :: Expression outer grp commons schemas params from ty -- ^ expression
1189+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1190+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11861191allLt = unsafeSubqueryExpression "ALL <"
11871192
1188−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1193+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11891194-- >>> printSQL $ myRow `rowLtAll` values_ myRow
11901195-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11911196rowLtAll
11921197 :: 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)
1198+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1199+ -> Query from commons schemas params row -- ^ subquery
1200+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
11961201rowLtAll = unsafeRowSubqueryExpression "ALL <"
11971202
11981203-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
11991204-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12001205ltAny
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)
1206+ :: Expression outer grp commons schemas params from ty -- ^ expression
1207+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1208+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12041209ltAny = unsafeSubqueryExpression "ANY <"
12051210
1206−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1211+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12071212-- >>> printSQL $ myRow `rowLtAll` values_ myRow
12081213-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12091214rowLtAny
12101215 :: 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)
1216+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1217+ -> Query from commons schemas params row -- ^ subquery
1218+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12141219rowLtAny = unsafeRowSubqueryExpression "ANY <"
12151220
12161221-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
12171222-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12181223lteAll
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)
1224+ :: Expression outer grp commons schemas params from ty -- ^ expression
1225+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1226+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12221227lteAll = unsafeSubqueryExpression "<= ALL"
12231228
1224−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1229+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12251230-- >>> printSQL $ myRow `rowLteAll` values_ myRow
12261231-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12271232rowLteAll
12281233 :: 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)
1234+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1235+ -> Query from commons schemas params row -- ^ subquery
1236+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12321237rowLteAll = unsafeRowSubqueryExpression "<= ALL"
12331238
12341239-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
12351240-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12361241lteAny
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)
1242+ :: Expression outer grp commons schemas params from ty -- ^ expression
1243+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1244+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12401245lteAny = unsafeSubqueryExpression "<= ANY"
12411246
1242−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1247+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12431248-- >>> printSQL $ myRow `rowLteAny` values_ myRow
12441249-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12451250rowLteAny
12461251 :: 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)
1252+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1253+ -> Query from commons schemas params row -- ^ subquery
1254+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12501255rowLteAny = unsafeRowSubqueryExpression "<= ANY"
12511256
12521257-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
12531258-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12541259gtAll
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)
1260+ :: Expression outer grp commons schemas params from ty -- ^ expression
1261+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1262+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12581263gtAll = unsafeSubqueryExpression "> ALL"
12591264
1260−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1265+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12611266-- >>> printSQL $ myRow `rowGtAll` values_ myRow
12621267-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12631268rowGtAll
12641269 :: 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)
1270+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1271+ -> Query from commons schemas params row -- ^ subquery
1272+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12681273rowGtAll = unsafeRowSubqueryExpression "> ALL"
12691274
12701275-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
12711276-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12721277gtAny
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)
1278+ :: Expression outer grp commons schemas params from ty -- ^ expression
1279+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1280+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12761281gtAny = unsafeSubqueryExpression "> ANY"
12771282
1278−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1283+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12791284-- >>> printSQL $ myRow `rowGtAny` values_ myRow
12801285-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12811286rowGtAny
12821287 :: 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)
1288+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1289+ -> Query from commons schemas params row -- ^ subquery
1290+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12861291rowGtAny = unsafeRowSubqueryExpression "> ANY"
12871292
12881293-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
12891294-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12901295gteAll
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)
1296+ :: Expression outer grp commons schemas params from ty -- ^ expression
1297+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1298+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
12941299gteAll = unsafeSubqueryExpression ">= ALL"
12951300
1296−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1301+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12971302-- >>> printSQL $ myRow `rowGteAll` values_ myRow
12981303-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12991304rowGteAll
13001305 :: 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)
1306+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1307+ -> Query from commons schemas params row -- ^ subquery
1308+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
13041309rowGteAll = unsafeRowSubqueryExpression ">= ALL"
13051310
13061311-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
13071312-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
13081313gteAny
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)
1314+ :: Expression outer grp commons schemas params from ty -- ^ expression
1315+ -> Query from commons schemas params '[alias ::: ty] -- ^ subquery
1316+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
13121317gteAny = unsafeSubqueryExpression ">= ANY"
13131318
1314−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1319+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression outer grp commons schemas params from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
13151320-- >>> printSQL $ myRow `rowGteAny` values_ myRow
13161321-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
13171322rowGteAny
13181323 :: 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)
1324+ => NP (Aliased (Expression outer grp commons schemas params from)) row -- ^ row constructor
1325+ -> Query from commons schemas params row -- ^ subquery
1326+ -> Expression outer grp commons schemas params from (nullity 'PGbool)
13221327rowGteAny = unsafeRowSubqueryExpression ">= ANY"
13231328
13241329-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
@@ -1360,7 +1365,7 @@ class With statement where
13601365 -> statement commons1 schemas params row
13611366 -- ^ larger query
13621367 -> statement commons0 schemas params row
1363−instance With Query where
1368+instance With (Query outer) where
13641369 with Done query = query
13651370 with ctes query = UnsafeQuery $
13661371 "WITH" <+> renderSQL ctes <+> renderSQL query