@@ -34,6 +34,17 @@ Squeal expressions are the atoms used to build statements.
34module Squeal.PostgreSQL.Expression
34module Squeal.PostgreSQL.Expression
35 ( -- * Expression
35 ( -- * Expression
36 Expression (..)
36 Expression (..)
37 , HasParameter (parameter)
48 , HasParameter (parameter)
39 -- ** Null
50 -- ** Null
@@ -47,15 +58,14 @@ module Squeal.PostgreSQL.Expression
48 -- ** Collections
59 -- ** Collections
50 , cardinality
63 , cardinality
54 -- ** Functions
68 -- ** Functions
58− , unsafeVariadicFunction
@@ -65,6 +75,7 @@ module Squeal.PostgreSQL.Expression
65 , ceiling_
75 , ceiling_
66 , greatest
76 , greatest
68 -- ** Conditions
79 -- ** Conditions
@@ -93,16 +104,19 @@ module Squeal.PostgreSQL.Expression
93 , isUnknown
104 , isUnknown
94 , isNotUnknown
105 , isNotUnknown
95 -- ** Time
106 -- ** Time
96 , currentDate
108 , currentDate
97 , currentTime
109 , currentTime
98 , currentTimestamp
110 , currentTimestamp
99 , localTime
111 , localTime
100 , localTimestamp
112 , localTimestamp
101− , TimeOp (..)
113+ , now
102 , makeDate
114 , makeDate
103 , makeTime
115 , makeTime
104 , makeTimestamp
116 , makeTimestamp
105 , makeTimestamptz
117 , makeTimestamptz
106 -- ** Text
120 -- ** Text
@@ -116,8 +130,6 @@ module Squeal.PostgreSQL.Expression
118 -- *** Jsonb operators
132 -- *** Jsonb operators
@@ -132,6 +144,7 @@ module Squeal.PostgreSQL.Expression
132 , rowToJson
144 , rowToJson
133 , jsonBuildArray
145 , jsonBuildArray
134 , jsonbBuildArray
146 , jsonbBuildArray
135 , jsonBuildObject
148 , jsonBuildObject
136 , jsonbBuildObject
149 , jsonbBuildObject
137 , jsonObject
150 , jsonObject
@@ -151,6 +164,28 @@ module Squeal.PostgreSQL.Expression
151 , jsonbSet
164 , jsonbSet
152 , jsonbInsert
165 , jsonbInsert
153 , jsonbPretty
166 , jsonbPretty
178+ , websearchToTSquery
154 -- ** Aggregation
189 -- ** Aggregation
155 , Aggregate (..)
190 , Aggregate (..)
156 , Distinction (..)
191 , Distinction (..)
@@ -211,10 +246,11 @@ module Squeal.PostgreSQL.Expression
212 , vararray
247 , vararray
213 , fixarray
248 , fixarray
214 -- * Re-export
251 -- * Re-export
216 , NP (..)
253 , NP (..)
@@ -223,12 +259,12 @@ import Control.DeepSeq
223import Data.ByteString (ByteString)
259import Data.ByteString (ByteString)
224import Data.ByteString.Lazy (toStrict)
260import Data.ByteString.Lazy (toStrict)
225import Data.Function ((&))
261import Data.Function ((&))
226import Data.Semigroup hiding (All)
263import Data.Semigroup hiding (All)
227import qualified Data.Aeson as JSON
264import qualified Data.Aeson as JSON
228import Data.String
265import Data.String
229import Data.Word
266import Data.Word
230import Generics.SOP hiding (All, from)
267import Generics.SOP hiding (All, from)
231−import GHC.Generics ((:*:) (..))
232import GHC.OverloadedLabels
268import GHC.OverloadedLabels
233import GHC.TypeLits
269import GHC.TypeLits
234import Numeric
270import Numeric
@@ -257,18 +293,82 @@ and other operations.
258newtype Expression
294newtype Expression
259 (outer :: FromType)
295 (outer :: FromType)
261 (commons :: FromType)
296 (commons :: FromType)
262 (schemas :: SchemasType)
298 (schemas :: SchemasType)
263 (params :: [NullityType])
299 (params :: [NullityType])
264 (from :: FromType)
300 (from :: FromType)
265 (ty :: NullityType)
301 (ty :: NullityType)
266 = UnsafeExpression { renderExpression :: ByteString }
302 = UnsafeExpression { renderExpression :: ByteString }
267 deriving (GHC.Generic,Show,Eq,Ord,NFData)
303 deriving (GHC.Generic,Show,Eq,Ord,NFData)
269−instance RenderSQL (Expression outer grp commons schemas params from ty) where
304+instance RenderSQL (Expression outer commons grp schemas params from ty) where
270 renderSQL = renderExpression
305 renderSQL = renderExpression
307+-- | An `Expr` is a closed `Expression`.
308+-- It is a F`RankNType` but don't be scared.
309+-- Think of it as an expression which sees no
310+-- namespaces, so you can't use parameters
311+-- or alias references. It can be used as
312+-- a simple piece of more complex `Expression`s.
314+ = forall outer commons grp schemas params from
315+ . Expression outer commons grp schemas params from x
316+ -- ^ cannot reference aliases
318+-- | A `RankNType` for binary operators.
319+type Operator x1 x2 y
320+ = forall outer commons grp schemas params from
321+ . Expression outer commons grp schemas params from x1
323+ -> Expression outer commons grp schemas params from x2
325+ -> Expression outer commons grp schemas params from y
328+-- | A `RankNType` for functions with a single argument.
329+-- These could be either function calls or unary operators.
330+-- This is a subtype of the usual Haskell function type `Prelude.->`,
331+-- indeed a subcategory as it is closed under the usual
332+-- `Prelude..` and `Prelude.id`.
334+ = forall outer commons grp schemas params from
335+ . Expression outer commons grp schemas params from x
337+ -> Expression outer commons grp schemas params from y
340+{- | A `RankNType` for functions with a fixed-length list of heterogeneous arguments.
341+Use the `*:` operator to end your argument lists, like so.
343+>>> printSQL (unsafeFunctionHet "fun" (true :* false :* localTime *: true))
344+fun(TRUE, FALSE, LOCALTIME, TRUE)
346+type FunctionHet xs y
347+ = forall outer commons grp schemas params from
348+ . NP (Expression outer commons grp schemas params from) xs
350+ -> Expression outer commons grp schemas params from y
353+{- | A `RankNType` for functions with a variable-length list of
354+homogeneous arguments and at least 1 more argument.
356+type FunctionHom x0 x1 y
357+ = forall outer commons grp schemas params from
358+ . [Expression outer commons grp schemas params from x0]
360+ -> Expression outer commons grp schemas params from x1
361+ -- ^ must have at least 1 input
362+ -> Expression outer commons grp schemas params from y
365+{- | >>> printSQL (unsafeFunctionHom "greatest" [true, null_] false)
366+greatest(TRUE, NULL, FALSE)
368+unsafeFunctionHom :: ByteString -> FunctionHom x0 x1 y
369+unsafeFunctionHom fun xs x = UnsafeExpression $ fun <> parenthesized
370+ (commaSeparated (renderSQL <$> xs) <> ", " <> renderSQL x)
272{- | A `HasParameter` constraint is used to indicate a value that is
372{- | A `HasParameter` constraint is used to indicate a value that is
273supplied externally to a SQL statement.
373supplied externally to a SQL statement.
274`Squeal.PostgreSQL.PQ.manipulateParams`,
374`Squeal.PostgreSQL.PQ.manipulateParams`,
@@ -284,12 +384,12 @@ class KnownNat n => HasParameter
284 | n params -> ty where
384 | n params -> ty where
285 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
385 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
287− -- >>> let expr = parameter @1 int4 :: Expression outer grp '[] schemas '[ 'Null 'PGint4] from ('Null 'PGint4)
387+ -- >>> let expr = parameter @1 int4 :: Expression outer '[] grp schemas '[ 'Null 'PGint4] from ('Null 'PGint4)
288 -- >>> printSQL expr
388 -- >>> printSQL expr
289 -- ($1 :: int4)
389 -- ($1 :: int4)
290 parameter
390 parameter
291 :: TypeExpression schemas ty
391 :: TypeExpression schemas ty
292− -> Expression outer grp commons schemas params from ty
392+ -> Expression outer commons grp schemas params from ty
293 parameter ty = UnsafeExpression $ parenthesized $
393 parameter ty = UnsafeExpression $ parenthesized $
294 "$" <> renderNat @n <+> "::"
394 "$" <> renderNat @n <+> "::"
295 <+> renderSQL ty
395 <+> renderSQL ty
@@ -300,44 +400,44 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
300-- | `param` takes a `Nat` using type application and for basic types,
400-- | `param` takes a `Nat` using type application and for basic types,
301-- infers a `TypeExpression`.
401-- infers a `TypeExpression`.
303−-- >>> let expr = param @1 :: Expression outer grp commons schemas '[ 'Null 'PGint4] from ('Null 'PGint4)
403+-- >>> let expr = param @1 :: Expression outer commons grp schemas '[ 'Null 'PGint4] from ('Null 'PGint4)
304-- >>> printSQL expr
404-- >>> printSQL expr
305-- ($1 :: int4)
405-- ($1 :: int4)
307 :: forall n outer commons schemas params from grp ty
407 :: forall n outer commons schemas params from grp ty
308 . (PGTyped schemas ty, HasParameter n params ty)
408 . (PGTyped schemas ty, HasParameter n params ty)
309− => Expression outer grp commons schemas params from ty -- ^ param
409+ => Expression outer commons grp schemas params from ty -- ^ param
310param = parameter @n (pgtype @schemas)
410param = parameter @n (pgtype @schemas)
312instance (HasUnique tab (Join outer from) row, Has col row ty)
412instance (HasUnique tab (Join outer from) row, Has col row ty)
313− => IsLabel col (Expression outer 'Ungrouped commons schemas params from ty) where
413+ => IsLabel col (Expression outer commons 'Ungrouped schemas params from ty) where
314 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
414 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
315instance (HasUnique tab (Join outer from) row, Has col row ty, tys ~ '[ty])
415instance (HasUnique tab (Join outer from) row, Has col row ty, tys ~ '[ty])
316− => IsLabel col (NP (Expression outer 'Ungrouped commons schemas params from) tys) where
416+ => IsLabel col (NP (Expression outer commons 'Ungrouped schemas params from) tys) where
317 fromLabel = fromLabel @col :* Nil
417 fromLabel = fromLabel @col :* Nil
318instance (HasUnique tab (Join outer from) row, Has col row ty, column ~ (col ::: ty))
418instance (HasUnique tab (Join outer from) row, Has col row ty, column ~ (col ::: ty))
319 => IsLabel col
419 => IsLabel col
320− (Aliased (Expression outer 'Ungrouped commons schemas params from) column) where
420+ (Aliased (Expression outer commons 'Ungrouped schemas params from) column) where
321 fromLabel = fromLabel @col `As` Alias
421 fromLabel = fromLabel @col `As` Alias
322instance (HasUnique tab (Join outer from) row, Has col row ty, columns ~ '[col ::: ty])
422instance (HasUnique tab (Join outer from) row, Has col row ty, columns ~ '[col ::: ty])
323 => IsLabel col
423 => IsLabel col
324− (NP (Aliased (Expression outer 'Ungrouped commons schemas params from)) columns) where
424+ (NP (Aliased (Expression outer commons 'Ungrouped schemas params from)) columns) where
325 fromLabel = fromLabel @col :* Nil
425 fromLabel = fromLabel @col :* Nil
327instance (Has tab (Join outer from) row, Has col row ty)
427instance (Has tab (Join outer from) row, Has col row ty)
328− => IsQualified tab col (Expression outer 'Ungrouped commons schemas params from ty) where
428+ => IsQualified tab col (Expression outer commons 'Ungrouped schemas params from ty) where
329 tab ! col = UnsafeExpression $
429 tab ! col = UnsafeExpression $
330 renderSQL tab <> "." <> renderSQL col
430 renderSQL tab <> "." <> renderSQL col
331instance (Has tab (Join outer from) row, Has col row ty, tys ~ '[ty])
431instance (Has tab (Join outer from) row, Has col row ty, tys ~ '[ty])
332− => IsQualified tab col (NP (Expression outer 'Ungrouped commons schemas params from) tys) where
432+ => IsQualified tab col (NP (Expression outer commons 'Ungrouped schemas params from) tys) where
333 tab ! col = tab ! col :* Nil
433 tab ! col = tab ! col :* Nil
334instance (Has tab (Join outer from) row, Has col row ty, column ~ (col ::: ty))
434instance (Has tab (Join outer from) row, Has col row ty, column ~ (col ::: ty))
335 => IsQualified tab col
435 => IsQualified tab col
336− (Aliased (Expression outer 'Ungrouped commons schemas params from) column) where
436+ (Aliased (Expression outer commons 'Ungrouped schemas params from) column) where
337 tab ! col = tab ! col `As` col
437 tab ! col = tab ! col `As` col
338instance (Has tab (Join outer from) row, Has col row ty, columns ~ '[col ::: ty])
438instance (Has tab (Join outer from) row, Has col row ty, columns ~ '[col ::: ty])
339 => IsQualified tab col
439 => IsQualified tab col
340− (NP (Aliased (Expression outer 'Ungrouped commons schemas params from)) columns) where
440+ (NP (Aliased (Expression outer commons 'Ungrouped schemas params from)) columns) where
341 tab ! col = tab ! col :* Nil
441 tab ! col = tab ! col :* Nil
@@ -345,7 +445,7 @@ instance
345 , Has col row ty
445 , Has col row ty
346 , GroupedBy tab col bys
446 , GroupedBy tab col bys
347 ) => IsLabel col
447 ) => IsLabel col
348− (Expression outer ('Grouped bys) commons schemas params from ty) where
448+ (Expression outer commons ('Grouped bys) schemas params from ty) where
349 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
449 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
351 ( HasUnique tab (Join outer from) row
451 ( HasUnique tab (Join outer from) row
@@ -353,7 +453,7 @@ instance
353 , GroupedBy tab col bys
453 , GroupedBy tab col bys
354 , tys ~ '[ty]
454 , tys ~ '[ty]
355 ) => IsLabel col
455 ) => IsLabel col
356− (NP (Expression outer ('Grouped bys) commons schemas params from) tys) where
456+ (NP (Expression outer commons ('Grouped bys) schemas params from) tys) where
357 fromLabel = fromLabel @col :* Nil
457 fromLabel = fromLabel @col :* Nil
359 ( HasUnique tab (Join outer from) row
459 ( HasUnique tab (Join outer from) row
@@ -361,7 +461,7 @@ instance
361 , GroupedBy tab col bys
461 , GroupedBy tab col bys
362 , column ~ (col ::: ty)
462 , column ~ (col ::: ty)
363 ) => IsLabel col
463 ) => IsLabel col
364− (Aliased (Expression outer ('Grouped bys) commons schemas params from) column) where
464+ (Aliased (Expression outer commons ('Grouped bys) schemas params from) column) where
365 fromLabel = fromLabel @col `As` Alias
465 fromLabel = fromLabel @col `As` Alias
367 ( HasUnique tab (Join outer from) row
467 ( HasUnique tab (Join outer from) row
@@ -369,7 +469,7 @@ instance
369 , GroupedBy tab col bys
469 , GroupedBy tab col bys
370 , columns ~ '[col ::: ty]
470 , columns ~ '[col ::: ty]
371 ) => IsLabel col
471 ) => IsLabel col
372− (NP (Aliased (Expression outer ('Grouped bys) commons schemas params from)) columns) where
472+ (NP (Aliased (Expression outer commons ('Grouped bys) schemas params from)) columns) where
373 fromLabel = fromLabel @col :* Nil
473 fromLabel = fromLabel @col :* Nil
@@ -377,7 +477,7 @@ instance
377 , Has col row ty
477 , Has col row ty
378 , GroupedBy tab col bys
478 , GroupedBy tab col bys
379 ) => IsQualified tab col
479 ) => IsQualified tab col
380− (Expression outer ('Grouped bys) commons schemas params from ty) where
480+ (Expression outer commons ('Grouped bys) schemas params from ty) where
381 tab ! col = UnsafeExpression $
481 tab ! col = UnsafeExpression $
382 renderSQL tab <> "." <> renderSQL col
482 renderSQL tab <> "." <> renderSQL col
@@ -386,7 +486,7 @@ instance
386 , GroupedBy tab col bys
486 , GroupedBy tab col bys
387 , tys ~ '[ty]
487 , tys ~ '[ty]
388 ) => IsQualified tab col
488 ) => IsQualified tab col
389− (NP (Expression outer ('Grouped bys) commons schemas params from) tys) where
489+ (NP (Expression outer commons ('Grouped bys) schemas params from) tys) where
390 tab ! col = tab ! col :* Nil
490 tab ! col = tab ! col :* Nil
392 ( Has tab (Join outer from) row
492 ( Has tab (Join outer from) row
@@ -394,7 +494,7 @@ instance
394 , GroupedBy tab col bys
494 , GroupedBy tab col bys
395 , column ~ (col ::: ty)
495 , column ~ (col ::: ty)
396 ) => IsQualified tab col
496 ) => IsQualified tab col
397− (Aliased (Expression outer ('Grouped bys) commons schemas params from) column) where
497+ (Aliased (Expression outer commons ('Grouped bys) schemas params from) column) where
398 tab ! col = tab ! col `As` col
498 tab ! col = tab ! col `As` col
400 ( Has tab (Join outer from) row
500 ( Has tab (Join outer from) row
@@ -402,35 +502,28 @@ instance
402 , GroupedBy tab col bys
502 , GroupedBy tab col bys
403 , columns ~ '[col ::: ty]
503 , columns ~ '[col ::: ty]
404 ) => IsQualified tab col
504 ) => IsQualified tab col
405− (NP (Aliased (Expression outer ('Grouped bys) commons schemas params from)) columns) where
505+ (NP (Aliased (Expression outer commons ('Grouped bys) schemas params from)) columns) where
406 tab ! col = tab ! col :* Nil
506 tab ! col = tab ! col :* Nil
408-- | analagous to `Nothing`
508-- | analagous to `Nothing`
410-- >>> printSQL null_
510-- >>> printSQL null_
412−null_ :: Expression outer grp commons schemas params from ('Null ty)
512+null_ :: Expr ('Null ty)
413null_ = UnsafeExpression "NULL"
513null_ = UnsafeExpression "NULL"
415-- | analagous to `Just`
515-- | analagous to `Just`
417-- >>> printSQL $ notNull true
517-- >>> printSQL $ notNull true
419−notNull
519+notNull :: 'NotNull ty :--> 'Null ty
420− :: Expression outer grp commons schemas params from ('NotNull ty)
421− -> Expression outer grp commons schemas params from ('Null ty)
422notNull = UnsafeExpression . renderSQL
520notNull = UnsafeExpression . renderSQL
424-- | return the leftmost value which is not NULL
522-- | return the leftmost value which is not NULL
426-- >>> printSQL $ coalesce [null_, true] false
524-- >>> printSQL $ coalesce [null_, true] false
427-- COALESCE(NULL, TRUE, FALSE)
525-- COALESCE(NULL, TRUE, FALSE)
428−coalesce
526+coalesce :: FunctionHom ('Null ty) ('NotNull ty) ('NotNull ty)
429− :: [Expression outer grp commons schemas params from ('Null ty)]
430− -- ^ @NULL@s may be present
431− -> Expression outer grp commons schemas params from ('NotNull ty)
432− -- ^ @NULL@ is absent
433− -> Expression outer grp commons schemas params from ('NotNull ty)
434coalesce nullxs notNullx = UnsafeExpression $
527coalesce nullxs notNullx = UnsafeExpression $
435 "COALESCE" <> parenthesized (commaSeparated
528 "COALESCE" <> parenthesized (commaSeparated
436 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
529 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
@@ -440,26 +533,20 @@ coalesce nullxs notNullx = UnsafeExpression $
440-- >>> printSQL $ fromNull true null_
533-- >>> printSQL $ fromNull true null_
441-- COALESCE(NULL, TRUE)
534-- COALESCE(NULL, TRUE)
443− :: Expression outer grp commons schemas params from ('NotNull ty)
536+ :: Expression outer commons grp schemas params from ('NotNull ty)
444 -- ^ what to convert @NULL@ to
537 -- ^ what to convert @NULL@ to
445− -> Expression outer grp commons schemas params from ('Null ty)
538+ -> Expression outer commons grp schemas params from ('Null ty)
446− -> Expression outer grp commons schemas params from ('NotNull ty)
539+ -> Expression outer commons grp schemas params from ('NotNull ty)
447fromNull notNullx nullx = coalesce [nullx] notNullx
540fromNull notNullx nullx = coalesce [nullx] notNullx
449-- | >>> printSQL $ null_ & isNull
542-- | >>> printSQL $ null_ & isNull
450-- NULL IS NULL
543-- NULL IS NULL
451−isNull
544+isNull :: 'Null ty :--> null 'PGbool
452− :: Expression outer grp commons schemas params from ('Null ty)
453− -- ^ possibly @NULL@
454− -> Condition outer grp commons schemas params from
455isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
545isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
457-- | >>> printSQL $ null_ & isNotNull
547-- | >>> printSQL $ null_ & isNotNull
458-- NULL IS NOT NULL
548-- NULL IS NOT NULL
459−isNotNull
549+isNotNull :: 'Null ty :--> null 'PGbool
460− :: Expression outer grp commons schemas params from ('Null ty)
461− -- ^ possibly @NULL@
462− -> Condition outer grp commons schemas params from
463isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
550isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
465-- | analagous to `maybe` using @IS NULL@
552-- | analagous to `maybe` using @IS NULL@
@@ -467,13 +554,13 @@ isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
467-- >>> printSQL $ matchNull true not_ null_
554-- >>> printSQL $ matchNull true not_ null_
468-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
555-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
470− :: Expression outer grp commons schemas params from (nullty)
557+ :: Expression outer commons grp schemas params from (nullty)
471 -- ^ what to convert @NULL@ to
558 -- ^ what to convert @NULL@ to
472− -> ( Expression outer grp commons schemas params from ('NotNull ty)
559+ -> ( Expression outer commons grp schemas params from ('NotNull ty)
473− -> Expression outer grp commons schemas params from (nullty) )
560+ -> Expression outer commons grp schemas params from (nullty) )
474 -- ^ function to perform when @NULL@ is absent
561 -- ^ function to perform when @NULL@ is absent
475− -> Expression outer grp commons schemas params from ('Null ty)
562+ -> Expression outer commons grp schemas params from ('Null ty)
476− -> Expression outer grp commons schemas params from (nullty)
563+ -> Expression outer commons grp schemas params from (nullty)
477matchNull y f x = ifThenElse (isNull x) y
564matchNull y f x = ifThenElse (isNull x) y
478 (f (UnsafeExpression (renderSQL x)))
565 (f (UnsafeExpression (renderSQL x)))
@@ -481,46 +568,87 @@ matchNull y f x = ifThenElse (isNull x) y
481`nullIf` gives @NULL@.
568`nullIf` gives @NULL@.
483>>> :set -XTypeApplications -XDataKinds
570>>> :set -XTypeApplications -XDataKinds
484−>>> let expr = nullIf false (param @1) :: Expression outer grp commons schemas '[ 'NotNull 'PGbool] from ('Null 'PGbool)
571+>>> let expr = nullIf (false *: param @1) :: Expression outer commons grp schemas '[ 'NotNull 'PGbool] from ('Null 'PGbool)
485>>> printSQL expr
572>>> printSQL expr
486−NULL IF (FALSE, ($1 :: bool))
573+NULLIF(FALSE, ($1 :: bool))
488−nullIf
575+nullIf :: FunctionHet '[ 'NotNull ty, 'NotNull ty] ('Null ty)
489− :: Expression outer grp commons schemas params from ('NotNull ty)
576+nullIf = unsafeFunctionHet "NULLIF"
490− -- ^ @NULL@ is absent
491− -> Expression outer grp commons schemas params from ('NotNull ty)
492− -- ^ @NULL@ is absent
493− -> Expression outer grp commons schemas params from ('Null ty)
494−nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
495− (renderSQL x <> ", " <> renderSQL y)
497-- | >>> printSQL $ array [null_, false, true]
578-- | >>> printSQL $ array [null_, false, true]
498-- ARRAY[NULL, FALSE, TRUE]
579-- ARRAY[NULL, FALSE, TRUE]
500− :: [Expression outer grp commons schemas params from ty]
581+ :: [Expression outer commons grp schemas params from ty]
501 -- ^ array elements
582 -- ^ array elements
502− -> Expression outer grp commons schemas params from (nullity ('PGvararray ty))
583+ -> Expression outer commons grp schemas params from (null ('PGvararray ty))
503−array xs = UnsafeExpression $
584+array xs = UnsafeExpression $ "ARRAY" <>
504− "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
585+ bracketed (commaSeparated (renderSQL <$> xs))
587+{- | construct a 1-dimensional fixed length array
589+>>> printSQL $ array1 (null_ :* false *: true)
590+ARRAY[NULL, FALSE, TRUE]
592+>>> :type array1 (null_ :* false *: true)
593+array1 (null_ :* false *: true)
601+ (null ('PGfixarray '[3] ('Null 'PGbool)))
604+ :: (n ~ Length tys, SOP.All ((~) ty) tys)
605+ => NP (Expression outer commons grp schemas params from) tys
606+ -> Expression outer commons grp schemas params from (null ('PGfixarray '[n] ty))
607+array1 xs = UnsafeExpression $ "ARRAY" <>
608+ bracketed (renderCommaSeparated renderSQL xs)
610+{- | construct a 2-dimensional fixed length array
612+>>> printSQL $ array2 ((null_ :* false *: true) *: (false :* null_ *: true))
613+ARRAY[[NULL, FALSE, TRUE], [FALSE, NULL, TRUE]]
615+>>> :type array2 ((null_ :* false *: true) *: (false :* null_ *: true))
616+array2 ((null_ :* false *: true) *: (false :* null_ *: true))
624+ (null ('PGfixarray '[2, 3] ('Null 'PGbool)))
627+ :: ( SOP.All ((~) tys) tyss
628+ , SOP.All SOP.SListI tyss
630+ , SOP.All ((~) ty) tys
632+ => NP (NP (Expression outer commons grp schemas params from)) tyss
633+ -> Expression outer commons grp schemas params from (null ('PGfixarray '[n1,n2] ty))
634+array2 xss = UnsafeExpression $ "ARRAY" <>
635+ bracketed (renderCommaSeparatedConstraint @SOP.SListI (bracketed . renderCommaSeparated renderSQL) xss)
506-- | >>> printSQL $ cardinality (array [null_, false, true])
637-- | >>> printSQL $ cardinality (array [null_, false, true])
507-- cardinality(ARRAY[NULL, FALSE, TRUE])
638-- cardinality(ARRAY[NULL, FALSE, TRUE])
508−cardinality
639+cardinality :: null ('PGvararray ty) :--> null 'PGint8
509− :: Expression outer grp commons schemas params from (nullity ('PGvararray ty))
510− -> Expression outer grp commons schemas params from (nullity 'PGint8)
511cardinality = unsafeFunction "cardinality"
640cardinality = unsafeFunction "cardinality"
513-- | >>> printSQL $ array [null_, false, true] & index 2
642-- | >>> printSQL $ array [null_, false, true] & index 2
514-- (ARRAY[NULL, FALSE, TRUE])[2]
643-- (ARRAY[NULL, FALSE, TRUE])[2]
516 :: Word64 -- ^ index
645 :: Word64 -- ^ index
517− -> Expression outer grp commons schemas params from (nullity ('PGvararray ty)) -- ^ array
646+ -> null ('PGvararray ty) :--> NullifyType ty
518− -> Expression outer grp commons schemas params from (NullifyType ty)
519index n expr = UnsafeExpression $
647index n expr = UnsafeExpression $
520 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
648 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
522instance (KnownSymbol label, label `In` labels) => IsPGlabel label
650instance (KnownSymbol label, label `In` labels) => IsPGlabel label
523− (Expression outer grp commons schemas params from (nullity ('PGenum labels))) where
651+ (Expression outer commons grp schemas params from (null ('PGenum labels))) where
524 label = UnsafeExpression $ renderSQL (PGlabel @label)
652 label = UnsafeExpression $ renderSQL (PGlabel @label)
526-- | A row constructor is an expression that builds a row value
654-- | A row constructor is an expression that builds a row value
@@ -532,14 +660,14 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
532-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
660-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
535−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression outer grp commons schemas params from ('NotNull Complex)
663+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression outer commons grp schemas params from ('NotNull Complex)
536-- >>> printSQL i
664-- >>> printSQL i
537-- ROW(0, 1)
665-- ROW(0, 1)
539 :: SListI row
667 :: SListI row
540− => NP (Aliased (Expression outer grp commons schemas params from)) row
668+ => NP (Aliased (Expression outer commons grp schemas params from)) row
541 -- ^ zero or more expressions for the row field values
669 -- ^ zero or more expressions for the row field values
542− -> Expression outer grp commons schemas params from (nullity ('PGcomposite row))
670+ -> Expression outer commons grp schemas params from (null ('PGcomposite row))
543row exprs = UnsafeExpression $ "ROW" <> parenthesized
671row exprs = UnsafeExpression $ "ROW" <> parenthesized
544 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
672 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
@@ -550,7 +678,7 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
550-- type Schema = '["complex" ::: 'Typedef Complex]
678-- type Schema = '["complex" ::: 'Typedef Complex]
553−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression outer grp '[] (Public Schema) from params ('NotNull Complex)
681+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression outer '[] grp (Public Schema) from params ('NotNull Complex)
554-- >>> printSQL $ i & field #complex #imaginary
682-- >>> printSQL $ i & field #complex #imaginary
555-- (ROW(0, 1)::"complex")."imaginary"
683-- (ROW(0, 1)::"complex")."imaginary"
@@ -559,87 +687,65 @@ field
559 , Has field row ty)
687 , Has field row ty)
560 => QualifiedAlias sch tydef -- ^ row type
688 => QualifiedAlias sch tydef -- ^ row type
561 -> Alias field -- ^ field name
689 -> Alias field -- ^ field name
562− -> Expression outer grp commons schemas params from ('NotNull ('PGcomposite row))
690+ -> Expression outer commons grp schemas params from ('NotNull ('PGcomposite row))
563− -> Expression outer grp commons schemas params from ty
691+ -> Expression outer commons grp schemas params from ty
564field td fld expr = UnsafeExpression $
692field td fld expr = UnsafeExpression $
565 parenthesized (renderSQL expr <> "::" <> renderSQL td)
693 parenthesized (renderSQL expr <> "::" <> renderSQL td)
566 <> "." <> renderSQL fld
694 <> "." <> renderSQL fld
568instance Semigroup
696instance Semigroup
569− (Expression outer grp commons schemas params from (nullity ('PGvararray ty))) where
697+ (Expression outer commons grp schemas params from (null ('PGvararray ty))) where
570 (<>) = unsafeBinaryOp "||"
698 (<>) = unsafeBinaryOp "||"
572instance Monoid
700instance Monoid
573− (Expression outer grp commons schemas params from (nullity ('PGvararray ty))) where
701+ (Expression outer commons grp schemas params from (null ('PGvararray ty))) where
574 mempty = array []
702 mempty = array []
575 mappend = (<>)
703 mappend = (<>)
577−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression outer grp commons schemas '[ 'NotNull 'PGtimestamptz] from ('NotNull 'PGtimestamptz)
705+-- | >>> let expr = greatest [param @1] currentTimestamp :: Expression outer commons grp schemas '[ 'NotNull 'PGtimestamptz] from ('NotNull 'PGtimestamptz)
578-- >>> printSQL expr
706-- >>> printSQL expr
579−-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
707+-- GREATEST(($1 :: timestamp with time zone), CURRENT_TIMESTAMP)
580−greatest
708+greatest :: FunctionHom ty ty ty
581− :: Expression outer grp commons schemas params from (nullty)
582− -- ^ needs at least 1 argument
583− -> [Expression outer grp commons schemas params from (nullty)]
585− -> Expression outer grp commons schemas params from (nullty)
586−greatest x xs = UnsafeExpression $ "GREATEST("
709+greatest = unsafeFunctionHom "GREATEST"
587− <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
710+
589−-- | >>> printSQL $ least currentTimestamp [null_]
711+-- | >>> printSQL $ least [null_] currentTimestamp
590−-- LEAST(CURRENT_TIMESTAMP, NULL)
712+-- LEAST(NULL, CURRENT_TIMESTAMP)
591−least
713+least :: FunctionHom ty ty ty
592− :: Expression outer grp commons schemas params from (nullty)
714+least = unsafeFunctionHom "LEAST"
593− -- ^ needs at least 1 argument
594− -> [Expression outer grp commons schemas params from (nullty)]
596− -> Expression outer grp commons schemas params from (nullty)
597−least x xs = UnsafeExpression $ "LEAST("
598− <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
600-- | >>> printSQL $ unsafeBinaryOp "OR" true false
716-- | >>> printSQL $ unsafeBinaryOp "OR" true false
601-- (TRUE OR FALSE)
717-- (TRUE OR FALSE)
602−unsafeBinaryOp
718+unsafeBinaryOp :: ByteString {- ^ operator -} -> Operator ty0 ty1 ty2
605− -> Expression outer grp commons schemas params from (ty0)
606− -> Expression outer grp commons schemas params from (ty1)
607− -> Expression outer grp commons schemas params from (ty2)
608unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
719unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
609 renderSQL x <+> op <+> renderSQL y
720 renderSQL x <+> op <+> renderSQL y
611−-- | >>> printSQL $ unsafeUnaryOp "NOT" true
722+-- | >>> printSQL $ unsafeUnaryOpL "NOT" true
612-- (NOT TRUE)
723-- (NOT TRUE)
614− :: ByteString
724+unsafeUnaryOpL :: ByteString {- ^ operator -} -> x :--> y
615− -- ^ operator
725+unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
616− -> Expression outer grp commons schemas params from (ty0)
726+
617− -> Expression outer grp commons schemas params from (ty1)
727+-- | >>> printSQL $ true & unsafeUnaryOpR "IS NOT TRUE"
728+-- (TRUE IS NOT TRUE)
729+unsafeUnaryOpR :: ByteString {- ^ operator -} -> x :--> y
618−unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
730+unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
621-- | >>> printSQL $ unsafeFunction "f" true
732-- | >>> printSQL $ unsafeFunction "f" true
622-- f(TRUE)
733-- f(TRUE)
623−unsafeFunction
734+unsafeFunction :: ByteString {- ^ function -} -> x :--> y
626− -> Expression outer grp commons schemas params from (xty)
627− -> Expression outer grp commons schemas params from (yty)
628unsafeFunction fun x = UnsafeExpression $
735unsafeFunction fun x = UnsafeExpression $
629 fun <> parenthesized (renderSQL x)
736 fun <> parenthesized (renderSQL x)
631−-- | Helper for defining variadic functions.
738+-- | >>> printSQL $ unsafeFunctionHet "f" (currentTime :* localTimestamp :* false *: litChar 'a')
632−unsafeVariadicFunction
739+-- f(CURRENT_TIME, LOCALTIMESTAMP, FALSE, E'a')
633− :: SListI elems
741+ :: SListI xs
634− => ByteString
742+ => ByteString {- ^ function -}
635− -- ^ function
743+ -> FunctionHet xs y
636− -> NP (Expression outer grp commons schemas params from) elems
637− -> Expression outer grp commons schemas params from ret
638−unsafeVariadicFunction fun x = UnsafeExpression $
744+unsafeFunctionHet fun xs = UnsafeExpression $
639− fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
745+ fun <> parenthesized (renderCommaSeparated renderSQL xs)
641instance ty `In` PGNum
747instance ty `In` PGNum
642− => Num (Expression outer grp commons schemas params from (nullity ty)) where
748+ => Num (Expression outer commons grp schemas params from (null ty)) where
643 (+) = unsafeBinaryOp "+"
749 (+) = unsafeBinaryOp "+"
644 (-) = unsafeBinaryOp "-"
750 (-) = unsafeBinaryOp "-"
645 (*) = unsafeBinaryOp "*"
751 (*) = unsafeBinaryOp "*"
@@ -651,7 +757,7 @@ instance ty `In` PGNum
653instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
759instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
654− (Expression outer grp commons schemas params from (nullity ty)) where
760+ (Expression outer commons grp schemas params from (null ty)) where
655 (/) = unsafeBinaryOp "/"
761 (/) = unsafeBinaryOp "/"
656 fromRational
762 fromRational
657 = UnsafeExpression
763 = UnsafeExpression
@@ -661,7 +767,7 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
661 . fromRat @Double
767 . fromRat @Double
663instance (ty `In` PGNum, ty `In` PGFloating) => Floating
769instance (ty `In` PGNum, ty `In` PGFloating) => Floating
664− (Expression outer grp commons schemas params from (nullity ty)) where
770+ (Expression outer commons grp schemas params from (null ty)) where
665 pi = UnsafeExpression "pi()"
771 pi = UnsafeExpression "pi()"
666 exp = unsafeFunction "exp"
772 exp = unsafeFunction "exp"
667 log = unsafeFunction "ln"
773 log = unsafeFunction "ln"
@@ -684,20 +790,15 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
685-- | >>> :{
791-- | >>> :{
687−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
793+-- expression :: Expr (null 'PGfloat4)
688−-- expression = atan2_ pi 2
794+-- expression = atan2_ (pi *: 2)
689-- in printSQL expression
795-- in printSQL expression
691-- atan2(pi(), 2)
797-- atan2(pi(), 2)
693 :: float `In` PGFloating
799 :: float `In` PGFloating
694− => Expression outer grp commons schemas params from (nullity float)
800+ => FunctionHet '[ null float, null float] (null float)
695− -- ^ numerator
801+atan2_ = unsafeFunctionHet "atan2"
696− -> Expression outer grp commons schemas params from (nullity float)
698− -> Expression outer grp commons schemas params from (nullity float)
699−atan2_ y x = UnsafeExpression $
700− "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
702-- When a `cast` is applied to an `Expression` of a known type, it
803-- When a `cast` is applied to an `Expression` of a known type, it
703-- represents a run-time type conversion. The cast will succeed only if a
804-- represents a run-time type conversion. The cast will succeed only if a
@@ -708,9 +809,9 @@ atan2_ y x = UnsafeExpression $
709 :: TypeExpression schemas ty1
810 :: TypeExpression schemas ty1
710 -- ^ type to cast as
811 -- ^ type to cast as
711− -> Expression outer grp commons schemas params from ty0
812+ -> Expression outer commons grp schemas params from ty0
712 -- ^ value to convert
813 -- ^ value to convert
713− -> Expression outer grp commons schemas params from ty1
814+ -> Expression outer commons grp schemas params from ty1
714cast ty x = UnsafeExpression $ parenthesized $
815cast ty x = UnsafeExpression $ parenthesized $
715 renderSQL x <+> "::" <+> renderSQL ty
816 renderSQL x <+> "::" <+> renderSQL ty
@@ -718,136 +819,108 @@ cast ty x = UnsafeExpression $ parenthesized $
721−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
822+-- expression :: Expression outer commons grp schemas params from (null 'PGint2)
722-- expression = 5 `quot_` 2
823-- expression = 5 `quot_` 2
723-- in printSQL expression
824-- in printSQL expression
725-- (5 / 2)
826-- (5 / 2)
727 :: int `In` PGIntegral
828 :: int `In` PGIntegral
728− => Expression outer grp commons schemas params from (nullity int)
829+ => Operator (null int) (null int) (null int)
730− -> Expression outer grp commons schemas params from (nullity int)
732− -> Expression outer grp commons schemas params from (nullity int)
733quot_ = unsafeBinaryOp "/"
830quot_ = unsafeBinaryOp "/"
735-- | remainder upon integer division
832-- | remainder upon integer division
739−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
836+-- expression :: Expression outer commons grp schemas params from (null 'PGint2)
740-- expression = 5 `rem_` 2
837-- expression = 5 `rem_` 2
741-- in printSQL expression
838-- in printSQL expression
743-- (5 % 2)
840-- (5 % 2)
745 :: int `In` PGIntegral
842 :: int `In` PGIntegral
746− => Expression outer grp commons schemas params from (nullity int)
843+ => Operator (null int) (null int) (null int)
748− -> Expression outer grp commons schemas params from (nullity int)
750− -> Expression outer grp commons schemas params from (nullity int)
751rem_ = unsafeBinaryOp "%"
844rem_ = unsafeBinaryOp "%"
753-- | >>> :{
846-- | >>> :{
755−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
848+-- expression :: Expression outer commons grp schemas params from (null 'PGfloat4)
756-- expression = trunc pi
849-- expression = trunc pi
757-- in printSQL expression
850-- in printSQL expression
759-- trunc(pi())
852-- trunc(pi())
761− :: frac `In` PGFloating
853+trunc :: frac `In` PGFloating => null frac :--> null frac
762− => Expression outer grp commons schemas params from (nullity frac)
763− -- ^ fractional number
764− -> Expression outer grp commons schemas params from (nullity frac)
765trunc = unsafeFunction "trunc"
854trunc = unsafeFunction "trunc"
767-- | >>> :{
856-- | >>> :{
769−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
858+-- expression :: Expression outer commons grp schemas params from (null 'PGfloat4)
770-- expression = round_ pi
859-- expression = round_ pi
771-- in printSQL expression
860-- in printSQL expression
773-- round(pi())
862-- round(pi())
775− :: frac `In` PGFloating
863+round_ :: frac `In` PGFloating => null frac :--> null frac
776− => Expression outer grp commons schemas params from (nullity frac)
777− -- ^ fractional number
778− -> Expression outer grp commons schemas params from (nullity frac)
779round_ = unsafeFunction "round"
864round_ = unsafeFunction "round"
781-- | >>> :{
866-- | >>> :{
783−-- expression :: Expression outer grp commons schemas params from (nullity 'PGfloat4)
868+-- expression :: Expression outer commons grp schemas params from (null 'PGfloat4)
784-- expression = ceiling_ pi
869-- expression = ceiling_ pi
785-- in printSQL expression
870-- in printSQL expression
787-- ceiling(pi())
872-- ceiling(pi())
789− :: frac `In` PGFloating
873+ceiling_ :: frac `In` PGFloating => null frac :--> null frac
790− => Expression outer grp commons schemas params from (nullity frac)
791− -- ^ fractional number
792− -> Expression outer grp commons schemas params from (nullity frac)
793ceiling_ = unsafeFunction "ceiling"
874ceiling_ = unsafeFunction "ceiling"
795-- | A `Condition` is an `Expression`, which can evaluate
876-- | A `Condition` is an `Expression`, which can evaluate
796-- to `true`, `false` or `null_`. This is because SQL uses
877-- to `true`, `false` or `null_`. This is because SQL uses
797-- a three valued logic.
878-- a three valued logic.
798−type Condition outer grp commons schemas params from =
879+type Condition outer commons grp schemas params from =
799− Expression outer grp commons schemas params from ('Null 'PGbool)
880+ Expression outer commons grp schemas params from ('Null 'PGbool)
801-- | >>> printSQL true
882-- | >>> printSQL true
803−true :: Expression outer grp commons schemas params from (nullity 'PGbool)
884+true :: Expr (null 'PGbool)
804true = UnsafeExpression "TRUE"
885true = UnsafeExpression "TRUE"
806-- | >>> printSQL false
887-- | >>> printSQL false
808−false :: Expression outer grp commons schemas params from (nullity 'PGbool)
889+false :: Expr (null 'PGbool)
809false = UnsafeExpression "FALSE"
890false = UnsafeExpression "FALSE"
811-- | >>> printSQL $ not_ true
892-- | >>> printSQL $ not_ true
812-- (NOT TRUE)
893-- (NOT TRUE)
813−not_
894+not_ :: null 'PGbool :--> null 'PGbool
814− :: Expression outer grp commons schemas params from (nullity 'PGbool)
895+not_ = unsafeUnaryOpL "NOT"
815− -> Expression outer grp commons schemas params from (nullity 'PGbool)
816−not_ = unsafeUnaryOp "NOT"
818-- | >>> printSQL $ true .&& false
897-- | >>> printSQL $ true .&& false
819-- (TRUE AND FALSE)
898-- (TRUE AND FALSE)
820−(.&&)
899+(.&&) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
821− :: Expression outer grp commons schemas params from (nullity 'PGbool)
822− -> Expression outer grp commons schemas params from (nullity 'PGbool)
823− -> Expression outer grp commons schemas params from (nullity 'PGbool)
824infixr 3 .&&
900infixr 3 .&&
825(.&&) = unsafeBinaryOp "AND"
901(.&&) = unsafeBinaryOp "AND"
827-- | >>> printSQL $ true .|| false
903-- | >>> printSQL $ true .|| false
828-- (TRUE OR FALSE)
904-- (TRUE OR FALSE)
829−(.||)
905+(.||) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
830− :: Expression outer grp commons schemas params from (nullity 'PGbool)
831− -> Expression outer grp commons schemas params from (nullity 'PGbool)
832− -> Expression outer grp commons schemas params from (nullity 'PGbool)
833infixr 2 .||
906infixr 2 .||
834(.||) = unsafeBinaryOp "OR"
907(.||) = unsafeBinaryOp "OR"
836-- | >>> :{
909-- | >>> :{
838−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
911+-- expression :: Expression outer commons grp schemas params from (null 'PGint2)
839-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
912-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
840-- in printSQL expression
913-- in printSQL expression
842-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
915-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
843caseWhenThenElse
916caseWhenThenElse
844− :: [ ( Condition outer grp commons schemas params from
917+ :: [ ( Condition outer commons grp schemas params from
845− , Expression outer grp commons schemas params from ty
918+ , Expression outer commons grp schemas params from ty
847 -- ^ whens and thens
920 -- ^ whens and thens
848− -> Expression outer grp commons schemas params from ty
921+ -> Expression outer commons grp schemas params from ty
849 -- ^ else
922 -- ^ else
850− -> Expression outer grp commons schemas params from ty
923+ -> Expression outer commons grp schemas params from ty
851caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
924caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
853 , mconcat
926 , mconcat
@@ -863,16 +936,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
864-- | >>> :{
937-- | >>> :{
866−-- expression :: Expression outer grp commons schemas params from (nullity 'PGint2)
939+-- expression :: Expression outer commons grp schemas params from (null 'PGint2)
867-- expression = ifThenElse true 1 0
940-- expression = ifThenElse true 1 0
868-- in printSQL expression
941-- in printSQL expression
870-- CASE WHEN TRUE THEN 1 ELSE 0 END
943-- CASE WHEN TRUE THEN 1 ELSE 0 END
871ifThenElse
944ifThenElse
872− :: Condition outer grp commons schemas params from
945+ :: Condition outer commons grp schemas params from
873− -> Expression outer grp commons schemas params from ty -- ^ then
946+ -> Expression outer commons grp schemas params from ty -- ^ then
874− -> Expression outer grp commons schemas params from ty -- ^ else
947+ -> Expression outer commons grp schemas params from ty -- ^ else
875− -> Expression outer grp commons schemas params from ty
948+ -> Expression outer commons grp schemas params from ty
876ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
949ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
878-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
951-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -880,261 +953,242 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
881-- >>> printSQL $ true .== null_
954-- >>> printSQL $ true .== null_
882-- (TRUE = NULL)
955-- (TRUE = NULL)
883−(.==)
956+(.==) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
884− :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
885− -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
886− -> Condition outer grp commons schemas params from
887(.==) = unsafeBinaryOp "="
957(.==) = unsafeBinaryOp "="
888infix 4 .==
958infix 4 .==
890-- | >>> printSQL $ true ./= null_
960-- | >>> printSQL $ true ./= null_
891-- (TRUE <> NULL)
961-- (TRUE <> NULL)
892−(./=)
962+(./=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
893− :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
894− -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
895− -> Condition outer grp commons schemas params from
896(./=) = unsafeBinaryOp "<>"
963(./=) = unsafeBinaryOp "<>"
897infix 4 ./=
964infix 4 ./=
899-- | >>> printSQL $ true .>= null_
966-- | >>> printSQL $ true .>= null_
900-- (TRUE >= NULL)
967-- (TRUE >= NULL)
901−(.>=)
968+(.>=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
902− :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
903− -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
904− -> Condition outer grp commons schemas params from
905(.>=) = unsafeBinaryOp ">="
969(.>=) = unsafeBinaryOp ">="
906infix 4 .>=
970infix 4 .>=
908-- | >>> printSQL $ true .< null_
972-- | >>> printSQL $ true .< null_
909-- (TRUE < NULL)
973-- (TRUE < NULL)
910−(.<)
974+(.<) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
911− :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
912− -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
913− -> Condition outer grp commons schemas params from
914(.<) = unsafeBinaryOp "<"
975(.<) = unsafeBinaryOp "<"
915infix 4 .<
976infix 4 .<
917-- | >>> printSQL $ true .<= null_
978-- | >>> printSQL $ true .<= null_
918-- (TRUE <= NULL)
979-- (TRUE <= NULL)
919−(.<=)
980+(.<=) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
920− :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
921− -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
922− -> Condition outer grp commons schemas params from
923(.<=) = unsafeBinaryOp "<="
981(.<=) = unsafeBinaryOp "<="
924infix 4 .<=
982infix 4 .<=
926-- | >>> printSQL $ true .> null_
984-- | >>> printSQL $ true .> null_
927-- (TRUE > NULL)
985-- (TRUE > NULL)
928−(.>)
986+(.>) :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
929− :: Expression outer grp commons schemas params from (nullity0 ty) -- ^ lhs
930− -> Expression outer grp commons schemas params from (nullity1 ty) -- ^ rhs
931− -> Condition outer grp commons schemas params from
932(.>) = unsafeBinaryOp ">"
987(.>) = unsafeBinaryOp ">"
933infix 4 .>
988infix 4 .>
936−>>> printSQL $ true `between` (null_, false)
990+{- | >>> printSQL $ true `between` (null_, false)
937TRUE BETWEEN NULL AND FALSE
991TRUE BETWEEN NULL AND FALSE
940− :: Expression outer grp commons schemas params from (nullity ty)
994+ :: Expression outer commons grp schemas params from (null ty)
941− -> ( Expression outer grp commons schemas params from (nullity ty)
995+ -> ( Expression outer commons grp schemas params from (null ty)
942− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
996+ , Expression outer commons grp schemas params from (null ty) ) -- ^ bounds
943− -> Condition outer grp commons schemas params from
997+ -> Condition outer commons grp schemas params from
944between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
998between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
945 <+> renderSQL x <+> "AND" <+> renderSQL y
999 <+> renderSQL x <+> "AND" <+> renderSQL y
948−>>> printSQL $ true `notBetween` (null_, false)
1001+{- | >>> printSQL $ true `notBetween` (null_, false)
949TRUE NOT BETWEEN NULL AND FALSE
1002TRUE NOT BETWEEN NULL AND FALSE
951notBetween
1004notBetween
952− :: Expression outer grp commons schemas params from (nullity ty)
1005+ :: Expression outer commons grp schemas params from (null ty)
953− -> ( Expression outer grp commons schemas params from (nullity ty)
1006+ -> ( Expression outer commons grp schemas params from (null ty)
954− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
1007+ , Expression outer commons grp schemas params from (null ty) ) -- ^ bounds
955− -> Condition outer grp commons schemas params from
1008+ -> Condition outer commons grp schemas params from
956notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
1009notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
957 <+> renderSQL x <+> "AND" <+> renderSQL y
1010 <+> renderSQL x <+> "AND" <+> renderSQL y
959{- | between, after sorting the comparison values
1012{- | between, after sorting the comparison values
960>>> printSQL $ true `betweenSymmetric` (null_, false)
1014>>> printSQL $ true `betweenSymmetric` (null_, false)
961TRUE BETWEEN SYMMETRIC NULL AND FALSE
1015TRUE BETWEEN SYMMETRIC NULL AND FALSE
963betweenSymmetric
1017betweenSymmetric
964− :: Expression outer grp commons schemas params from (nullity ty)
1018+ :: Expression outer commons grp schemas params from (null ty)
965− -> ( Expression outer grp commons schemas params from (nullity ty)
1019+ -> ( Expression outer commons grp schemas params from (null ty)
966− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
1020+ , Expression outer commons grp schemas params from (null ty) ) -- ^ bounds
967− -> Condition outer grp commons schemas params from
1021+ -> Condition outer commons grp schemas params from
968betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
1022betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
969 <+> "BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
1023 <+> "BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
971{- | not between, after sorting the comparison values
1025{- | not between, after sorting the comparison values
972>>> printSQL $ true `notBetweenSymmetric` (null_, false)
1027>>> printSQL $ true `notBetweenSymmetric` (null_, false)
973TRUE NOT BETWEEN SYMMETRIC NULL AND FALSE
1028TRUE NOT BETWEEN SYMMETRIC NULL AND FALSE
975notBetweenSymmetric
1030notBetweenSymmetric
976− :: Expression outer grp commons schemas params from (nullity ty)
1031+ :: Expression outer commons grp schemas params from (null ty)
977− -> ( Expression outer grp commons schemas params from (nullity ty)
1032+ -> ( Expression outer commons grp schemas params from (null ty)
978− , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
1033+ , Expression outer commons grp schemas params from (null ty) ) -- ^ bounds
979− -> Condition outer grp commons schemas params from
1034+ -> Condition outer commons grp schemas params from
980notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
1035notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
981 <+> "NOT BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
1036 <+> "NOT BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
983{- | not equal, treating null like an ordinary value
1038{- | not equal, treating null like an ordinary value
984>>> printSQL $ true `isDistinctFrom` null_
1040>>> printSQL $ true `isDistinctFrom` null_
985(TRUE IS DISTINCT FROM NULL)
1041(TRUE IS DISTINCT FROM NULL)
987−isDistinctFrom
1043+isDistinctFrom :: Operator (null0 ty) (null1 ty) ('Null 'PGbool)
988− :: Expression outer grp commons schemas params from (nullity ty)
989− -> Expression outer grp commons schemas params from (nullity ty)
990− -> Condition outer grp commons schemas params from
991isDistinctFrom = unsafeBinaryOp "IS DISTINCT FROM"
1044isDistinctFrom = unsafeBinaryOp "IS DISTINCT FROM"
993{- | equal, treating null like an ordinary value
1046{- | equal, treating null like an ordinary value
994>>> printSQL $ true `isNotDistinctFrom` null_
1048>>> printSQL $ true `isNotDistinctFrom` null_
995(TRUE IS NOT DISTINCT FROM NULL)
1049(TRUE IS NOT DISTINCT FROM NULL)
997−isNotDistinctFrom
1051+isNotDistinctFrom :: Operator (null0 ty) (null1 ty) ('NotNull 'PGbool)
998− :: Expression outer grp commons schemas params from (nullity ty)
999− -> Expression outer grp commons schemas params from (nullity ty)
1000− -> Condition outer grp commons schemas params from
1001isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
1052isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
1003{- | is true
1054{- | is true
1004>>> printSQL $ true & isTrue
1056>>> printSQL $ true & isTrue
1005−TRUE IS TRUE
1057+(TRUE IS TRUE)
1007−isTrue
1059+isTrue :: null0 'PGbool :--> null1 'PGbool
1008− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1060+isTrue = unsafeUnaryOpR "IS TRUE"
1009− -> Condition outer grp commons schemas params from
1010−isTrue b = UnsafeExpression $ renderSQL b <+> "IS TRUE"
1012{- | is false or unknown
1062{- | is false or unknown
1013>>> printSQL $ true & isNotTrue
1064>>> printSQL $ true & isNotTrue
1014−TRUE IS NOT TRUE
1065+(TRUE IS NOT TRUE)
1016−isNotTrue
1067+isNotTrue :: null0 'PGbool :--> null1 'PGbool
1017− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1018− -> Condition outer grp commons schemas params from
1019−isNotTrue b = UnsafeExpression $ renderSQL b <+> "IS NOT TRUE"
1068+isNotTrue = unsafeUnaryOpR "IS NOT TRUE"
1021{- | is false
1070{- | is false
1022>>> printSQL $ true & isFalse
1072>>> printSQL $ true & isFalse
1023−TRUE IS FALSE
1073+(TRUE IS FALSE)
1025−isFalse
1075+isFalse :: null0 'PGbool :--> null1 'PGbool
1026− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1027− -> Condition outer grp commons schemas params from
1028−isFalse b = UnsafeExpression $ renderSQL b <+> "IS FALSE"
1076+isFalse = unsafeUnaryOpR "IS FALSE"
1030{- | is true or unknown
1078{- | is true or unknown
1031>>> printSQL $ true & isNotFalse
1080>>> printSQL $ true & isNotFalse
1032−TRUE IS NOT FALSE
1081+(TRUE IS NOT FALSE)
1034−isNotFalse
1083+isNotFalse :: null0 'PGbool :--> null1 'PGbool
1035− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1036− -> Condition outer grp commons schemas params from
1037−isNotFalse b = UnsafeExpression $ renderSQL b <+> "IS NOT FALSE"
1084+isNotFalse = unsafeUnaryOpR "IS NOT FALSE"
1039{- | is unknown
1086{- | is unknown
1040>>> printSQL $ true & isUnknown
1088>>> printSQL $ true & isUnknown
1041−TRUE IS UNKNOWN
1089+(TRUE IS UNKNOWN)
1043−isUnknown
1091+isUnknown :: null0 'PGbool :--> null1 'PGbool
1044− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1045− -> Condition outer grp commons schemas params from
1046−isUnknown b = UnsafeExpression $ renderSQL b <+> "IS UNKNOWN"
1092+isUnknown = unsafeUnaryOpR "IS UNKNOWN"
1048{- | is true or false
1094{- | is true or false
1049>>> printSQL $ true & isNotUnknown
1096>>> printSQL $ true & isNotUnknown
1050−TRUE IS NOT UNKNOWN
1097+(TRUE IS NOT UNKNOWN)
1052−isNotUnknown
1099+isNotUnknown :: null0 'PGbool :--> null1 'PGbool
1053− :: Expression outer grp commons schemas params from (nullity 'PGbool)
1054− -> Condition outer grp commons schemas params from
1055−isNotUnknown b = UnsafeExpression $ renderSQL b <+> "IS NOT UNKNOWN"
1100+isNotUnknown = unsafeUnaryOpR "IS NOT UNKNOWN"
1057-- | >>> printSQL currentDate
1102-- | >>> printSQL currentDate
1058-- CURRENT_DATE
1103-- CURRENT_DATE
1059−currentDate
1104+currentDate :: Expr (null 'PGdate)
1060− :: Expression outer grp commons schemas params from (nullity 'PGdate)
1061currentDate = UnsafeExpression "CURRENT_DATE"
1105currentDate = UnsafeExpression "CURRENT_DATE"
1063-- | >>> printSQL currentTime
1107-- | >>> printSQL currentTime
1064-- CURRENT_TIME
1108-- CURRENT_TIME
1065−currentTime
1109+currentTime :: Expr (null 'PGtimetz)
1066− :: Expression outer grp commons schemas params from (nullity 'PGtimetz)
1067currentTime = UnsafeExpression "CURRENT_TIME"
1110currentTime = UnsafeExpression "CURRENT_TIME"
1069-- | >>> printSQL currentTimestamp
1112-- | >>> printSQL currentTimestamp
1070-- CURRENT_TIMESTAMP
1113-- CURRENT_TIMESTAMP
1071−currentTimestamp
1114+currentTimestamp :: Expr (null 'PGtimestamptz)
1072− :: Expression outer grp commons schemas params from (nullity 'PGtimestamptz)
1073currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
1115currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
1075-- | >>> printSQL localTime
1117-- | >>> printSQL localTime
1076-- LOCALTIME
1118-- LOCALTIME
1077−localTime
1119+localTime :: Expr (null 'PGtime)
1078− :: Expression outer grp commons schemas params from (nullity 'PGtime)
1079localTime = UnsafeExpression "LOCALTIME"
1120localTime = UnsafeExpression "LOCALTIME"
1081-- | >>> printSQL localTimestamp
1122-- | >>> printSQL localTimestamp
1082-- LOCALTIMESTAMP
1123-- LOCALTIMESTAMP
1083−localTimestamp
1124+localTimestamp :: Expr (null 'PGtimestamp)
1084− :: Expression outer grp commons schemas params from (nullity 'PGtimestamp)
1085localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
1125localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
1127+-- | Current date and time (equivalent to `currentTimestamp`)
1131+now :: Expr (null 'PGtimestamptz)
1132+now = UnsafeExpression "now()"
1087{-----------------------------------------
1134{-----------------------------------------
1089-----------------------------------------}
1136-----------------------------------------}
1138+escape :: Char -> String
1091instance IsString
1150instance IsString
1092− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1151+ (Expression outer commons grp schemas params from (null 'PGtext)) where
1093 fromString str = UnsafeExpression $
1152 fromString str = UnsafeExpression $
1094 "E\'" <> fromString (escape =<< str) <> "\'"
1153 "E\'" <> fromString (escape =<< str) <> "\'"
1095− where
1154+instance IsString
1096− escape = \case
1155+ (Expression outer commons grp schemas params from (null 'PGtsvector)) where
1097− '\NUL' -> "\\0"
1156+ fromString str = cast tsvector . UnsafeExpression $
1098− '\'' -> "''"
1157+ "E\'" <> fromString (escape =<< str) <> "\'"
1099− '"' -> "\\\""
1158+instance IsString
1100− '\b' -> "\\b"
1159+ (Expression outer commons grp schemas params from (null 'PGtsquery)) where
1101− '\n' -> "\\n"
1160+ fromString str = cast tsquery . UnsafeExpression $
1102− '\r' -> "\\r"
1161+ "E\'" <> fromString (escape =<< str) <> "\'"
1107instance Semigroup
1163instance Semigroup
1108− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1164+ (Expression outer commons grp schemas params from (null 'PGtext)) where
1165+ (<>) = unsafeBinaryOp "||"
1167+ (Expression outer commons grp schemas params from (null 'PGtsvector)) where
1109 (<>) = unsafeBinaryOp "||"
1168 (<>) = unsafeBinaryOp "||"
1111instance Monoid
1170instance Monoid
1112− (Expression outer grp commons schemas params from (nullity 'PGtext)) where
1171+ (Expression outer commons grp schemas params from (null 'PGtext)) where
1172+ mempty = fromString ""
1175+ (Expression outer commons grp schemas params from (null 'PGtsvector)) where
1113 mempty = fromString ""
1176 mempty = fromString ""
1114 mappend = (<>)
1177 mappend = (<>)
1116-- | >>> printSQL $ lower "ARRRGGG"
1179-- | >>> printSQL $ lower "ARRRGGG"
1117-- lower(E'ARRRGGG')
1180-- lower(E'ARRRGGG')
1118−lower
1181+lower :: null 'PGtext :--> null 'PGtext
1119− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1120− -- ^ string to lower case
1121− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1122lower = unsafeFunction "lower"
1182lower = unsafeFunction "lower"
1124-- | >>> printSQL $ upper "eeee"
1184-- | >>> printSQL $ upper "eeee"
1125-- upper(E'eeee')
1185-- upper(E'eeee')
1126−upper
1186+upper :: null 'PGtext :--> null 'PGtext
1127− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1128− -- ^ string to upper case
1129− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1130upper = unsafeFunction "upper"
1187upper = unsafeFunction "upper"
1132-- | >>> printSQL $ charLength "four"
1189-- | >>> printSQL $ charLength "four"
1133-- char_length(E'four')
1190-- char_length(E'four')
1134−charLength
1191+charLength :: null 'PGtext :--> null 'PGint4
1135− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1136− -- ^ string to measure
1137− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1138charLength = unsafeFunction "char_length"
1192charLength = unsafeFunction "char_length"
1140-- | The `like` expression returns true if the @string@ matches
1194-- | The `like` expression returns true if the @string@ matches
@@ -1146,12 +1200,7 @@ charLength = unsafeFunction "char_length"
1147-- >>> printSQL $ "abc" `like` "a%"
1201-- >>> printSQL $ "abc" `like` "a%"
1148-- (E'abc' LIKE E'a%')
1202-- (E'abc' LIKE E'a%')
1149−like
1203+like :: Operator (null 'PGtext) (null 'PGtext) ('Null 'PGbool)
1150− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1152− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1154− -> Expression outer grp commons schemas params from (nullity 'PGbool)
1155like = unsafeBinaryOp "LIKE"
1204like = unsafeBinaryOp "LIKE"
1157-- | The key word ILIKE can be used instead of LIKE to make the
1206-- | The key word ILIKE can be used instead of LIKE to make the
@@ -1159,12 +1208,7 @@ like = unsafeBinaryOp "LIKE"
1160-- >>> printSQL $ "abc" `ilike` "a%"
1209-- >>> printSQL $ "abc" `ilike` "a%"
1161-- (E'abc' ILIKE E'a%')
1210-- (E'abc' ILIKE E'a%')
1162−ilike
1211+ilike :: Operator (null 'PGtext) (null 'PGtext) ('Null 'PGbool)
1163− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1165− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1167− -> Expression outer grp commons schemas params from (nullity 'PGbool)
1168ilike = unsafeBinaryOp "ILIKE"
1212ilike = unsafeBinaryOp "ILIKE"
1170{-----------------------------------------
1214{-----------------------------------------
@@ -1179,86 +1223,66 @@ Table 9.44: json and jsonb operators
1179-- | Get JSON value (object field or array element) at a key.
1223-- | Get JSON value (object field or array element) at a key.
1181 :: (json `In` PGJsonType, key `In` PGJsonKey)
1225 :: (json `In` PGJsonType, key `In` PGJsonKey)
1182− => Expression outer grp commons schemas params from (nullity json)
1226+ => Operator (null json) (null key) ('Null json)
1183− -> Expression outer grp commons schemas params from (nullity key)
1184− -> Expression outer grp commons schemas params from ('Null json)
1185infixl 8 .->
1227infixl 8 .->
1186(.->) = unsafeBinaryOp "->"
1228(.->) = unsafeBinaryOp "->"
1188-- | Get JSON value (object field or array element) at a key, as text.
1230-- | Get JSON value (object field or array element) at a key, as text.
1190 :: (json `In` PGJsonType, key `In` PGJsonKey)
1232 :: (json `In` PGJsonType, key `In` PGJsonKey)
1191− => Expression outer grp commons schemas params from (nullity json)
1233+ => Operator (null json) (null key) ('Null 'PGtext)
1192− -> Expression outer grp commons schemas params from (nullity key)
1193− -> Expression outer grp commons schemas params from ('Null 'PGtext)
1194infixl 8 .->>
1234infixl 8 .->>
1195(.->>) = unsafeBinaryOp "->>"
1235(.->>) = unsafeBinaryOp "->>"
1197-- | Get JSON value at a specified path.
1237-- | Get JSON value at a specified path.
1199− :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1239+ :: json `In` PGJsonType
1200− => Expression outer grp commons schemas params from (nullity json)
1240+ => Operator (null json) (null ('PGvararray ('NotNull 'PGtext))) ('Null json)
1201− -> Expression outer grp commons schemas params from (nullity path)
1202− -> Expression outer grp commons schemas params from ('Null json)
1203infixl 8 .#>
1241infixl 8 .#>
1204(.#>) = unsafeBinaryOp "#>"
1242(.#>) = unsafeBinaryOp "#>"
1206-- | Get JSON value at a specified path as text.
1244-- | Get JSON value at a specified path as text.
1208− :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1246+ :: json `In` PGJsonType
1209− => Expression outer grp commons schemas params from (nullity json)
1247+ => Operator (null json) (null ('PGvararray ('NotNull 'PGtext))) ('Null 'PGtext)
1210− -> Expression outer grp commons schemas params from (nullity path)
1211− -> Expression outer grp commons schemas params from ('Null 'PGtext)
1212infixl 8 .#>>
1248infixl 8 .#>>
1213(.#>>) = unsafeBinaryOp "#>>"
1249(.#>>) = unsafeBinaryOp "#>>"
1215-- Additional jsonb operators
1251-- Additional jsonb operators
1217−-- | Does the left JSON value contain the right JSON path/value entries at the
1253+class PGSubset container where
1218−-- top level?
1254+ (@>) :: Operator (null0 container) (null1 container) ('Null 'PGbool)
1220− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1221− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1222− -> Condition outer grp commons schemas params from
1224−(.@>) = unsafeBinaryOp "@>"
1255+ (@>) = unsafeBinaryOp "@>"
1225−
1256+ (<@) :: Operator (null0 container) (null1 container) ('Null 'PGbool)
1226−-- | Are the left JSON path/value entries contained at the top level within the
1257+ (<@) = unsafeBinaryOp "<@"
1227−-- right JSON value?
1258+instance PGSubset 'PGjsonb
1228−(.<@)
1259+instance PGSubset 'PGtsquery
1229− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1260+instance PGSubset ('PGvararray ty)
1230− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1231− -> Condition outer grp commons schemas params from
1233−(.<@) = unsafeBinaryOp "<@"
1235-- | Does the string exist as a top-level key within the JSON value?
1262-- | Does the string exist as a top-level key within the JSON value?
1236−(.?)
1263+(.?) :: Operator (null 'PGjsonb) (null 'PGtext) ('Null 'PGbool)
1237− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1238− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1239− -> Condition outer grp commons schemas params from
1240infixl 9 .?
1264infixl 9 .?
1241(.?) = unsafeBinaryOp "?"
1265(.?) = unsafeBinaryOp "?"
1243-- | Do any of these array strings exist as top-level keys?
1267-- | Do any of these array strings exist as top-level keys?
1244−(.?|)
1268+(.?|) :: Operator
1245− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1269+ (null 'PGjsonb)
1246− -> Expression outer grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1270+ (null ('PGvararray ('NotNull 'PGtext)))
1247− -> Condition outer grp commons schemas params from
1271+ ('Null 'PGbool)
1248infixl 9 .?|
1272infixl 9 .?|
1249(.?|) = unsafeBinaryOp "?|"
1273(.?|) = unsafeBinaryOp "?|"
1251-- | Do all of these array strings exist as top-level keys?
1275-- | Do all of these array strings exist as top-level keys?
1252−(.?&)
1276+(.?&) :: Operator
1253− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1277+ (null 'PGjsonb)
1254− -> Expression outer grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1278+ (null ('PGvararray ('NotNull 'PGtext)))
1255− -> Condition outer grp commons schemas params from
1279+ ('Null 'PGbool)
1256infixl 9 .?&
1280infixl 9 .?&
1257(.?&) = unsafeBinaryOp "?&"
1281(.?&) = unsafeBinaryOp "?&"
1259-- | Concatenate two jsonb values into a new jsonb value.
1283-- | Concatenate two jsonb values into a new jsonb value.
1260instance Semigroup
1284instance Semigroup
1261− (Expression outer grp commons schemas params from (nullity 'PGjsonb)) where
1285+ (Expression outer commons grp schemas params from (null 'PGjsonb)) where
1262 (<>) = unsafeBinaryOp "||"
1286 (<>) = unsafeBinaryOp "||"
1264-- | Delete a key or keys from a JSON object, or remove an array element.
1288-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1275,19 +1299,13 @@ instance Semigroup
1275-- count from the end). Throws an error if top level container is not an array.
1299-- count from the end). Throws an error if top level container is not an array.
1277 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1301 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1278− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1302+ => Operator (null 'PGjsonb) (null key) (null 'PGjsonb)
1279− -> Expression outer grp commons schemas params from (nullity key)
1280− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1281infixl 6 .-.
1303infixl 6 .-.
1282(.-.) = unsafeBinaryOp "-"
1304(.-.) = unsafeBinaryOp "-"
1284-- | Delete the field or element with specified path (for JSON arrays, negative
1306-- | Delete the field or element with specified path (for JSON arrays, negative
1285-- integers count from the end)
1307-- integers count from the end)
1286−(#-.)
1308+(#-.) :: Operator (null 'PGjsonb) (null ('PGvararray ('NotNull 'PGtext))) (null 'PGjsonb)
1287− :: PGTextArray "(#-.)" arrayty
1288− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1289− -> Expression outer grp commons schemas params from (nullity arrayty)
1290− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1291infixl 6 #-.
1309infixl 6 #-.
1292(#-.) = unsafeBinaryOp "#-"
1310(#-.) = unsafeBinaryOp "#-"
@@ -1296,16 +1314,12 @@ Table 9.45: JSON creation functions
1296-----------------------------------------}
1314-----------------------------------------}
1298-- | Literal binary JSON
1316-- | Literal binary JSON
1300− :: JSON.ToJSON x
1317+jsonbLit :: JSON.ToJSON x => x -> Expr (null 'PGjsonb)
1301− => x -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1302jsonbLit = cast jsonb . UnsafeExpression
1318jsonbLit = cast jsonb . UnsafeExpression
1303 . singleQuotedUtf8 . toStrict . JSON.encode
1319 . singleQuotedUtf8 . toStrict . JSON.encode
1305-- | Literal JSON
1321-- | Literal JSON
1307− :: JSON.ToJSON x
1322+jsonLit :: JSON.ToJSON x => x -> Expr (null 'PGjson)
1308− => x -> Expression outer grp commons schemas params from (nullity 'PGjson)
1309jsonLit = cast json . UnsafeExpression
1323jsonLit = cast json . UnsafeExpression
1310 . singleQuotedUtf8 . toStrict . JSON.encode
1324 . singleQuotedUtf8 . toStrict . JSON.encode
@@ -1315,9 +1329,7 @@ jsonLit = cast json . UnsafeExpression
1315-- otherwise, a scalar value is produced. For any scalar type other than a
1329-- otherwise, a scalar value is produced. For any scalar type other than a
1316-- number, a Boolean, or a null value, the text representation will be used, in
1330-- number, a Boolean, or a null value, the text representation will be used, in
1317-- such a fashion that it is a valid json value.
1331-- such a fashion that it is a valid json value.
1318−toJson
1332+toJson :: null ty :--> null 'PGjson
1319− :: Expression outer grp commons schemas params from (nullity ty)
1320− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1321toJson = unsafeFunction "to_json"
1333toJson = unsafeFunction "to_json"
1323-- | Returns the value as jsonb. Arrays and composites are converted
1335-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1326,204 +1338,154 @@ toJson = unsafeFunction "to_json"
1326-- otherwise, a scalar value is produced. For any scalar type other than a
1338-- otherwise, a scalar value is produced. For any scalar type other than a
1327-- number, a Boolean, or a null value, the text representation will be used, in
1339-- number, a Boolean, or a null value, the text representation will be used, in
1328-- such a fashion that it is a valid jsonb value.
1340-- such a fashion that it is a valid jsonb value.
1329−toJsonb
1341+toJsonb :: null ty :--> null 'PGjsonb
1330− :: Expression outer grp commons schemas params from (nullity ty)
1331− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1332toJsonb = unsafeFunction "to_jsonb"
1342toJsonb = unsafeFunction "to_jsonb"
1334-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1344-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1335-- becomes a JSON array of arrays.
1345-- becomes a JSON array of arrays.
1336−arrayToJson
1346+arrayToJson :: null ('PGvararray ty) :--> null 'PGjson
1337− :: PGArray "arrayToJson" arr
1338− => Expression outer grp commons schemas params from (nullity arr)
1339− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1340arrayToJson = unsafeFunction "array_to_json"
1347arrayToJson = unsafeFunction "array_to_json"
1342-- | Returns the row as a JSON object.
1349-- | Returns the row as a JSON object.
1343−rowToJson
1350+rowToJson :: null ('PGcomposite ty) :--> null 'PGjson
1344− :: Expression outer grp commons schemas params from (nullity ('PGcomposite ty))
1345− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1346rowToJson = unsafeFunction "row_to_json"
1351rowToJson = unsafeFunction "row_to_json"
1348-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1353-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1349-- argument list.
1354-- argument list.
1350−jsonBuildArray
1355+jsonBuildArray :: SListI tuple => FunctionHet tuple (null 'PGjson)
1352− => NP (Expression outer grp commons schemas params from) elems
1353− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1354−jsonBuildArray = unsafeVariadicFunction "json_build_array"
1356+jsonBuildArray = unsafeFunctionHet "json_build_array"
1356-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1358-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1357-- variadic argument list.
1359-- variadic argument list.
1358−jsonbBuildArray
1360+jsonbBuildArray :: SListI tuple => FunctionHet tuple (null 'PGjsonb)
1360− => NP (Expression outer grp commons schemas params from) elems
1361− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1362−jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1361+jsonbBuildArray = unsafeFunctionHet "jsonb_build_array"
1364−unsafeRowFunction
1363+class PGBuildObject tys where
1365− :: SOP.SListI elems
1364+instance PGBuildObject '[]
1366− => NP (Aliased (Expression outer grp commons schemas params from)) elems
1365+instance (PGBuildObject tys, key `In` PGJsonKey)
1367− -> [ByteString]
1366+ => PGBuildObject ('NotNull key ': value ': tys)
1369− (`appEndo` []) . hcfoldMap (Proxy :: SOP.Proxy SOP.Top)
1370− (\(col `As` name) -> Endo $ \xs ->
1371− renderAliasString name : renderSQL col : xs)
1373− renderAliasString :: KnownSymbol alias => Alias alias -> ByteString
1374− renderAliasString = singleQuotedText . fromString . symbolVal
1376-- | Builds a possibly-heterogeneously-typed JSON object out of a variadic
1368-- | Builds a possibly-heterogeneously-typed JSON object out of a variadic
1377-- argument list. The elements of the argument list must alternate between text
1369-- argument list. The elements of the argument list must alternate between text
1378-- and values.
1370-- and values.
1379jsonBuildObject
1371jsonBuildObject
1380− :: SOP.SListI elems
1372+ :: (SListI elems, PGBuildObject elems)
1381− => NP (Aliased (Expression outer grp commons schemas params from)) elems
1373+ => FunctionHet elems (null 'PGjson)
1382− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1383−jsonBuildObject
1374+jsonBuildObject = unsafeFunctionHet "json_build_object"
1384− = unsafeFunction "json_build_object"
1387− . unsafeRowFunction
1389-- | Builds a possibly-heterogeneously-typed (binary) JSON object out of a
1376-- | Builds a possibly-heterogeneously-typed (binary) JSON object out of a
1390-- variadic argument list. The elements of the argument list must alternate
1377-- variadic argument list. The elements of the argument list must alternate
1391−-- between text and values.
1378+-- between keys and values.
1393− :: SOP.SListI elems
1394− => NP (Aliased (Expression outer grp commons schemas params from)) elems
1395− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1396jsonbBuildObject
1379jsonbBuildObject
1380+ :: (SListI elems, PGBuildObject elems)
1381+ => FunctionHet elems (null 'PGjsonb)
1397− = unsafeFunction "jsonb_build_object"
1382+jsonbBuildObject = unsafeFunctionHet "jsonb_build_object"
1398− . UnsafeExpression
1383+
1400− . unsafeRowFunction
1402−-- | Builds a JSON object out of a text array. The array must have either
1384+-- | Builds a JSON object out of a text array.
1403−-- exactly one dimension with an even number of members, in which case they are
1385+-- The array must have two dimensions
1404−-- taken as alternating key/value pairs, or two dimensions such that each inner
1386+-- such that each inner array has exactly two elements,
1405−-- array has exactly two elements, which are taken as a key/value pair.
1387+-- which are taken as a key/value pair.
1406jsonObject
1388jsonObject
1407− :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1389+ :: null ('PGfixarray '[n,2] ('NotNull 'PGtext))
1408− => Expression outer grp commons schemas params from (nullity arr)
1390+ :--> null 'PGjson
1409− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1410jsonObject = unsafeFunction "json_object"
1391jsonObject = unsafeFunction "json_object"
1412−-- | Builds a binary JSON object out of a text array. The array must have either
1393+-- | Builds a binary JSON object out of a text array.
1413−-- exactly one dimension with an even number of members, in which case they are
1394+-- The array must have two dimensions
1414−-- taken as alternating key/value pairs, or two dimensions such that each inner
1395+-- such that each inner array has exactly two elements,
1415−-- array has exactly two elements, which are taken as a key/value pair.
1396+-- which are taken as a key/value pair.
1416jsonbObject
1397jsonbObject
1417− :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1398+ :: null ('PGfixarray '[n,2] ('NotNull 'PGtext))
1418− => Expression outer grp commons schemas params from (nullity arr)
1399+ :--> null 'PGjsonb
1419− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1420jsonbObject = unsafeFunction "jsonb_object"
1400jsonbObject = unsafeFunction "jsonb_object"
1422-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1402-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1423-- keys and one for values, that are zipped pairwise to create a JSON object.
1403-- keys and one for values, that are zipped pairwise to create a JSON object.
1424−jsonZipObject
1404+jsonZipObject :: FunctionHet
1425− :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1405+ '[ null ('PGvararray ('NotNull 'PGtext))
1426− , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1406+ , null ('PGvararray ('NotNull 'PGtext)) ]
1427− => Expression outer grp commons schemas params from (nullity keysArray)
1407+ ( null 'PGjson )
1428− -> Expression outer grp commons schemas params from (nullity valuesArray)
1429− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1430−jsonZipObject ks vs =
1408+jsonZipObject = unsafeFunctionHet "json_object"
1431− unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1433−-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1410+-- | This is an alternate form of 'jsonbObject' that takes two arrays; one for
1434-- keys and one for values, that are zipped pairwise to create a binary JSON
1411-- keys and one for values, that are zipped pairwise to create a binary JSON
1435-- object.
1412-- object.
1436−jsonbZipObject
1413+jsonbZipObject :: FunctionHet
1437− :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1414+ '[ null ('PGvararray ('NotNull 'PGtext))
1438− , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1415+ , null ('PGvararray ('NotNull 'PGtext)) ]
1439− => Expression outer grp commons schemas params from (nullity keysArray)
1416+ ( null 'PGjsonb )
1440− -> Expression outer grp commons schemas params from (nullity valuesArray)
1441− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1442−jsonbZipObject ks vs =
1417+jsonbZipObject = unsafeFunctionHet "jsonb_object"
1443− unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1445{-----------------------------------------
1419{-----------------------------------------
1446Table 9.46: JSON processing functions
1420Table 9.46: JSON processing functions
1447-----------------------------------------}
1421-----------------------------------------}
1449-- | Returns the number of elements in the outermost JSON array.
1423-- | Returns the number of elements in the outermost JSON array.
1450−jsonArrayLength
1424+jsonArrayLength :: null 'PGjson :--> null 'PGint4
1451− :: Expression outer grp commons schemas params from (nullity 'PGjson)
1452− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1453jsonArrayLength = unsafeFunction "json_array_length"
1425jsonArrayLength = unsafeFunction "json_array_length"
1455-- | Returns the number of elements in the outermost binary JSON array.
1427-- | Returns the number of elements in the outermost binary JSON array.
1456−jsonbArrayLength
1428+jsonbArrayLength :: null 'PGjsonb :--> null 'PGint4
1457− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1458− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1459jsonbArrayLength = unsafeFunction "jsonb_array_length"
1429jsonbArrayLength = unsafeFunction "jsonb_array_length"
1461-- | Returns JSON value pointed to by the given path (equivalent to #>
1431-- | Returns JSON value pointed to by the given path (equivalent to #>
1462-- operator).
1432-- operator).
1463jsonExtractPath
1433jsonExtractPath
1464 :: SListI elems
1434 :: SListI elems
1465− => Expression outer grp commons schemas params from (nullity 'PGjson)
1435+ => Expression outer commons grp schemas params from (null 'PGjson)
1466− -> NP (Expression outer grp commons schemas params from) elems
1436+ -> NP (Expression outer commons grp schemas params from) elems
1467− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1437+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1468jsonExtractPath x xs =
1438jsonExtractPath x xs =
1469− unsafeVariadicFunction "json_extract_path" (x :* xs)
1439+ unsafeFunctionHet "json_extract_path" (x :* xs)
1471-- | Returns JSON value pointed to by the given path (equivalent to #>
1441-- | Returns JSON value pointed to by the given path (equivalent to #>
1472-- operator).
1442-- operator).
1473jsonbExtractPath
1443jsonbExtractPath
1474 :: SListI elems
1444 :: SListI elems
1475− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1445+ => Expression outer commons grp schemas params from (null 'PGjsonb)
1476− -> NP (Expression outer grp commons schemas params from) elems
1446+ -> NP (Expression outer commons grp schemas params from) elems
1477− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1447+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1478jsonbExtractPath x xs =
1448jsonbExtractPath x xs =
1479− unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1449+ unsafeFunctionHet "jsonb_extract_path" (x :* xs)
1481-- | Returns JSON value pointed to by the given path (equivalent to #>
1451-- | Returns JSON value pointed to by the given path (equivalent to #>
1482-- operator), as text.
1452-- operator), as text.
1483jsonExtractPathAsText
1453jsonExtractPathAsText
1484 :: SListI elems
1454 :: SListI elems
1485− => Expression outer grp commons schemas params from (nullity 'PGjson)
1455+ => Expression outer commons grp schemas params from (null 'PGjson)
1486− -> NP (Expression outer grp commons schemas params from) elems
1456+ -> NP (Expression outer commons grp schemas params from) elems
1487− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1457+ -> Expression outer commons grp schemas params from (null 'PGjson)
1488jsonExtractPathAsText x xs =
1458jsonExtractPathAsText x xs =
1489− unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1459+ unsafeFunctionHet "json_extract_path_text" (x :* xs)
1491-- | Returns JSON value pointed to by the given path (equivalent to #>
1461-- | Returns JSON value pointed to by the given path (equivalent to #>
1492-- operator), as text.
1462-- operator), as text.
1493jsonbExtractPathAsText
1463jsonbExtractPathAsText
1494 :: SListI elems
1464 :: SListI elems
1495− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1465+ => Expression outer commons grp schemas params from (null 'PGjsonb)
1496− -> NP (Expression outer grp commons schemas params from) elems
1466+ -> NP (Expression outer commons grp schemas params from) elems
1497− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1467+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1498jsonbExtractPathAsText x xs =
1468jsonbExtractPathAsText x xs =
1499− unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1469+ unsafeFunctionHet "jsonb_extract_path_text" (x :* xs)
1501-- | Returns the type of the outermost JSON value as a text string. Possible
1471-- | Returns the type of the outermost JSON value as a text string. Possible
1502-- types are object, array, string, number, boolean, and null.
1472-- types are object, array, string, number, boolean, and null.
1503−jsonTypeof
1473+jsonTypeof :: null 'PGjson :--> null 'PGtext
1504− :: Expression outer grp commons schemas params from (nullity 'PGjson)
1505− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1506jsonTypeof = unsafeFunction "json_typeof"
1474jsonTypeof = unsafeFunction "json_typeof"
1508-- | Returns the type of the outermost binary JSON value as a text string.
1476-- | Returns the type of the outermost binary JSON value as a text string.
1509-- Possible types are object, array, string, number, boolean, and null.
1477-- Possible types are object, array, string, number, boolean, and null.
1510−jsonbTypeof
1478+jsonbTypeof :: null 'PGjsonb :--> null 'PGtext
1511− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1512− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1513jsonbTypeof = unsafeFunction "jsonb_typeof"
1479jsonbTypeof = unsafeFunction "jsonb_typeof"
1515-- | Returns its argument with all object fields that have null values omitted.
1481-- | Returns its argument with all object fields that have null values omitted.
1516-- Other null values are untouched.
1482-- Other null values are untouched.
1517−jsonStripNulls
1483+jsonStripNulls :: null 'PGjson :--> null 'PGjson
1518− :: Expression outer grp commons schemas params from (nullity 'PGjson)
1519− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1520jsonStripNulls = unsafeFunction "json_strip_nulls"
1484jsonStripNulls = unsafeFunction "json_strip_nulls"
1522-- | Returns its argument with all object fields that have null values omitted.
1486-- | Returns its argument with all object fields that have null values omitted.
1523-- Other null values are untouched.
1487-- Other null values are untouched.
1524−jsonbStripNulls
1488+jsonbStripNulls :: null 'PGjsonb :--> null 'PGjsonb
1525− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1526− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1527jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1489jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1529-- | @ jsonbSet target path new_value create_missing @
1491-- | @ jsonbSet target path new_value create_missing @
@@ -1534,15 +1496,14 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1534-- operators, negative integers that appear in path count from the end of JSON
1496-- operators, negative integers that appear in path count from the end of JSON
1535-- arrays.
1497-- arrays.
1537− :: PGTextArray "jsonbSet" arr
1538− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1499+ :: Expression outer commons grp schemas params from (null 'PGjsonb)
1539− -> Expression outer grp commons schemas params from (nullity arr)
1500+ -> Expression outer commons grp schemas params from (null ('PGvararray ('NotNull 'PGtext)))
1540− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1501+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1541− -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1502+ -> Maybe (Expression outer commons grp schemas params from (null 'PGbool))
1542− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1503+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1543jsonbSet tgt path val createMissing = case createMissing of
1504jsonbSet tgt path val createMissing = case createMissing of
1544− Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1505+ Just m -> unsafeFunctionHet "jsonb_set" (tgt :* path :* val :* m :* Nil)
1545− Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
1506+ Nothing -> unsafeFunctionHet "jsonb_set" (tgt :* path :* val :* Nil)
1547-- | @ jsonbInsert target path new_value insert_after @
1508-- | @ jsonbInsert target path new_value insert_after @
@@ -1553,39 +1514,120 @@ jsonbSet tgt path val createMissing = case createMissing of
1553-- exist. As with the path orientated operators, negative integers that appear
1514-- exist. As with the path orientated operators, negative integers that appear
1554-- in path count from the end of JSON arrays.
1515-- in path count from the end of JSON arrays.
1555jsonbInsert
1516jsonbInsert
1556− :: PGTextArray "jsonbInsert" arr
1557− => Expression outer grp commons schemas params from (nullity 'PGjsonb)
1517+ :: Expression outer commons grp schemas params from (null 'PGjsonb)
1558− -> Expression outer grp commons schemas params from (nullity arr)
1518+ -> Expression outer commons grp schemas params from (null ('PGvararray ('NotNull 'PGtext)))
1559− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1519+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1560− -> Maybe (Expression outer grp commons schemas params from (nullity 'PGbool))
1520+ -> Maybe (Expression outer commons grp schemas params from (null 'PGbool))
1561− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1521+ -> Expression outer commons grp schemas params from (null 'PGjsonb)
1562jsonbInsert tgt path val insertAfter = case insertAfter of
1522jsonbInsert tgt path val insertAfter = case insertAfter of
1563− Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1523+ Just i -> unsafeFunctionHet "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1564− Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1524+ Nothing -> unsafeFunctionHet "jsonb_insert" (tgt :* path :* val :* Nil)
1566-- | Returns its argument as indented JSON text.
1526-- | Returns its argument as indented JSON text.
1567−jsonbPretty
1527+jsonbPretty :: null 'PGjsonb :--> null 'PGtext
1568− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1569− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1570jsonbPretty = unsafeFunction "jsonb_pretty"
1528jsonbPretty = unsafeFunction "jsonb_pretty"
1530+(@@) :: Operator (null 'PGtsvector) (null 'PGtsquery) ('Null 'PGbool)
1531+(@@) = unsafeBinaryOp "@@"
1533+(.&) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
1534+(.&) = unsafeBinaryOp "&&"
1536+(.|) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
1537+(.|) = unsafeBinaryOp "||"
1539+(.!) :: null 'PGtsquery :--> null 'PGtsquery
1540+(.!) = unsafeUnaryOpL "!!"
1542+(<->) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
1543+(<->) = unsafeBinaryOp "<->"
1546+ :: null ('PGvararray ('NotNull 'PGtext))
1547+ :--> null 'PGtsvector
1548+arrayToTSvector = unsafeFunction "array_to_tsvector"
1550+tsvectorLength :: null 'PGtsvector :--> null 'PGint4
1551+tsvectorLength = unsafeFunction "length"
1553+numnode :: null 'PGtsquery :--> null 'PGint4
1554+numnode = unsafeFunction "numnode"
1556+plainToTSquery :: null 'PGtext :--> null 'PGtsquery
1557+plainToTSquery = unsafeFunction "plainto_tsquery"
1559+phraseToTSquery :: null 'PGtext :--> null 'PGtsquery
1560+phraseToTSquery = unsafeFunction "phraseto_tsquery"
1562+websearchToTSquery :: null 'PGtext :--> null 'PGtsquery
1563+websearchToTSquery = unsafeFunction "websearch_to_tsquery"
1565+queryTree :: null 'PGtsquery :--> null 'PGtext
1566+queryTree = unsafeFunction "query_tree"
1568+toTSquery :: null 'PGtext :--> null 'PGtsquery
1569+toTSquery = unsafeFunction "to_tsquery"
1572+ :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1573+ => null ty :--> null 'PGtsquery
1574+toTSvector = unsafeFunction "to_tsvector"
1577+ :: FunctionHet '[null 'PGtsvector, null ('PGchar 1)] (null 'PGtsvector)
1578+setWeight = unsafeFunctionHet "set_weight"
1580+litChar :: Char -> Expr (null ('PGchar 1))
1581+litChar chr = UnsafeExpression $
1582+ "E\'" <> fromString (escape =<< [chr]) <> "\'"
1584+strip :: null 'PGtsvector :--> null 'PGtsvector
1585+strip = unsafeFunction "strip"
1587+jsonToTSvector :: FunctionHet '[null 'PGjson, null 'PGjson] (null 'PGtsvector)
1588+jsonToTSvector = unsafeFunctionHet "json_to_tsvector"
1590+jsonbToTSvector :: FunctionHet '[null 'PGjsonb, null 'PGjsonb] (null 'PGtsvector)
1591+jsonbToTSvector = unsafeFunctionHet "jsonb_to_tsvector"
1593+tsDelete :: FunctionHet
1594+ '[null 'PGtsvector, null ('PGvararray ('NotNull 'PGtext))]
1596+tsDelete = unsafeFunctionHet "ts_delete"
1598+tsFilter :: FunctionHet
1599+ '[null 'PGtsvector, null ('PGvararray ('NotNull ('PGchar 1)))]
1601+tsFilter = unsafeFunctionHet "ts_filter"
1604+ :: document `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1605+ => FunctionHet '[null document, null 'PGtsquery] (null 'PGtext)
1606+tsHeadline = unsafeFunctionHet "ts_headline"
1572{-----------------------------------------
1607{-----------------------------------------
1573aggregation
1608aggregation
1574-----------------------------------------}
1609-----------------------------------------}
1613+ => ByteString -- ^ function
1614+ -> Distinction (NP (Expression outer commons 'Ungrouped schemas params from)) xs
1615+ -> Expression outer commons ('Grouped bys) schemas params from y
1616+unsafeAggregateHet fun xs = UnsafeExpression $ fun <> parenthesized (renderSQL xs)
1577`Aggregate` functions compute a single result from a set of input values.
1619`Aggregate` functions compute a single result from a set of input values.
1578`Aggregate` functions can be used as `GroupedBy` `Expression`s as well
1620`Aggregate` functions can be used as `GroupedBy` `Expression`s as well
1579as `WindowFunction`s.
1621as `WindowFunction`s.
1581−class Aggregate expr1 expr2 aggr
1623+class Aggregate expr1 exprHet aggr
1582− | aggr -> expr1, aggr -> expr2 where
1624+ | aggr -> expr1, aggr -> exprHet where
1584 -- | A special aggregation that does not require an input
1626 -- | A special aggregation that does not require an input
1586 -- >>> :{
1628 -- >>> :{
1588− -- expression :: Expression '[] ('Grouped bys) commons schemas params from ('NotNull 'PGint8)
1630+ -- expression :: Expression '[] commons ('Grouped bys) schemas params from ('NotNull 'PGint8)
1589 -- expression = countStar
1631 -- expression = countStar
1590 -- in printSQL expression
1632 -- in printSQL expression
@@ -1594,7 +1636,7 @@ class Aggregate expr1 expr2 aggr
1595 -- | >>> :{
1637 -- | >>> :{
1597− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1639+ -- expression :: Expression '[] commons ('Grouped bys) schemas params '[tab ::: '["col" ::: null ty]] ('NotNull 'PGint8)
1598 -- expression = count (All #col)
1640 -- expression = count (All #col)
1599 -- in printSQL expression
1641 -- in printSQL expression
@@ -1606,14 +1648,14 @@ class Aggregate expr1 expr2 aggr
1607 -- | >>> :{
1649 -- | >>> :{
1609− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('NotNull 'PGnumeric)
1651+ -- expression :: Expression '[] commons ('Grouped bys) schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('NotNull 'PGnumeric)
1610 -- expression = sum_ (Distinct #col)
1652 -- expression = sum_ (Distinct #col)
1611 -- in printSQL expression
1653 -- in printSQL expression
1613 -- sum(DISTINCT "col")
1655 -- sum(DISTINCT "col")
1615 :: ty `In` PGNum
1657 :: ty `In` PGNum
1616− => expr1 (nullity ty)
1658+ => expr1 (null ty)
1617 -> aggr ('NotNull ty)
1659 -> aggr ('NotNull ty)
1619 -- | input values, including nulls, concatenated into an array
1661 -- | input values, including nulls, concatenated into an array
@@ -1635,7 +1677,7 @@ class Aggregate expr1 expr2 aggr
1635 the bitwise AND of all non-null input values, or null if none
1677 the bitwise AND of all non-null input values, or null if none
1638− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] ('Null 'PGint4)
1680+ expression :: Expression '[] commons ('Grouped bys) schemas params '[tab ::: '["col" ::: null 'PGint4]] ('Null 'PGint4)
1639 expression = bitAnd (Distinct #col)
1681 expression = bitAnd (Distinct #col)
1640 in printSQL expression
1682 in printSQL expression
@@ -1643,7 +1685,7 @@ class Aggregate expr1 expr2 aggr
1645 :: int `In` PGIntegral
1687 :: int `In` PGIntegral
1646− => expr1 (nullity int)
1688+ => expr1 (null int)
1647 -- ^ what to aggregate
1689 -- ^ what to aggregate
1648 -> aggr ('Null int)
1690 -> aggr ('Null int)
@@ -1652,7 +1694,7 @@ class Aggregate expr1 expr2 aggr
1655− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] ('Null 'PGint4)
1697+ expression :: Expression '[] commons ('Grouped bys) schemas params '[tab ::: '["col" ::: null 'PGint4]] ('Null 'PGint4)
1656 expression = bitOr (All #col)
1698 expression = bitOr (All #col)
1657 in printSQL expression
1699 in printSQL expression
@@ -1660,7 +1702,7 @@ class Aggregate expr1 expr2 aggr
1662 :: int `In` PGIntegral
1704 :: int `In` PGIntegral
1663− => expr1 (nullity int)
1705+ => expr1 (null int)
1664 -- ^ what to aggregate
1706 -- ^ what to aggregate
1665 -> aggr ('Null int)
1707 -> aggr ('Null int)
@@ -1669,14 +1711,14 @@ class Aggregate expr1 expr2 aggr
1672− winFun :: WindowFunction '[] 'Ungrouped commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1714+ winFun :: WindowFunction '[] commons 'Ungrouped schemas params '[tab ::: '["col" ::: null 'PGbool]] ('Null 'PGbool)
1673 winFun = boolAnd #col
1715 winFun = boolAnd #col
1674 in printSQL winFun
1716 in printSQL winFun
1676 bool_and("col")
1718 bool_and("col")
1679− :: expr1 (nullity 'PGbool)
1721+ :: expr1 (null 'PGbool)
1680 -- ^ what to aggregate
1722 -- ^ what to aggregate
1681 -> aggr ('Null 'PGbool)
1723 -> aggr ('Null 'PGbool)
@@ -1685,14 +1727,14 @@ class Aggregate expr1 expr2 aggr
1688− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1730+ expression :: Expression '[] commons ('Grouped bys) schemas params '[tab ::: '["col" ::: null 'PGbool]] ('Null 'PGbool)
1689 expression = boolOr (All #col)
1731 expression = boolOr (All #col)
1690 in printSQL expression
1732 in printSQL expression
1692 bool_or(ALL "col")
1734 bool_or(ALL "col")
1695− :: expr1(nullity 'PGbool)
1737+ :: expr1 (null 'PGbool)
1696 -- ^ what to aggregate
1738 -- ^ what to aggregate
1697 -> aggr ('Null 'PGbool)
1739 -> aggr ('Null 'PGbool)
@@ -1701,185 +1743,185 @@ class Aggregate expr1 expr2 aggr
1704− expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1746+ expression :: Expression '[] commons ('Grouped bys) schemas params '[tab ::: '["col" ::: null 'PGbool]] ('Null 'PGbool)
1705 expression = every (Distinct #col)
1747 expression = every (Distinct #col)
1706 in printSQL expression
1748 in printSQL expression
1708 every(DISTINCT "col")
1750 every(DISTINCT "col")
1711− :: expr1 (nullity 'PGbool)
1753+ :: expr1 (null 'PGbool)
1712 -- ^ what to aggregate
1754 -- ^ what to aggregate
1713 -> aggr ('Null 'PGbool)
1755 -> aggr ('Null 'PGbool)
1715 {- |maximum value of expression across all input values-}
1757 {- |maximum value of expression across all input values-}
1717− :: expr1 (nullity ty)
1759+ :: expr1 (null ty)
1718 -- ^ what to maximize
1760 -- ^ what to maximize
1719 -> aggr ('Null ty)
1761 -> aggr ('Null ty)
1721 -- | minimum value of expression across all input values
1763 -- | minimum value of expression across all input values
1723− :: expr1 (nullity ty)
1765+ :: expr1 (null ty)
1724 -- ^ what to minimize
1766 -- ^ what to minimize
1725 -> aggr ('Null ty)
1767 -> aggr ('Null ty)
1727 -- | the average (arithmetic mean) of all input values
1769 -- | the average (arithmetic mean) of all input values
1729− :: expr1 (nullity ty)
1771+ :: expr1 (null ty)
1730 -- ^ what to average
1772 -- ^ what to average
1731 -> aggr ('Null (PGAvg ty))
1773 -> aggr ('Null (PGAvg ty))
1733 {- | correlation coefficient
1775 {- | correlation coefficient
1736− expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1778+ expression :: Expression '[] c ('Grouped g) s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1737− expression = corr (All (#y :*: #x))
1779+ expression = corr (All (#y *: #x))
1738 in printSQL expression
1780 in printSQL expression
1740 corr(ALL "y", "x")
1782 corr(ALL "y", "x")
1743− :: expr2 (nullity 'PGfloat8)
1785+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1744 -> aggr ('Null 'PGfloat8)
1786 -> aggr ('Null 'PGfloat8)
1746 {- | population covariance
1788 {- | population covariance
1749− expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1791+ expression :: Expression '[] c ('Grouped g) s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1750− expression = covarPop (All (#y :*: #x))
1792+ expression = covarPop (All (#y *: #x))
1751 in printSQL expression
1793 in printSQL expression
1753 covar_pop(ALL "y", "x")
1795 covar_pop(ALL "y", "x")
1755 covarPop
1797 covarPop
1756− :: expr2 (nullity 'PGfloat8)
1798+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1757 -> aggr ('Null 'PGfloat8)
1799 -> aggr ('Null 'PGfloat8)
1759 {- | sample covariance
1801 {- | sample covariance
1762− winFun :: WindowFunction '[] 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1804+ winFun :: WindowFunction '[] c 'Ungrouped s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1763− winFun = covarSamp (#y :*: #x)
1805+ winFun = covarSamp (#y *: #x)
1764 in printSQL winFun
1806 in printSQL winFun
1766 covar_samp("y", "x")
1808 covar_samp("y", "x")
1768 covarSamp
1810 covarSamp
1769− :: expr2 (nullity 'PGfloat8)
1811+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1770 -> aggr ('Null 'PGfloat8)
1812 -> aggr ('Null 'PGfloat8)
1772 {- | average of the independent variable (sum(X)/N)
1814 {- | average of the independent variable (sum(X)/N)
1775− expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1817+ expression :: Expression '[] c ('Grouped g) s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1776− expression = regrAvgX (All (#y :*: #x))
1818+ expression = regrAvgX (All (#y *: #x))
1777 in printSQL expression
1819 in printSQL expression
1779 regr_avgx(ALL "y", "x")
1821 regr_avgx(ALL "y", "x")
1781 regrAvgX
1823 regrAvgX
1782− :: expr2 (nullity 'PGfloat8)
1824+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1783 -> aggr ('Null 'PGfloat8)
1825 -> aggr ('Null 'PGfloat8)
1785 {- | average of the dependent variable (sum(Y)/N)
1827 {- | average of the dependent variable (sum(Y)/N)
1788− winFun :: WindowFunction '[] 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1830+ winFun :: WindowFunction '[] c 'Ungrouped s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1789− winFun = regrAvgY (#y :*: #x)
1831+ winFun = regrAvgY (#y *: #x)
1790 in printSQL winFun
1832 in printSQL winFun
1792 regr_avgy("y", "x")
1834 regr_avgy("y", "x")
1794 regrAvgY
1836 regrAvgY
1795− :: expr2 (nullity 'PGfloat8)
1837+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1796 -> aggr ('Null 'PGfloat8)
1838 -> aggr ('Null 'PGfloat8)
1798 {- | number of input rows in which both expressions are nonnull
1840 {- | number of input rows in which both expressions are nonnull
1801− winFun :: WindowFunction '[] 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGint8)
1843+ winFun :: WindowFunction '[] c 'Ungrouped s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGint8)
1802− winFun = regrCount (#y :*: #x)
1844+ winFun = regrCount (#y *: #x)
1803 in printSQL winFun
1845 in printSQL winFun
1805 regr_count("y", "x")
1847 regr_count("y", "x")
1807 regrCount
1849 regrCount
1808− :: expr2 (nullity 'PGfloat8)
1850+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1809 -> aggr ('Null 'PGint8)
1851 -> aggr ('Null 'PGint8)
1811 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
1853 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
1814− expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1856+ expression :: Expression '[] c ('Grouped g) s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1815− expression = regrIntercept (All (#y :*: #x))
1857+ expression = regrIntercept (All (#y *: #x))
1816 in printSQL expression
1858 in printSQL expression
1818 regr_intercept(ALL "y", "x")
1860 regr_intercept(ALL "y", "x")
1820 regrIntercept
1862 regrIntercept
1821− :: expr2 (nullity 'PGfloat8)
1863+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1822 -> aggr ('Null 'PGfloat8)
1864 -> aggr ('Null 'PGfloat8)
1824 -- | @regr_r2(Y, X)@, square of the correlation coefficient
1866 -- | @regr_r2(Y, X)@, square of the correlation coefficient
1826− :: expr2 (nullity 'PGfloat8)
1868+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1827 -> aggr ('Null 'PGfloat8)
1869 -> aggr ('Null 'PGfloat8)
1829 -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
1871 -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
1830 -- determined by the (X, Y) pairs
1872 -- determined by the (X, Y) pairs
1831 regrSlope
1873 regrSlope
1832− :: expr2 (nullity 'PGfloat8)
1874+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1833 -> aggr ('Null 'PGfloat8)
1875 -> aggr ('Null 'PGfloat8)
1835 -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
1877 -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
1836 -- (“sum of squares” of the independent variable)
1878 -- (“sum of squares” of the independent variable)
1838− :: expr2 (nullity 'PGfloat8)
1880+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1839 -> aggr ('Null 'PGfloat8)
1881 -> aggr ('Null 'PGfloat8)
1841 -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
1883 -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
1842 -- (“sum of products” of independent times dependent variable)
1884 -- (“sum of products” of independent times dependent variable)
1844− :: expr2 (nullity 'PGfloat8)
1886+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1845 -> aggr ('Null 'PGfloat8)
1887 -> aggr ('Null 'PGfloat8)
1847 -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
1889 -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
1848 -- (“sum of squares” of the dependent variable)
1890 -- (“sum of squares” of the dependent variable)
1850− :: expr2 (nullity 'PGfloat8)
1892+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
1851 -> aggr ('Null 'PGfloat8)
1893 -> aggr ('Null 'PGfloat8)
1853 -- | historical alias for `stddevSamp`
1895 -- | historical alias for `stddevSamp`
1855− :: expr1 (nullity ty)
1897+ :: expr1 (null ty)
1856 -> aggr ('Null (PGAvg ty))
1898 -> aggr ('Null (PGAvg ty))
1858 -- | population standard deviation of the input values
1900 -- | population standard deviation of the input values
1859 stddevPop
1901 stddevPop
1860− :: expr1 (nullity ty)
1902+ :: expr1 (null ty)
1861 -> aggr ('Null (PGAvg ty))
1903 -> aggr ('Null (PGAvg ty))
1863 -- | sample standard deviation of the input values
1905 -- | sample standard deviation of the input values
1864 stddevSamp
1906 stddevSamp
1865− :: expr1 (nullity ty)
1907+ :: expr1 (null ty)
1866 -> aggr ('Null (PGAvg ty))
1908 -> aggr ('Null (PGAvg ty))
1868 -- | historical alias for `varSamp`
1910 -- | historical alias for `varSamp`
1869 variance
1911 variance
1870− :: expr1 (nullity ty)
1912+ :: expr1 (null ty)
1871 -> aggr ('Null (PGAvg ty))
1913 -> aggr ('Null (PGAvg ty))
1873 -- | population variance of the input values
1915 -- | population variance of the input values
1874 -- (square of the population standard deviation)
1916 -- (square of the population standard deviation)
1876− :: expr1 (nullity ty)
1918+ :: expr1 (null ty)
1877 -> aggr ('Null (PGAvg ty))
1919 -> aggr ('Null (PGAvg ty))
1879 -- | sample variance of the input values
1921 -- | sample variance of the input values
1880 -- (square of the sample standard deviation)
1922 -- (square of the sample standard deviation)
1882− :: expr1 (nullity ty)
1924+ :: expr1 (null ty)
1883 -> aggr ('Null (PGAvg ty))
1925 -> aggr ('Null (PGAvg ty))
@@ -1888,30 +1930,25 @@ class Aggregate expr1 expr2 aggr
1888`Distinct` invokes the aggregate once for each distinct value of the expression
1930`Distinct` invokes the aggregate once for each distinct value of the expression
1889(or distinct set of values, for multiple expressions) found in the input
1931(or distinct set of values, for multiple expressions) found in the input
1891−data Distinction expr ty
1933+data Distinction (expr :: kind -> Type) (ty :: kind)
1892 = All (expr ty)
1934 = All (expr ty)
1893 | Distinct (expr ty)
1935 | Distinct (expr ty)
1894 deriving (GHC.Generic,Show,Eq,Ord)
1936 deriving (GHC.Generic,Show,Eq,Ord)
1895−instance NFData (Distinction (Expression outer grp commons schemas params from) ty)
1937+instance NFData (Distinction (Expression outer commons grp schemas params from) ty)
1896−instance RenderSQL (Distinction (Expression outer grp commons schemas params from) ty) where
1938+instance RenderSQL (Distinction (Expression outer commons grp schemas params from) ty) where
1897 renderSQL = \case
1939 renderSQL = \case
1898 All x -> "ALL" <+> renderSQL x
1940 All x -> "ALL" <+> renderSQL x
1899 Distinct x -> "DISTINCT" <+> renderSQL x
1941 Distinct x -> "DISTINCT" <+> renderSQL x
1900−instance RenderSQL
1942+instance SOP.SListI tys => RenderSQL
1901− (Distinction
1943+ (Distinction (NP (Expression outer commons grp schemas params from)) tys) where
1902− ( Expression outer grp commons schemas params from
1904− Expression outer grp commons schemas params from) xty ) where
1905− renderSQL = \case
1944+ renderSQL = \case
1906− All (x :*: x') ->
1945+ All xs -> "ALL" <+> renderCommaSeparated renderSQL xs
1907− "ALL" <+> renderSQL x <> ", " <> renderSQL x'
1908− Distinct (x :*: x') ->
1909− "DISTINCT" <+> renderSQL x <> ", " <> renderSQL x'
1946+ Distinct xs -> "DISTINCT" <+> renderCommaSeparated renderSQL xs
1911instance Aggregate
1948instance Aggregate
1912− (Distinction (Expression outer 'Ungrouped commons schemas params from))
1949+ (Distinction (Expression outer commons 'Ungrouped schemas params from))
1913− (Distinction (Expression outer 'Ungrouped commons schemas params from :*: Expression outer 'Ungrouped commons schemas params from))
1950+ (Distinction (NP (Expression outer commons 'Ungrouped schemas params from)))
1914− (Expression outer ('Grouped bys) commons schemas params from) where
1951+ (Expression outer commons ('Grouped bys) schemas params from) where
1915 countStar = UnsafeExpression "count(*)"
1952 countStar = UnsafeExpression "count(*)"
1916 count = unsafeAggregate1 "count"
1953 count = unsafeAggregate1 "count"
1917 sum_ = unsafeAggregate1 "sum"
1954 sum_ = unsafeAggregate1 "sum"
@@ -1926,18 +1963,18 @@ instance Aggregate
1926 max_ = unsafeAggregate1 "max"
1963 max_ = unsafeAggregate1 "max"
1927 min_ = unsafeAggregate1 "min"
1964 min_ = unsafeAggregate1 "min"
1928 avg = unsafeAggregate1 "avg"
1965 avg = unsafeAggregate1 "avg"
1929− corr = unsafeAggregate2 "corr"
1966+ corr = unsafeAggregateHet "corr"
1930− covarPop = unsafeAggregate2 "covar_pop"
1967+ covarPop = unsafeAggregateHet "covar_pop"
1931− covarSamp = unsafeAggregate2 "covar_samp"
1968+ covarSamp = unsafeAggregateHet "covar_samp"
1932− regrAvgX = unsafeAggregate2 "regr_avgx"
1969+ regrAvgX = unsafeAggregateHet "regr_avgx"
1933− regrAvgY = unsafeAggregate2 "regr_avgy"
1970+ regrAvgY = unsafeAggregateHet "regr_avgy"
1934− regrCount = unsafeAggregate2 "regr_count"
1971+ regrCount = unsafeAggregateHet "regr_count"
1935− regrIntercept = unsafeAggregate2 "regr_intercept"
1972+ regrIntercept = unsafeAggregateHet "regr_intercept"
1936− regrR2 = unsafeAggregate2 "regr_r2"
1973+ regrR2 = unsafeAggregateHet "regr_r2"
1937− regrSlope = unsafeAggregate2 "regr_slope"
1974+ regrSlope = unsafeAggregateHet "regr_slope"
1938− regrSxx = unsafeAggregate2 "regr_sxx"
1975+ regrSxx = unsafeAggregateHet "regr_sxx"
1939− regrSxy = unsafeAggregate2 "regr_sxy"
1976+ regrSxy = unsafeAggregateHet "regr_sxy"
1940− regrSyy = unsafeAggregate2 "regr_syy"
1977+ regrSyy = unsafeAggregateHet "regr_syy"
1941 stddev = unsafeAggregate1 "stddev"
1978 stddev = unsafeAggregate1 "stddev"
1942 stddevPop = unsafeAggregate1 "stddev_pop"
1979 stddevPop = unsafeAggregate1 "stddev_pop"
1943 stddevSamp = unsafeAggregate1 "stddev_samp"
1980 stddevSamp = unsafeAggregate1 "stddev_samp"
@@ -1945,9 +1982,9 @@ instance Aggregate
1945 varPop = unsafeAggregate1 "var_pop"
1982 varPop = unsafeAggregate1 "var_pop"
1946 varSamp = unsafeAggregate1 "var_samp"
1983 varSamp = unsafeAggregate1 "var_samp"
1947instance Aggregate
1984instance Aggregate
1948− (Expression outer grp commons schemas params from)
1985+ (Expression outer commons grp schemas params from)
1949− (Expression outer grp commons schemas params from :*: Expression outer grp commons schemas params from)
1986+ (NP (Expression outer commons grp schemas params from))
1950− (WindowFunction outer grp commons schemas params from) where
1987+ (WindowFunction outer commons grp schemas params from) where
1951 countStar = UnsafeWindowFunction "count(*)"
1988 countStar = UnsafeWindowFunction "count(*)"
1952 count = unsafeWindowFunction1 "count"
1989 count = unsafeWindowFunction1 "count"
1953 sum_ = unsafeWindowFunction1 "sum"
1990 sum_ = unsafeWindowFunction1 "sum"
@@ -1962,18 +1999,18 @@ instance Aggregate
1962 max_ = unsafeWindowFunction1 "max"
1999 max_ = unsafeWindowFunction1 "max"
1963 min_ = unsafeWindowFunction1 "min"
2000 min_ = unsafeWindowFunction1 "min"
1964 avg = unsafeWindowFunction1 "avg"
2001 avg = unsafeWindowFunction1 "avg"
1965− corr = unsafeWindowFunction2 "corr"
2002+ corr = unsafeWindowFunctionHet "corr"
1966− covarPop = unsafeWindowFunction2 "covar_pop"
2003+ covarPop = unsafeWindowFunctionHet "covar_pop"
1967− covarSamp = unsafeWindowFunction2 "covar_samp"
2004+ covarSamp = unsafeWindowFunctionHet "covar_samp"
1968− regrAvgX = unsafeWindowFunction2 "regr_avgx"
2005+ regrAvgX = unsafeWindowFunctionHet "regr_avgx"
1969− regrAvgY = unsafeWindowFunction2 "regr_avgy"
2006+ regrAvgY = unsafeWindowFunctionHet "regr_avgy"
1970− regrCount = unsafeWindowFunction2 "regr_count"
2007+ regrCount = unsafeWindowFunctionHet "regr_count"
1971− regrIntercept = unsafeWindowFunction2 "regr_intercept"
2008+ regrIntercept = unsafeWindowFunctionHet "regr_intercept"
1972− regrR2 = unsafeWindowFunction2 "regr_r2"
2009+ regrR2 = unsafeWindowFunctionHet "regr_r2"
1973− regrSlope = unsafeWindowFunction2 "regr_slope"
2010+ regrSlope = unsafeWindowFunctionHet "regr_slope"
1974− regrSxx = unsafeWindowFunction2 "regr_sxx"
2011+ regrSxx = unsafeWindowFunctionHet "regr_sxx"
1975− regrSxy = unsafeWindowFunction2 "regr_sxy"
2012+ regrSxy = unsafeWindowFunctionHet "regr_sxy"
1976− regrSyy = unsafeWindowFunction2 "regr_syy"
2013+ regrSyy = unsafeWindowFunctionHet "regr_syy"
1977 stddev = unsafeWindowFunction1 "stddev"
2014 stddev = unsafeWindowFunction1 "stddev"
1978 stddevPop = unsafeWindowFunction1 "stddev_pop"
2015 stddevPop = unsafeWindowFunction1 "stddev_pop"
1979 stddevSamp = unsafeWindowFunction1 "stddev_samp"
2016 stddevSamp = unsafeWindowFunction1 "stddev_samp"
@@ -1984,18 +2021,9 @@ instance Aggregate
1984-- | escape hatch to define aggregate functions
2021-- | escape hatch to define aggregate functions
1985unsafeAggregate1
2022unsafeAggregate1
1986 :: ByteString -- ^ aggregate function
2023 :: ByteString -- ^ aggregate function
1987− -> Distinction (Expression outer 'Ungrouped commons schemas params from) xty
2024+ -> Distinction (Expression outer commons 'Ungrouped schemas params from) x
1988− -> Expression outer ('Grouped bys) commons schemas params from yty
2025+ -> Expression outer commons ('Grouped bys) schemas params from y
1989−unsafeAggregate1 fun x = UnsafeExpression $ mconcat
2026+unsafeAggregate1 fun x = UnsafeExpression $ fun <> parenthesized (renderSQL x)
1990− [fun, "(", renderSQL x, ")"]
1992−-- | escape hatch to define aggregate binary functions
1994− :: ByteString -- ^ aggregate function
1995− -> Distinction (Expression outer 'Ungrouped commons schemas params from :*: Expression outer 'Ungrouped commons schemas params from) xty
1996− -> Expression outer ('Grouped bys) commons schemas params from yty
1997−unsafeAggregate2 fun xx = UnsafeExpression $ mconcat
1998− [fun, "(", renderSQL xx, ")"]
2000-- | A type family that calculates `PGAvg` type of a `PGType`.
2028-- | A type family that calculates `PGAvg` type of a `PGType`.
2001type family PGAvg ty where
2029type family PGAvg ty where
@@ -2025,7 +2053,7 @@ instance RenderSQL (TypeExpression schemas ty) where
2026 :: (Has sch schemas schema, Has td schema ('Typedef ty))
2054 :: (Has sch schemas schema, Has td schema ('Typedef ty))
2027 => QualifiedAlias sch td
2055 => QualifiedAlias sch td
2028− -> TypeExpression schemas (nullity ty)
2056+ -> TypeExpression schemas (null ty)
2029typedef = UnsafeTypeExpression . renderSQL
2057typedef = UnsafeTypeExpression . renderSQL
2031-- | The composite type corresponding to a `Table` definition can be expressed
2059-- | The composite type corresponding to a `Table` definition can be expressed
@@ -2033,7 +2061,7 @@ typedef = UnsafeTypeExpression . renderSQL
2033typetable
2061typetable
2034 :: (Has sch schemas schema, Has tab schema ('Table table))
2062 :: (Has sch schemas schema, Has tab schema ('Table table))
2035 => QualifiedAlias sch tab
2063 => QualifiedAlias sch tab
2036− -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
2064+ -> TypeExpression schemas (null ('PGcomposite (TableToRow table)))
2037typetable = UnsafeTypeExpression . renderSQL
2065typetable = UnsafeTypeExpression . renderSQL
2039-- | The composite type corresponding to a `View` definition can be expressed
2067-- | The composite type corresponding to a `View` definition can be expressed
@@ -2041,101 +2069,101 @@ typetable = UnsafeTypeExpression . renderSQL
2042 :: (Has sch schemas schema, Has vw schema ('View view))
2070 :: (Has sch schemas schema, Has vw schema ('View view))
2043 => QualifiedAlias sch vw
2071 => QualifiedAlias sch vw
2044− -> TypeExpression schemas (nullity ('PGcomposite view))
2072+ -> TypeExpression schemas (null ('PGcomposite view))
2045typeview = UnsafeTypeExpression . renderSQL
2073typeview = UnsafeTypeExpression . renderSQL
2047-- | logical Boolean (true/false)
2075-- | logical Boolean (true/false)
2048−bool :: TypeExpression schemas (nullity 'PGbool)
2076+bool :: TypeExpression schemas (null 'PGbool)
2049bool = UnsafeTypeExpression "bool"
2077bool = UnsafeTypeExpression "bool"
2050-- | signed two-byte integer
2078-- | signed two-byte integer
2051−int2, smallint :: TypeExpression schemas (nullity 'PGint2)
2079+int2, smallint :: TypeExpression schemas (null 'PGint2)
2052int2 = UnsafeTypeExpression "int2"
2080int2 = UnsafeTypeExpression "int2"
2053smallint = UnsafeTypeExpression "smallint"
2081smallint = UnsafeTypeExpression "smallint"
2054-- | signed four-byte integer
2082-- | signed four-byte integer
2055−int4, int, integer :: TypeExpression schemas (nullity 'PGint4)
2083+int4, int, integer :: TypeExpression schemas (null 'PGint4)
2056int4 = UnsafeTypeExpression "int4"
2084int4 = UnsafeTypeExpression "int4"
2057int = UnsafeTypeExpression "int"
2085int = UnsafeTypeExpression "int"
2058integer = UnsafeTypeExpression "integer"
2086integer = UnsafeTypeExpression "integer"
2059-- | signed eight-byte integer
2087-- | signed eight-byte integer
2060−int8, bigint :: TypeExpression schemas (nullity 'PGint8)
2088+int8, bigint :: TypeExpression schemas (null 'PGint8)
2061int8 = UnsafeTypeExpression "int8"
2089int8 = UnsafeTypeExpression "int8"
2062bigint = UnsafeTypeExpression "bigint"
2090bigint = UnsafeTypeExpression "bigint"
2063-- | arbitrary precision numeric type
2091-- | arbitrary precision numeric type
2064−numeric :: TypeExpression schemas (nullity 'PGnumeric)
2092+numeric :: TypeExpression schemas (null 'PGnumeric)
2065numeric = UnsafeTypeExpression "numeric"
2093numeric = UnsafeTypeExpression "numeric"
2066-- | single precision floating-point number (4 bytes)
2094-- | single precision floating-point number (4 bytes)
2067−float4, real :: TypeExpression schemas (nullity 'PGfloat4)
2095+float4, real :: TypeExpression schemas (null 'PGfloat4)
2068float4 = UnsafeTypeExpression "float4"
2096float4 = UnsafeTypeExpression "float4"
2069real = UnsafeTypeExpression "real"
2097real = UnsafeTypeExpression "real"
2070-- | double precision floating-point number (8 bytes)
2098-- | double precision floating-point number (8 bytes)
2071−float8, doublePrecision :: TypeExpression schemas (nullity 'PGfloat8)
2099+float8, doublePrecision :: TypeExpression schemas (null 'PGfloat8)
2072float8 = UnsafeTypeExpression "float8"
2100float8 = UnsafeTypeExpression "float8"
2073doublePrecision = UnsafeTypeExpression "double precision"
2101doublePrecision = UnsafeTypeExpression "double precision"
2074-- | currency amount
2102-- | currency amount
2075−money :: TypeExpression schema (nullity 'PGmoney)
2103+money :: TypeExpression schema (null 'PGmoney)
2076money = UnsafeTypeExpression "money"
2104money = UnsafeTypeExpression "money"
2077-- | variable-length character string
2105-- | variable-length character string
2078−text :: TypeExpression schemas (nullity 'PGtext)
2106+text :: TypeExpression schemas (null 'PGtext)
2079text = UnsafeTypeExpression "text"
2107text = UnsafeTypeExpression "text"
2080-- | fixed-length character string
2108-- | fixed-length character string
2081char, character
2109char, character
2082− :: forall n schemas nullity. (KnownNat n, 1 <= n)
2110+ :: forall n schemas null. (KnownNat n, 1 <= n)
2083− => TypeExpression schemas (nullity ('PGchar n))
2111+ => TypeExpression schemas (null ('PGchar n))
2084char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
2112char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
2085character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
2113character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
2086-- | variable-length character string
2114-- | variable-length character string
2087varchar, characterVarying
2115varchar, characterVarying
2088− :: forall n schemas nullity. (KnownNat n, 1 <= n)
2116+ :: forall n schemas null. (KnownNat n, 1 <= n)
2089− => TypeExpression schemas (nullity ('PGvarchar n))
2117+ => TypeExpression schemas (null ('PGvarchar n))
2090varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
2118varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
2091characterVarying = UnsafeTypeExpression $
2119characterVarying = UnsafeTypeExpression $
2092 "character varying(" <> renderNat @n <> ")"
2120 "character varying(" <> renderNat @n <> ")"
2093-- | binary data ("byte array")
2121-- | binary data ("byte array")
2094−bytea :: TypeExpression schemas (nullity 'PGbytea)
2122+bytea :: TypeExpression schemas (null 'PGbytea)
2095bytea = UnsafeTypeExpression "bytea"
2123bytea = UnsafeTypeExpression "bytea"
2096-- | date and time (no time zone)
2124-- | date and time (no time zone)
2097−timestamp :: TypeExpression schemas (nullity 'PGtimestamp)
2125+timestamp :: TypeExpression schemas (null 'PGtimestamp)
2098timestamp = UnsafeTypeExpression "timestamp"
2126timestamp = UnsafeTypeExpression "timestamp"
2099-- | date and time, including time zone
2127-- | date and time, including time zone
2100−timestampWithTimeZone :: TypeExpression schemas (nullity 'PGtimestamptz)
2128+timestampWithTimeZone :: TypeExpression schemas (null 'PGtimestamptz)
2101timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
2129timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
2102-- | calendar date (year, month, day)
2130-- | calendar date (year, month, day)
2103−date :: TypeExpression schemas (nullity 'PGdate)
2131+date :: TypeExpression schemas (null 'PGdate)
2104date = UnsafeTypeExpression "date"
2132date = UnsafeTypeExpression "date"
2105-- | time of day (no time zone)
2133-- | time of day (no time zone)
2106−time :: TypeExpression schemas (nullity 'PGtime)
2134+time :: TypeExpression schemas (null 'PGtime)
2107time = UnsafeTypeExpression "time"
2135time = UnsafeTypeExpression "time"
2108-- | time of day, including time zone
2136-- | time of day, including time zone
2109−timeWithTimeZone :: TypeExpression schemas (nullity 'PGtimetz)
2137+timeWithTimeZone :: TypeExpression schemas (null 'PGtimetz)
2110timeWithTimeZone = UnsafeTypeExpression "time with time zone"
2138timeWithTimeZone = UnsafeTypeExpression "time with time zone"
2111-- | time span
2139-- | time span
2112−interval :: TypeExpression schemas (nullity 'PGinterval)
2140+interval :: TypeExpression schemas (null 'PGinterval)
2113interval = UnsafeTypeExpression "interval"
2141interval = UnsafeTypeExpression "interval"
2114-- | universally unique identifier
2142-- | universally unique identifier
2115−uuid :: TypeExpression schemas (nullity 'PGuuid)
2143+uuid :: TypeExpression schemas (null 'PGuuid)
2116uuid = UnsafeTypeExpression "uuid"
2144uuid = UnsafeTypeExpression "uuid"
2117-- | IPv4 or IPv6 host address
2145-- | IPv4 or IPv6 host address
2118−inet :: TypeExpression schemas (nullity 'PGinet)
2146+inet :: TypeExpression schemas (null 'PGinet)
2119inet = UnsafeTypeExpression "inet"
2147inet = UnsafeTypeExpression "inet"
2120-- | textual JSON data
2148-- | textual JSON data
2121−json :: TypeExpression schemas (nullity 'PGjson)
2149+json :: TypeExpression schemas (null 'PGjson)
2122json = UnsafeTypeExpression "json"
2150json = UnsafeTypeExpression "json"
2123-- | binary JSON data, decomposed
2151-- | binary JSON data, decomposed
2124−jsonb :: TypeExpression schemas (nullity 'PGjsonb)
2152+jsonb :: TypeExpression schemas (null 'PGjsonb)
2125jsonb = UnsafeTypeExpression "jsonb"
2153jsonb = UnsafeTypeExpression "jsonb"
2126-- | variable length array
2154-- | variable length array
2128 :: TypeExpression schemas pg
2156 :: TypeExpression schemas pg
2129− -> TypeExpression schemas (nullity ('PGvararray pg))
2157+ -> TypeExpression schemas (null ('PGvararray pg))
2130vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
2158vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
2131-- | fixed length array
2159-- | fixed length array
2133-- >>> renderSQL (fixarray @'[2] json)
2161-- >>> renderSQL (fixarray @'[2] json)
2134-- "json[2]"
2162-- "json[2]"
2136− :: forall dims schemas nullity pg. SOP.All KnownNat dims
2164+ :: forall dims schemas null pg. SOP.All KnownNat dims
2137 => TypeExpression schemas pg
2165 => TypeExpression schemas pg
2138− -> TypeExpression schemas (nullity ('PGfixarray dims pg))
2166+ -> TypeExpression schemas (null ('PGfixarray dims pg))
2139fixarray ty = UnsafeTypeExpression $
2167fixarray ty = UnsafeTypeExpression $
2140 renderSQL ty <> renderDims @dims
2168 renderSQL ty <> renderDims @dims
@@ -2148,38 +2176,45 @@ fixarray ty = UnsafeTypeExpression $
2148 $ hcmap (SOP.Proxy @KnownNat)
2176 $ hcmap (SOP.Proxy @KnownNat)
2149 (K . fromString . show . natVal)
2177 (K . fromString . show . natVal)
2150 (hpure SOP.Proxy :: NP SOP.Proxy ns)
2178 (hpure SOP.Proxy :: NP SOP.Proxy ns)
2179+tsvector :: TypeExpression schemas (null 'PGtsvector)
2180+tsvector = UnsafeTypeExpression "tsvector"
2181+tsquery :: TypeExpression schemas (null 'PGtsquery)
2182+tsquery = UnsafeTypeExpression "tsquery"
2152-- | `pgtype` is a demoted version of a `PGType`
2184-- | `pgtype` is a demoted version of a `PGType`
2153class PGTyped schemas (ty :: NullityType) where
2185class PGTyped schemas (ty :: NullityType) where
2154 pgtype :: TypeExpression schemas ty
2186 pgtype :: TypeExpression schemas ty
2155−instance PGTyped schemas (nullity 'PGbool) where pgtype = bool
2187+instance PGTyped schemas (null 'PGbool) where pgtype = bool
2156−instance PGTyped schemas (nullity 'PGint2) where pgtype = int2
2188+instance PGTyped schemas (null 'PGint2) where pgtype = int2
2157−instance PGTyped schemas (nullity 'PGint4) where pgtype = int4
2189+instance PGTyped schemas (null 'PGint4) where pgtype = int4
2158−instance PGTyped schemas (nullity 'PGint8) where pgtype = int8
2190+instance PGTyped schemas (null 'PGint8) where pgtype = int8
2159−instance PGTyped schemas (nullity 'PGnumeric) where pgtype = numeric
2191+instance PGTyped schemas (null 'PGnumeric) where pgtype = numeric
2160−instance PGTyped schemas (nullity 'PGfloat4) where pgtype = float4
2192+instance PGTyped schemas (null 'PGfloat4) where pgtype = float4
2161−instance PGTyped schemas (nullity 'PGfloat8) where pgtype = float8
2193+instance PGTyped schemas (null 'PGfloat8) where pgtype = float8
2162−instance PGTyped schemas (nullity 'PGtext) where pgtype = text
2194+instance PGTyped schemas (null 'PGmoney) where pgtype = money
2195+instance PGTyped schemas (null 'PGtext) where pgtype = text
2163instance (KnownNat n, 1 <= n)
2196instance (KnownNat n, 1 <= n)
2164− => PGTyped schemas (nullity ('PGchar n)) where pgtype = char @n
2197+ => PGTyped schemas (null ('PGchar n)) where pgtype = char @n
2165instance (KnownNat n, 1 <= n)
2198instance (KnownNat n, 1 <= n)
2166− => PGTyped schemas (nullity ('PGvarchar n)) where pgtype = varchar @n
2199+ => PGTyped schemas (null ('PGvarchar n)) where pgtype = varchar @n
2167−instance PGTyped schemas (nullity 'PGbytea) where pgtype = bytea
2200+instance PGTyped schemas (null 'PGbytea) where pgtype = bytea
2168−instance PGTyped schemas (nullity 'PGtimestamp) where pgtype = timestamp
2201+instance PGTyped schemas (null 'PGtimestamp) where pgtype = timestamp
2169−instance PGTyped schemas (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
2202+instance PGTyped schemas (null 'PGtimestamptz) where pgtype = timestampWithTimeZone
2170−instance PGTyped schemas (nullity 'PGdate) where pgtype = date
2203+instance PGTyped schemas (null 'PGdate) where pgtype = date
2171−instance PGTyped schemas (nullity 'PGtime) where pgtype = time
2204+instance PGTyped schemas (null 'PGtime) where pgtype = time
2172−instance PGTyped schemas (nullity 'PGtimetz) where pgtype = timeWithTimeZone
2205+instance PGTyped schemas (null 'PGtimetz) where pgtype = timeWithTimeZone
2173−instance PGTyped schemas (nullity 'PGinterval) where pgtype = interval
2206+instance PGTyped schemas (null 'PGinterval) where pgtype = interval
2174−instance PGTyped schemas (nullity 'PGuuid) where pgtype = uuid
2207+instance PGTyped schemas (null 'PGuuid) where pgtype = uuid
2175−instance PGTyped schemas (nullity 'PGjson) where pgtype = json
2208+instance PGTyped schemas (null 'PGjson) where pgtype = json
2176−instance PGTyped schemas (nullity 'PGjsonb) where pgtype = jsonb
2209+instance PGTyped schemas (null 'PGjsonb) where pgtype = jsonb
2177instance PGTyped schemas ty
2210instance PGTyped schemas ty
2178− => PGTyped schemas (nullity ('PGvararray ty)) where
2211+ => PGTyped schemas (null ('PGvararray ty)) where
2179 pgtype = vararray (pgtype @schemas @ty)
2212 pgtype = vararray (pgtype @schemas @ty)
2180instance (SOP.All KnownNat dims, PGTyped schemas ty)
2213instance (SOP.All KnownNat dims, PGTyped schemas ty)
2181− => PGTyped schemas (nullity ('PGfixarray dims ty)) where
2214+ => PGTyped schemas (null ('PGfixarray dims ty)) where
2182 pgtype = fixarray @dims (pgtype @schemas @ty)
2215 pgtype = fixarray @dims (pgtype @schemas @ty)
2216+instance PGTyped schemas (null 'PGtsvector) where pgtype = tsvector
2217+instance PGTyped schemas (null 'PGtsquery) where pgtype = tsquery
2184{-----------------------------------------
2219{-----------------------------------------
@@ -2194,26 +2229,26 @@ Sorting
2194-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
2229-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
2195-- determine whether nulls appear before or after non-null values in the sort
2230-- determine whether nulls appear before or after non-null values in the sort
2196-- ordering of a `Null` result column.
2231-- ordering of a `Null` result column.
2197−data SortExpression outer grp commons schemas params from where
2232+data SortExpression outer commons grp schemas params from where
2199− :: Expression outer grp commons schemas params from ('NotNull ty)
2234+ :: Expression outer commons grp schemas params from ('NotNull ty)
2200− -> SortExpression outer grp commons schemas params from
2235+ -> SortExpression outer commons grp schemas params from
2202− :: Expression outer grp commons schemas params from ('NotNull ty)
2237+ :: Expression outer commons grp schemas params from ('NotNull ty)
2203− -> SortExpression outer grp commons schemas params from
2238+ -> SortExpression outer commons grp schemas params from
2204 AscNullsFirst
2239 AscNullsFirst
2205− :: Expression outer grp commons schemas params from ('Null ty)
2240+ :: Expression outer commons grp schemas params from ('Null ty)
2206− -> SortExpression outer grp commons schemas params from
2241+ -> SortExpression outer commons grp schemas params from
2207 AscNullsLast
2242 AscNullsLast
2208− :: Expression outer grp commons schemas params from ('Null ty)
2243+ :: Expression outer commons grp schemas params from ('Null ty)
2209− -> SortExpression outer grp commons schemas params from
2244+ -> SortExpression outer commons grp schemas params from
2210 DescNullsFirst
2245 DescNullsFirst
2211− :: Expression outer grp commons schemas params from ('Null ty)
2246+ :: Expression outer commons grp schemas params from ('Null ty)
2212− -> SortExpression outer grp commons schemas params from
2247+ -> SortExpression outer commons grp schemas params from
2213 DescNullsLast
2248 DescNullsLast
2214− :: Expression outer grp commons schemas params from ('Null ty)
2249+ :: Expression outer commons grp schemas params from ('Null ty)
2215− -> SortExpression outer grp commons schemas params from
2250+ -> SortExpression outer commons grp schemas params from
2216−deriving instance Show (SortExpression outer grp commons schemas params from)
2251+deriving instance Show (SortExpression outer commons grp schemas params from)
2219The `orderBy` clause causes the result rows of a `Squeal.PostgreSQL.Query.TableExpression`
2254The `orderBy` clause causes the result rows of a `Squeal.PostgreSQL.Query.TableExpression`
@@ -2228,12 +2263,12 @@ using `orderBy` within `Squeal.PostgreSQL.Query.Over`.
2229class OrderBy expr where
2264class OrderBy expr where
2231− :: [SortExpression outer grp commons schemas params from]
2266+ :: [SortExpression outer commons grp schemas params from]
2232− -> expr outer grp commons schemas params from
2267+ -> expr outer commons grp schemas params from
2233− -> expr outer grp commons schemas params from
2268+ -> expr outer commons grp schemas params from
2235-- | Render a `SortExpression`.
2270-- | Render a `SortExpression`.
2236−instance RenderSQL (SortExpression outer grp commons schemas params from) where
2271+instance RenderSQL (SortExpression outer commons grp schemas params from) where
2237 renderSQL = \case
2272 renderSQL = \case
2238 Asc expression -> renderSQL expression <+> "ASC"
2273 Asc expression -> renderSQL expression <+> "ASC"
2239 Desc expression -> renderSQL expression <+> "DESC"
2274 Desc expression -> renderSQL expression <+> "DESC"
@@ -2246,12 +2281,12 @@ instance RenderSQL (SortExpression outer grp commons schemas params from) where
2247-- | A `WindowDefinition` is a set of table rows that are somehow related
2282-- | A `WindowDefinition` is a set of table rows that are somehow related
2248-- to the current row
2283-- to the current row
2249−data WindowDefinition outer grp commons schemas params from where
2284+data WindowDefinition outer commons grp schemas params from where
2250 WindowDefinition
2285 WindowDefinition
2251 :: SListI bys
2286 :: SListI bys
2252− => NP (Expression outer grp commons schemas params from) bys
2287+ => NP (Expression outer commons grp schemas params from) bys
2253− -> [SortExpression outer grp commons schemas params from]
2288+ -> [SortExpression outer commons grp schemas params from]
2254− -> WindowDefinition outer grp commons schemas params from
2289+ -> WindowDefinition outer commons grp schemas params from
2256instance OrderBy WindowDefinition where
2291instance OrderBy WindowDefinition where
2257 orderBy sortsR (WindowDefinition parts sortsL)
2292 orderBy sortsR (WindowDefinition parts sortsL)
@@ -2277,8 +2312,8 @@ the same partition as the current row.
2278partitionBy
2313partitionBy
2279 :: SListI bys
2314 :: SListI bys
2280− => NP (Expression outer grp commons schemas params from) bys
2315+ => NP (Expression outer commons grp schemas params from) bys
2281− -> WindowDefinition outer grp commons schemas params from
2316+ -> WindowDefinition outer commons grp schemas params from
2282partitionBy bys = WindowDefinition bys []
2317partitionBy bys = WindowDefinition bys []
@@ -2293,8 +2328,8 @@ just the current row of the query result.
2294newtype WindowFunction
2329newtype WindowFunction
2295 (outer :: FromType)
2330 (outer :: FromType)
2297 (commons :: FromType)
2331 (commons :: FromType)
2298 (schemas :: SchemasType)
2333 (schemas :: SchemasType)
2299 (params :: [NullityType])
2334 (params :: [NullityType])
2300 (from :: FromType)
2335 (from :: FromType)
@@ -2302,49 +2337,62 @@ newtype WindowFunction
2302 = UnsafeWindowFunction { renderWindowFunction :: ByteString }
2337 = UnsafeWindowFunction { renderWindowFunction :: ByteString }
2303 deriving (GHC.Generic,Show,Eq,Ord,NFData)
2338 deriving (GHC.Generic,Show,Eq,Ord,NFData)
2305−instance RenderSQL (WindowFunction outer grp commons schemas params from ty) where
2340+instance RenderSQL (WindowFunction outer commons grp schemas params from ty) where
2306 renderSQL = renderWindowFunction
2341 renderSQL = renderWindowFunction
2344+ = forall outer commons grp schemas params from
2345+ . WindowFunction outer commons grp schemas params from x
2346+ -- ^ cannot reference aliases
2349+ = forall outer commons grp schemas params from
2350+ . Expression outer commons grp schemas params from x
2352+ -> WindowFunction outer commons grp schemas params from y
2356+ = forall outer commons grp schemas params from
2357+ . NP (Expression outer commons grp schemas params from) xs
2359+ -> WindowFunction outer commons grp schemas params from y
2308−unsafeWindowFunction1
2362+unsafeWindowFunction1 :: ByteString -> WinFun1 x y
2310− -> Expression outer grp commons schemas params from ty0
2311− -> WindowFunction outer grp commons schemas params from ty1
2312unsafeWindowFunction1 fun x
2363unsafeWindowFunction1 fun x
2313 = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x)
2364 = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x)
2315−unsafeWindowFunction2
2366+unsafeWindowFunctionHet :: SOP.SListI xs => ByteString -> WinFunHet xs y
2316− :: ByteString
2367+unsafeWindowFunctionHet fun xs = UnsafeWindowFunction $ fun <>
2317− -> (Expression outer grp commons schemas params from :*: Expression outer grp commons schemas params from) ty0
2318− -> WindowFunction outer grp commons schemas params from ty1
2319−unsafeWindowFunction2 fun (x :*: x')
2320− = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x <> ", " <> renderSQL x')
2368+ parenthesized (renderCommaSeparated renderSQL xs)
2322{- | rank of the current row with gaps; same as `rowNumber` of its first peer
2370{- | rank of the current row with gaps; same as `rowNumber` of its first peer
2323>>> printSQL rank
2371>>> printSQL rank
2326−rank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
2374+rank :: WinFun0 ('NotNull 'PGint8)
2327rank = UnsafeWindowFunction "rank()"
2375rank = UnsafeWindowFunction "rank()"
2329{- | number of the current row within its partition, counting from 1
2377{- | number of the current row within its partition, counting from 1
2330>>> printSQL rowNumber
2378>>> printSQL rowNumber
2331row_number()
2379row_number()
2333−rowNumber :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
2381+rowNumber :: WinFun0 ('NotNull 'PGint8)
2334rowNumber = UnsafeWindowFunction "row_number()"
2382rowNumber = UnsafeWindowFunction "row_number()"
2336{- | rank of the current row without gaps; this function counts peer groups
2384{- | rank of the current row without gaps; this function counts peer groups
2337>>> printSQL denseRank
2385>>> printSQL denseRank
2338dense_rank()
2386dense_rank()
2340−denseRank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
2388+denseRank :: WinFun0 ('NotNull 'PGint8)
2341denseRank = UnsafeWindowFunction "dense_rank()"
2389denseRank = UnsafeWindowFunction "dense_rank()"
2343{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
2391{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
2344>>> printSQL percentRank
2392>>> printSQL percentRank
2345percent_rank()
2393percent_rank()
2347−percentRank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGfloat8)
2395+percentRank :: WinFun0 ('NotNull 'PGfloat8)
2348percentRank = UnsafeWindowFunction "percent_rank()"
2396percentRank = UnsafeWindowFunction "percent_rank()"
2350{- | cumulative distribution: (number of partition rows
2398{- | cumulative distribution: (number of partition rows
@@ -2352,16 +2400,13 @@ preceding or peer with current row) / total partition rows
2352>>> printSQL cumeDist
2400>>> printSQL cumeDist
2353cume_dist()
2401cume_dist()
2355−cumeDist :: WindowFunction outer grp commons schemas params from ('NotNull 'PGfloat8)
2403+cumeDist :: WinFun0 ('NotNull 'PGfloat8)
2356cumeDist = UnsafeWindowFunction "cume_dist()"
2404cumeDist = UnsafeWindowFunction "cume_dist()"
2358{- | integer ranging from 1 to the argument value,
2406{- | integer ranging from 1 to the argument value,
2359dividing the partition as equally as possible
2407dividing the partition as equally as possible
2361−ntile
2409+ntile :: WinFun1 ('NotNull 'PGint4) ('NotNull 'PGint4)
2362− :: Expression outer grp commons schemas params from ('NotNull 'PGint4)
2364− -> WindowFunction outer grp commons schemas params from ('NotNull 'PGint4)
2365ntile = unsafeWindowFunction1 "ntile"
2410ntile = unsafeWindowFunction1 "ntile"
2367{- | returns value evaluated at the row that is offset rows before the current
2412{- | returns value evaluated at the row that is offset rows before the current
@@ -2369,188 +2414,110 @@ row within the partition; if there is no such row, instead return default
2369(which must be of the same type as value). Both offset and default are
2414(which must be of the same type as value). Both offset and default are
2370evaluated with respect to the current row.
2415evaluated with respect to the current row.
2372−lag
2417+lag :: WinFunHet '[ty, 'NotNull 'PGint4, ty] ty
2373− :: Expression outer grp commons schemas params from ty
2418+lag = unsafeWindowFunctionHet "lag"
2375− -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2377− -> Expression outer grp commons schemas params from ty
2379− -> WindowFunction outer grp commons schemas params from ty
2380−lag value offset def = UnsafeWindowFunction $ "lag"
2382− (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
2384{- | returns value evaluated at the row that is offset rows after the current
2420{- | returns value evaluated at the row that is offset rows after the current
2385row within the partition; if there is no such row, instead return default
2421row within the partition; if there is no such row, instead return default
2386(which must be of the same type as value). Both offset and default are
2422(which must be of the same type as value). Both offset and default are
2387evaluated with respect to the current row.
2423evaluated with respect to the current row.
2389−lead
2425+lead :: WinFunHet '[ty, 'NotNull 'PGint4, ty] ty
2390− :: Expression outer grp commons schemas params from ty
2426+lead = unsafeWindowFunctionHet "lag"
2392− -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2394− -> Expression outer grp commons schemas params from ty
2396− -> WindowFunction outer grp commons schemas params from ty
2397−lead value offset def = UnsafeWindowFunction $ "lag"
2399− (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
2401{- | returns value evaluated at the row that is the
2428{- | returns value evaluated at the row that is the
2402first row of the window frame
2429first row of the window frame
2404−firstValue
2431+firstValue :: WinFun1 ty ty
2405− :: Expression outer grp commons schemas params from ty
2407− -> WindowFunction outer grp commons schemas params from ty
2408firstValue = unsafeWindowFunction1 "first_value"
2432firstValue = unsafeWindowFunction1 "first_value"
2410{- | returns value evaluated at the row that is the
2434{- | returns value evaluated at the row that is the
2411last row of the window frame
2435last row of the window frame
2413−lastValue
2437+lastValue :: WinFun1 ty ty
2414− :: Expression outer grp commons schemas params from ty
2416− -> WindowFunction outer grp commons schemas params from ty
2417lastValue = unsafeWindowFunction1 "last_value"
2438lastValue = unsafeWindowFunction1 "last_value"
2419{- | returns value evaluated at the row that is the nth
2440{- | returns value evaluated at the row that is the nth
2420row of the window frame (counting from 1); null if no such row
2441row of the window frame (counting from 1); null if no such row
2422−nthValue
2443+nthValue :: WinFunHet '[null ty, 'NotNull 'PGint4] ('Null ty)
2423− :: Expression outer grp commons schemas params from (nullity ty)
2425− -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2427− -> WindowFunction outer grp commons schemas params from ('Null ty)
2428−nthValue value nth = UnsafeWindowFunction $ "nth_value"
2444+nthValue = unsafeWindowFunctionHet "nth_value"
2429− <> parenthesized (commaSeparated [renderSQL value, renderSQL nth])
2432Create date from year, month and day fields
2447Create date from year, month and day fields
2434−>>> printSQL (makeDate 1984 7 3)
2449+>>> printSQL (makeDate (1984 :* 7 *: 3))
2435make_date(1984, 7, 3)
2450make_date(1984, 7, 3)
2437−makeDate
2452+makeDate :: FunctionHet
2438− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2453+ '[ null 'PGint4, null 'PGint4, null 'PGint4 ]
2439− -- ^ year
2454+ ( null 'PGdate )
2440− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2442− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2444− -> Expression outer grp commons schemas params from (nullity 'PGdate)
2445−makeDate y m d = UnsafeExpression $ "make_date" <>
2455+makeDate = unsafeFunctionHet "make_date"
2446− parenthesized (renderCommaSeparated renderSQL (y :* m :* d :* Nil))
2449Create time from hour, minute and seconds fields
2458Create time from hour, minute and seconds fields
2451−>>> printSQL (makeTime 8 15 23.5)
2460+>>> printSQL (makeTime (8 :* 15 *: 23.5))
2452make_time(8, 15, 23.5)
2461make_time(8, 15, 23.5)
2454−makeTime
2463+makeTime :: FunctionHet
2455− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2464+ '[ null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2456− -- ^ hour
2465+ ( null 'PGtime )
2457− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2459− -> Expression outer grp commons schemas params from (nullity 'PGfloat8)
2461− -> Expression outer grp commons schemas params from (nullity 'PGtime)
2462−makeTime h m s = UnsafeExpression $ "make_time" <>
2466+makeTime = unsafeFunctionHet "make_time"
2463− parenthesized (renderCommaSeparated renderSQL (h :* m :* s :* Nil))
2466Create timestamp from year, month, day, hour, minute and seconds fields
2469Create timestamp from year, month, day, hour, minute and seconds fields
2468−>>> printSQL (makeTimestamp 2013 7 15 8 15 23.5)
2471+>>> printSQL (makeTimestamp (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
2469make_timestamp(2013, 7, 15, 8, 15, 23.5)
2472make_timestamp(2013, 7, 15, 8, 15, 23.5)
2471−makeTimestamp
2474+makeTimestamp :: FunctionHet
2472− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2475+ '[ null 'PGint4, null 'PGint4, null 'PGint4
2473− -- ^ year
2476+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2474− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2477+ ( null 'PGtimestamp )
2476− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2478− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2480− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2482− -> Expression outer grp commons schemas params from (nullity 'PGfloat8)
2484− -> Expression outer grp commons schemas params from (nullity 'PGtimestamp)
2485−makeTimestamp y mon d h m s =
2478+makeTimestamp = unsafeFunctionHet "make_timestamp"
2486− UnsafeExpression $ "make_timestamp" <> parenthesized
2487− (renderCommaSeparated renderSQL (y :* mon :* d :* h :* m :* s :* Nil))
2490Create timestamp with time zone from
2481Create timestamp with time zone from
2491year, month, day, hour, minute and seconds fields;
2482year, month, day, hour, minute and seconds fields;
2492the current time zone is used
2483the current time zone is used
2494−>>> printSQL (makeTimestamptz 2013 7 15 8 15 23.5)
2485+>>> printSQL (makeTimestamptz (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
2495make_timestamptz(2013, 7, 15, 8, 15, 23.5)
2486make_timestamptz(2013, 7, 15, 8, 15, 23.5)
2497−makeTimestamptz
2488+makeTimestamptz :: FunctionHet
2498− :: Expression outer grp commons schemas params from (nullity 'PGint4)
2489+ '[ null 'PGint4, null 'PGint4, null 'PGint4
2499− -- ^ year
2490+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
2500− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2491+ ( null 'PGtimestamptz )
2502− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2504− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2506− -> Expression outer grp commons schemas params from (nullity 'PGint4)
2508− -> Expression outer grp commons schemas params from (nullity 'PGfloat8)
2510− -> Expression outer grp commons schemas params from (nullity 'PGtimestamptz)
2511−makeTimestamptz y mon d h m s =
2492+makeTimestamptz = unsafeFunctionHet "make_timestamptz"
2512− UnsafeExpression $ "make_timestamptz" <> parenthesized
2513− (renderCommaSeparated renderSQL (y :* mon :* d :* h :* m :* s :* Nil))
2516Affine space operations on time types.
2495Affine space operations on time types.
2518class TimeOp time diff | time -> diff where
2497class TimeOp time diff | time -> diff where
2520− >>> printSQL (makeDate 1984 7 3 !+ 365)
2499+ >>> printSQL (makeDate (1984 :* 7 *: 3) !+ 365)
2521 (make_date(1984, 7, 3) + 365)
2500 (make_date(1984, 7, 3) + 365)
2523− (!+)
2502+ (!+) :: Operator (null time) (null diff) (null time)
2524− :: Expression outer grp commons schemas params from (nullity time)
2525− -> Expression outer grp commons schemas params from (nullity diff)
2526− -> Expression outer grp commons schemas params from (nullity time)
2527 (!+) = unsafeBinaryOp "+"
2503 (!+) = unsafeBinaryOp "+"
2529− >>> printSQL (365 +! makeDate 1984 7 3)
2505+ >>> printSQL (365 +! makeDate (1984 :* 7 *: 3))
2530 (365 + make_date(1984, 7, 3))
2506 (365 + make_date(1984, 7, 3))
2532− (+!)
2508+ (+!) :: Operator (null diff) (null time) (null time)
2533− :: Expression outer grp commons schemas params from (nullity diff)
2534− -> Expression outer grp commons schemas params from (nullity time)
2535− -> Expression outer grp commons schemas params from (nullity time)
2536 (+!) = unsafeBinaryOp "+"
2509 (+!) = unsafeBinaryOp "+"
2538− >>> printSQL (makeDate 1984 7 3 !- 365)
2511+ >>> printSQL (makeDate (1984 :* 7 *: 3) !- 365)
2539 (make_date(1984, 7, 3) - 365)
2512 (make_date(1984, 7, 3) - 365)
2541− (!-)
2514+ (!-) :: Operator (null time) (null diff) (null time)
2542− :: Expression outer grp commons schemas params from (nullity time)
2543− -> Expression outer grp commons schemas params from (nullity diff)
2544− -> Expression outer grp commons schemas params from (nullity time)
2545 (!-) = unsafeBinaryOp "-"
2515 (!-) = unsafeBinaryOp "-"
2547− >>> printSQL (makeDate 1984 7 3 !-! currentDate)
2517+ >>> printSQL (makeDate (1984 :* 7 *: 3) !-! currentDate)
2548 (make_date(1984, 7, 3) - CURRENT_DATE)
2518 (make_date(1984, 7, 3) - CURRENT_DATE)
2550− (!-!)
2520+ (!-!) :: Operator (null time) (null time) (null diff)
2551− :: Expression outer grp commons schemas params from (nullity time)
2552− -> Expression outer grp commons schemas params from (nullity time)
2553− -> Expression outer grp commons schemas params from (nullity diff)
2554 (!-!) = unsafeBinaryOp "-"
2521 (!-!) = unsafeBinaryOp "-"
2555instance TimeOp 'PGtimestamp 'PGinterval
2522instance TimeOp 'PGtimestamp 'PGinterval
2556instance TimeOp 'PGtimestamptz 'PGinterval
2523instance TimeOp 'PGtimestamptz 'PGinterval
@@ -2562,3 +2529,30 @@ infixl 6 !+
2562infixl 6 +!
2529infixl 6 +!
2563infixl 6 !-
2530infixl 6 !-
2564infixl 6 !-!
2531infixl 6 !-!
2534+ = Years | Months | Weeks | Days
2535+ | Hours | Minutes | Seconds
2536+ | Microseconds | Milliseconds
2537+ | Decades | Centuries | Millennia
2538+ deriving (Eq, Ord, Show, Read, Enum, GHC.Generic)
2539+instance RenderSQL TimeUnit where
2546+ Minutes -> "minutes"
2547+ Seconds -> "seconds"
2548+ Microseconds -> "microseconds"
2549+ Milliseconds -> "milliseconds"
2550+ Decades -> "decades"
2551+ Centuries -> "centuries"
2552+ Millennia -> "millennia"
2554+-- | >>> printSQL $ interval_ 7 Days
2555+-- (INTERVAL '7.0 days')
2556+interval_ :: Double -> TimeUnit -> Expr (null 'PGinterval)
2557+interval_ num unit = UnsafeExpression . parenthesized $ "INTERVAL" <+>
2558+ "'" <> fromString (show num) <+> renderSQL unit <> "'"