@@ -35,19 +35,19 @@ module Squeal.PostgreSQL.Expression
3535 ( -- * Expression
3636 Expression (..)
3737 , Expr
38− , Operator
39− , unsafeBinaryOp
4038 , (:-->)
39+ , unsafeFunction
4140 , unsafeUnaryOpL
4241 , unsafeUnaryOpR
43− , unsafeFunction
44− , FunctionHom
45− , unsafeFunctionHom
46− , FunctionHet
47− , unsafeFunctionHet
42+ , Operator
43+ , unsafeBinaryOp
44+ , FunctionVar
45+ , unsafeFunctionVar
46+ , FunctionN
47+ , unsafeFunctionN
48+ , Literal (..)
4849 , HasParameter (parameter)
4950 , param
50− , Literal (..)
5151 -- * Null
5252 , null_
5353 , notNull
@@ -66,31 +66,31 @@ module Squeal.PostgreSQL.Expression
6666 , row
6767 , field
6868 , PGSubset (..)
69− -- * Functions
69+ -- * Numerical
7070 , atan2_
71− , cast
7271 , quot_
7372 , rem_
7473 , trunc
7574 , round_
7675 , ceiling_
77− , greatest
78− , least
79− -- * Conditions
76+ -- * Logic
77+ , Condition
8078 , true
8179 , false
8280 , not_
8381 , (.&&)
8482 , (.||)
85− , Condition
8683 , caseWhenThenElse
8784 , ifThenElse
85+ -- * Comparison
8886 , (.==)
8987 , (./=)
9088 , (.>=)
9189 , (.<)
9290 , (.<=)
9391 , (.>)
92+ , greatest
93+ , least
9494 , between
9595 , notBetween
9696 , betweenSymmetric
@@ -208,6 +208,7 @@ module Squeal.PostgreSQL.Expression
208208 , OrderBy (..)
209209 -- * Types
210210 , TypeExpression (..)
211+ , cast
211212 , PGTyped (..)
212213 , typedef
213214 , typetable
@@ -286,7 +287,8 @@ column expressions
286287-----------------------------------------}
287288
288289{- | `Expression`s are used in a variety of contexts,
289−such as in the target list of the `Squeal.PostgreSQL.Query.select` command,
290+such as in the target `Squeal.PostgreSQL.Query.List` of the
291+`Squeal.PostgreSQL.Query.select` command,
290292as new column values in `Squeal.PostgreSQL.Manipulation.insertRow` or
291293`Squeal.PostgreSQL.Manipulation.update`,
292294or in search `Condition`s in a number of commands.
@@ -294,6 +296,19 @@ or in search `Condition`s in a number of commands.
294296The expression syntax allows the calculation of
295297values from primitive expression using arithmetic, logical,
296298and other operations.
299+
300+The type paremeters of `Expression` are
301+
302+* @outer :: @ `FromType`, the @from@ clauses of any outer queries in which
303+ the `Expression` is a correlated subquery expression;
304+* @commons :: @ `FromType`, `Squeal.PostgreSQL.Query.CommonTableExpression`s that are in
305+ scope for the `Expression`;
306+* @grp :: @ `Grouping`, the `Grouping` of the @from@ clause which may limit
307+ which columns may be referenced by alias;
308+* @schemas :: @ `SchemasType`, the schemas of your database;
309+* @from :: @ `FromType`, the @from@ clause which the `Expression` may use
310+ to reference columns by alias;
311+* @ty :: @ `NullityType`, the type of the `Expression`.
297312-}
298313newtype Expression
299314 (outer :: FromType)
@@ -344,10 +359,10 @@ type (:-->) x y
344359{- | A `RankNType` for functions with a fixed-length list of heterogeneous arguments.
345360Use the `*:` operator to end your argument lists, like so.
346361
347−>>> printSQL (unsafeFunctionHet "fun" (true :* false :* localTime *: true))
362+>>> printSQL (unsafeFunctionN "fun" (true :* false :* localTime *: true))
348363fun(TRUE, FALSE, LOCALTIME, TRUE)
349364-}
350−type FunctionHet xs y
365+type FunctionN xs y
351366 = forall outer commons grp schemas params from
352367 . NP (Expression outer commons grp schemas params from) xs
353368 -- ^ inputs
@@ -357,7 +372,7 @@ type FunctionHet xs y
357372{- | A `RankNType` for functions with a variable-length list of
358373homogeneous arguments and at least 1 more argument.
359374-}
360−type FunctionHom x0 x1 y
375+type FunctionVar x0 x1 y
361376 = forall outer commons grp schemas params from
362377 . [Expression outer commons grp schemas params from x0]
363378 -- ^ inputs
@@ -366,11 +381,11 @@ type FunctionHom x0 x1 y
366381 -> Expression outer commons grp schemas params from y
367382 -- ^ output
368383
369−{- | >>> printSQL (unsafeFunctionHom "greatest" [true, null_] false)
384+{- | >>> printSQL (unsafeFunctionVar "greatest" [true, null_] false)
370385greatest(TRUE, NULL, FALSE)
371386-}
372−unsafeFunctionHom :: ByteString -> FunctionHom x0 x1 y
373−unsafeFunctionHom fun xs x = UnsafeExpression $ fun <> parenthesized
387+unsafeFunctionVar :: ByteString -> FunctionVar x0 x1 y
388+unsafeFunctionVar fun xs x = UnsafeExpression $ fun <> parenthesized
374389 (commaSeparated (renderSQL <$> xs) <> ", " <> renderSQL x)
375390
376391{- | A `HasParameter` constraint is used to indicate a value that is
@@ -527,7 +542,7 @@ notNull = UnsafeExpression . renderSQL
527542--
528543-- >>> printSQL $ coalesce [null_, true] false
529544-- COALESCE(NULL, TRUE, FALSE)
530−coalesce :: FunctionHom ('Null ty) ('NotNull ty) ('NotNull ty)
545+coalesce :: FunctionVar ('Null ty) ('NotNull ty) ('NotNull ty)
531546coalesce nullxs notNullx = UnsafeExpression $
532547 "COALESCE" <> parenthesized (commaSeparated
533548 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
@@ -576,8 +591,8 @@ matchNull y f x = ifThenElse (isNull x) y
576591>>> printSQL expr
577592NULLIF(FALSE, ($1 :: bool))
578593-}
579−nullIf :: FunctionHet '[ 'NotNull ty, 'NotNull ty] ('Null ty)
580−nullIf = unsafeFunctionHet "NULLIF"
594+nullIf :: FunctionN '[ 'NotNull ty, 'NotNull ty] ('Null ty)
595+nullIf = unsafeFunctionN "NULLIF"
581596
582597-- | >>> printSQL $ array [null_, false, true]
583598-- ARRAY[NULL, FALSE, TRUE]
@@ -709,13 +724,13 @@ instance Monoid
709724-- | >>> let expr = greatest [param @1] currentTimestamp :: Expression outer commons grp schemas '[ 'NotNull 'PGtimestamptz] from ('NotNull 'PGtimestamptz)
710725-- >>> printSQL expr
711726-- GREATEST(($1 :: timestamp with time zone), CURRENT_TIMESTAMP)
712−greatest :: FunctionHom ty ty ty
713−greatest = unsafeFunctionHom "GREATEST"
727+greatest :: FunctionVar ty ty ty
728+greatest = unsafeFunctionVar "GREATEST"
714729
715730-- | >>> printSQL $ least [null_] currentTimestamp
716731-- LEAST(NULL, CURRENT_TIMESTAMP)
717−least :: FunctionHom ty ty ty
718−least = unsafeFunctionHom "LEAST"
732+least :: FunctionVar ty ty ty
733+least = unsafeFunctionVar "LEAST"
719734
720735-- | >>> printSQL $ unsafeBinaryOp "OR" true false
721736-- (TRUE OR FALSE)
@@ -739,13 +754,13 @@ unsafeFunction :: ByteString {- ^ function -} -> x :--> y
739754unsafeFunction fun x = UnsafeExpression $
740755 fun <> parenthesized (renderSQL x)
741756
742−-- | >>> printSQL $ unsafeFunctionHet "f" (currentTime :* localTimestamp :* false *: literal 'a')
743−-- f(CURRENT_TIME, LOCALTIMESTAMP, FALSE, (E'a' :: char(1)))
744−unsafeFunctionHet
757+-- | >>> printSQL $ unsafeFunctionN "f" (currentTime :* localTimestamp :* false *: literal 'a')
758+-- f(CURRENT_TIME, LOCALTIMESTAMP, FALSE, E'a')
759+unsafeFunctionN
745760 :: SListI xs
746761 => ByteString {- ^ function -}
747− -> FunctionHet xs y
748−unsafeFunctionHet fun xs = UnsafeExpression $
762+ -> FunctionN xs y
763+unsafeFunctionN fun xs = UnsafeExpression $
749764 fun <> parenthesized (renderCommaSeparated renderSQL xs)
750765
751766instance ty `In` PGNum
@@ -801,8 +816,8 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
801816-- atan2(pi(), 2)
802817atan2_
803818 :: float `In` PGFloating
804− => FunctionHet '[ null float, null float] (null float)
805−atan2_ = unsafeFunctionHet "atan2"
819+ => FunctionN '[ null float, null float] (null float)
820+atan2_ = unsafeFunctionN "atan2"
806821
807822-- When a `cast` is applied to an `Expression` of a known type, it
808823-- represents a run-time type conversion. The cast will succeed only if a
@@ -1284,7 +1299,6 @@ infixl 9 .?|
12841299infixl 9 .?&
12851300(.?&) = unsafeBinaryOp "?&"
12861301
1287−-- | Concatenate two jsonb values into a new jsonb value.
12881302instance Semigroup
12891303 (Expression outer commons grp schemas params from (null 'PGjsonb)) where
12901304 (<>) = unsafeBinaryOp "||"
@@ -1346,13 +1360,13 @@ rowToJson = unsafeFunction "row_to_json"
13461360
13471361-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
13481362-- argument list.
1349−jsonBuildArray :: SListI tuple => FunctionHet tuple (null 'PGjson)
1350−jsonBuildArray = unsafeFunctionHet "json_build_array"
1363+jsonBuildArray :: SListI tuple => FunctionN tuple (null 'PGjson)
1364+jsonBuildArray = unsafeFunctionN "json_build_array"
13511365
13521366-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
13531367-- variadic argument list.
1354−jsonbBuildArray :: SListI tuple => FunctionHet tuple (null 'PGjsonb)
1355−jsonbBuildArray = unsafeFunctionHet "jsonb_build_array"
1368+jsonbBuildArray :: SListI tuple => FunctionN tuple (null 'PGjsonb)
1369+jsonbBuildArray = unsafeFunctionN "jsonb_build_array"
13561370
13571371class PGBuildObject tys where
13581372instance PGBuildObject '[]
@@ -1364,16 +1378,16 @@ instance (PGBuildObject tys, key `In` PGJsonKey)
13641378-- and values.
13651379jsonBuildObject
13661380 :: (SListI elems, PGBuildObject elems)
1367− => FunctionHet elems (null 'PGjson)
1368−jsonBuildObject = unsafeFunctionHet "json_build_object"
1381+ => FunctionN elems (null 'PGjson)
1382+jsonBuildObject = unsafeFunctionN "json_build_object"
13691383
13701384-- | Builds a possibly-heterogeneously-typed (binary) JSON object out of a
13711385-- variadic argument list. The elements of the argument list must alternate
13721386-- between keys and values.
13731387jsonbBuildObject
13741388 :: (SListI elems, PGBuildObject elems)
1375− => FunctionHet elems (null 'PGjsonb)
1376−jsonbBuildObject = unsafeFunctionHet "jsonb_build_object"
1389+ => FunctionN elems (null 'PGjsonb)
1390+jsonbBuildObject = unsafeFunctionN "jsonb_build_object"
13771391
13781392-- | Builds a JSON object out of a text array.
13791393-- The array must have two dimensions
@@ -1395,20 +1409,20 @@ jsonbObject = unsafeFunction "jsonb_object"
13951409
13961410-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
13971411-- keys and one for values, that are zipped pairwise to create a JSON object.
1398−jsonZipObject :: FunctionHet
1412+jsonZipObject :: FunctionN
13991413 '[ null ('PGvararray ('NotNull 'PGtext))
14001414 , null ('PGvararray ('NotNull 'PGtext)) ]
14011415 ( null 'PGjson )
1402−jsonZipObject = unsafeFunctionHet "json_object"
1416+jsonZipObject = unsafeFunctionN "json_object"
14031417
14041418-- | This is an alternate form of 'jsonbObject' that takes two arrays; one for
14051419-- keys and one for values, that are zipped pairwise to create a binary JSON
14061420-- object.
1407−jsonbZipObject :: FunctionHet
1421+jsonbZipObject :: FunctionN
14081422 '[ null ('PGvararray ('NotNull 'PGtext))
14091423 , null ('PGvararray ('NotNull 'PGtext)) ]
14101424 ( null 'PGjsonb )
1411−jsonbZipObject = unsafeFunctionHet "jsonb_object"
1425+jsonbZipObject = unsafeFunctionN "jsonb_object"
14121426
14131427{-----------------------------------------
14141428Table 9.46: JSON processing functions
@@ -1430,7 +1444,7 @@ jsonExtractPath
14301444 -> NP (Expression outer commons grp schemas params from) elems
14311445 -> Expression outer commons grp schemas params from (null 'PGjsonb)
14321446jsonExtractPath x xs =
1433− unsafeFunctionHet "json_extract_path" (x :* xs)
1447+ unsafeFunctionN "json_extract_path" (x :* xs)
14341448
14351449-- | Returns JSON value pointed to by the given path (equivalent to #>
14361450-- operator).
@@ -1440,7 +1454,7 @@ jsonbExtractPath
14401454 -> NP (Expression outer commons grp schemas params from) elems
14411455 -> Expression outer commons grp schemas params from (null 'PGjsonb)
14421456jsonbExtractPath x xs =
1443− unsafeFunctionHet "jsonb_extract_path" (x :* xs)
1457+ unsafeFunctionN "jsonb_extract_path" (x :* xs)
14441458
14451459-- | Returns JSON value pointed to by the given path (equivalent to #>
14461460-- operator), as text.
@@ -1450,7 +1464,7 @@ jsonExtractPathAsText
14501464 -> NP (Expression outer commons grp schemas params from) elems
14511465 -> Expression outer commons grp schemas params from (null 'PGjson)
14521466jsonExtractPathAsText x xs =
1453− unsafeFunctionHet "json_extract_path_text" (x :* xs)
1467+ unsafeFunctionN "json_extract_path_text" (x :* xs)
14541468
14551469-- | Returns JSON value pointed to by the given path (equivalent to #>
14561470-- operator), as text.
@@ -1460,7 +1474,7 @@ jsonbExtractPathAsText
14601474 -> NP (Expression outer commons grp schemas params from) elems
14611475 -> Expression outer commons grp schemas params from (null 'PGjsonb)
14621476jsonbExtractPathAsText x xs =
1463− unsafeFunctionHet "jsonb_extract_path_text" (x :* xs)
1477+ unsafeFunctionN "jsonb_extract_path_text" (x :* xs)
14641478
14651479-- | Returns the type of the outermost JSON value as a text string. Possible
14661480-- types are object, array, string, number, boolean, and null.
@@ -1496,8 +1510,8 @@ jsonbSet
14961510 -> Maybe (Expression outer commons grp schemas params from (null 'PGbool))
14971511 -> Expression outer commons grp schemas params from (null 'PGjsonb)
14981512jsonbSet tgt path val createMissing = case createMissing of
1499− Just m -> unsafeFunctionHet "jsonb_set" (tgt :* path :* val :* m :* Nil)
1500− Nothing -> unsafeFunctionHet "jsonb_set" (tgt :* path :* val :* Nil)
1513+ Just m -> unsafeFunctionN "jsonb_set" (tgt :* path :* val :* m :* Nil)
1514+ Nothing -> unsafeFunctionN "jsonb_set" (tgt :* path :* val :* Nil)
15011515
15021516-- | @ jsonbInsert target path new_value insert_after @
15031517--
@@ -1514,8 +1528,8 @@ jsonbInsert
15141528 -> Maybe (Expression outer commons grp schemas params from (null 'PGbool))
15151529 -> Expression outer commons grp schemas params from (null 'PGjsonb)
15161530jsonbInsert tgt path val insertAfter = case insertAfter of
1517− Just i -> unsafeFunctionHet "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1518− Nothing -> unsafeFunctionHet "jsonb_insert" (tgt :* path :* val :* Nil)
1531+ Just i -> unsafeFunctionN "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1532+ Nothing -> unsafeFunctionN "jsonb_insert" (tgt :* path :* val :* Nil)
15191533
15201534-- | Returns its argument as indented JSON text.
15211535jsonbPretty :: null 'PGjsonb :--> null 'PGtext
@@ -1568,32 +1582,32 @@ toTSvector
15681582toTSvector = unsafeFunction "to_tsvector"
15691583
15701584setWeight
1571− :: FunctionHet '[null 'PGtsvector, null ('PGchar 1)] (null 'PGtsvector)
1572−setWeight = unsafeFunctionHet "set_weight"
1585+ :: FunctionN '[null 'PGtsvector, null ('PGchar 1)] (null 'PGtsvector)
1586+setWeight = unsafeFunctionN "set_weight"
15731587
15741588strip :: null 'PGtsvector :--> null 'PGtsvector
15751589strip = unsafeFunction "strip"
15761590
1577−jsonToTSvector :: FunctionHet '[null 'PGjson, null 'PGjson] (null 'PGtsvector)
1578−jsonToTSvector = unsafeFunctionHet "json_to_tsvector"
1591+jsonToTSvector :: FunctionN '[null 'PGjson, null 'PGjson] (null 'PGtsvector)
1592+jsonToTSvector = unsafeFunctionN "json_to_tsvector"
15791593
1580−jsonbToTSvector :: FunctionHet '[null 'PGjsonb, null 'PGjsonb] (null 'PGtsvector)
1581−jsonbToTSvector = unsafeFunctionHet "jsonb_to_tsvector"
1594+jsonbToTSvector :: FunctionN '[null 'PGjsonb, null 'PGjsonb] (null 'PGtsvector)
1595+jsonbToTSvector = unsafeFunctionN "jsonb_to_tsvector"
15821596
1583−tsDelete :: FunctionHet
1597+tsDelete :: FunctionN
15841598 '[null 'PGtsvector, null ('PGvararray ('NotNull 'PGtext))]
15851599 (null 'PGtsvector)
1586−tsDelete = unsafeFunctionHet "ts_delete"
1600+tsDelete = unsafeFunctionN "ts_delete"
15871601
1588−tsFilter :: FunctionHet
1602+tsFilter :: FunctionN
15891603 '[null 'PGtsvector, null ('PGvararray ('NotNull ('PGchar 1)))]
15901604 (null 'PGtsvector)
1591−tsFilter = unsafeFunctionHet "ts_filter"
1605+tsFilter = unsafeFunctionN "ts_filter"
15921606
15931607tsHeadline
15941608 :: document `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1595− => FunctionHet '[null document, null 'PGtsquery] (null 'PGtext)
1596−tsHeadline = unsafeFunctionHet "ts_headline"
1609+ => FunctionN '[null document, null 'PGtsquery] (null 'PGtext)
1610+tsHeadline = unsafeFunctionN "ts_headline"
15971611{-----------------------------------------
15981612aggregation
15991613-----------------------------------------}
@@ -1989,18 +2003,18 @@ instance Aggregate
19892003 max_ = unsafeWindowFunction1 "max"
19902004 min_ = unsafeWindowFunction1 "min"
19912005 avg = unsafeWindowFunction1 "avg"
1992− corr = unsafeWindowFunctionHet "corr"
1993− covarPop = unsafeWindowFunctionHet "covar_pop"
1994− covarSamp = unsafeWindowFunctionHet "covar_samp"
1995− regrAvgX = unsafeWindowFunctionHet "regr_avgx"
1996− regrAvgY = unsafeWindowFunctionHet "regr_avgy"
1997− regrCount = unsafeWindowFunctionHet "regr_count"
1998− regrIntercept = unsafeWindowFunctionHet "regr_intercept"
1999− regrR2 = unsafeWindowFunctionHet "regr_r2"
2000− regrSlope = unsafeWindowFunctionHet "regr_slope"
2001− regrSxx = unsafeWindowFunctionHet "regr_sxx"
2002− regrSxy = unsafeWindowFunctionHet "regr_sxy"
2003− regrSyy = unsafeWindowFunctionHet "regr_syy"
2006+ corr = unsafeWindowFunctionN "corr"
2007+ covarPop = unsafeWindowFunctionN "covar_pop"
2008+ covarSamp = unsafeWindowFunctionN "covar_samp"
2009+ regrAvgX = unsafeWindowFunctionN "regr_avgx"
2010+ regrAvgY = unsafeWindowFunctionN "regr_avgy"
2011+ regrCount = unsafeWindowFunctionN "regr_count"
2012+ regrIntercept = unsafeWindowFunctionN "regr_intercept"
2013+ regrR2 = unsafeWindowFunctionN "regr_r2"
2014+ regrSlope = unsafeWindowFunctionN "regr_slope"
2015+ regrSxx = unsafeWindowFunctionN "regr_sxx"
2016+ regrSxy = unsafeWindowFunctionN "regr_sxy"
2017+ regrSyy = unsafeWindowFunctionN "regr_syy"
20042018 stddev = unsafeWindowFunction1 "stddev"
20052019 stddevPop = unsafeWindowFunction1 "stddev_pop"
20062020 stddevSamp = unsafeWindowFunction1 "stddev_samp"
@@ -2353,8 +2367,8 @@ unsafeWindowFunction1 :: ByteString -> WinFun1 x y
23532367unsafeWindowFunction1 fun x
23542368 = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x)
23552369
2356−unsafeWindowFunctionHet :: SOP.SListI xs => ByteString -> WinFunHet xs y
2357−unsafeWindowFunctionHet fun xs = UnsafeWindowFunction $ fun <>
2370+unsafeWindowFunctionN :: SOP.SListI xs => ByteString -> WinFunHet xs y
2371+unsafeWindowFunctionN fun xs = UnsafeWindowFunction $ fun <>
23582372 parenthesized (renderCommaSeparated renderSQL xs)
23592373
23602374{- | rank of the current row with gaps; same as `rowNumber` of its first peer
@@ -2405,7 +2419,7 @@ row within the partition; if there is no such row, instead return default
24052419evaluated with respect to the current row.
24062420-}
24072421lag :: WinFunHet '[ty, 'NotNull 'PGint4, ty] ty
2408−lag = unsafeWindowFunctionHet "lag"
2422+lag = unsafeWindowFunctionN "lag"
24092423
24102424{- | returns value evaluated at the row that is offset rows after the current
24112425row within the partition; if there is no such row, instead return default
@@ -2413,7 +2427,7 @@ row within the partition; if there is no such row, instead return default
24132427evaluated with respect to the current row.
24142428-}
24152429lead :: WinFunHet '[ty, 'NotNull 'PGint4, ty] ty
2416−lead = unsafeWindowFunctionHet "lag"
2430+lead = unsafeWindowFunctionN "lag"
24172431
24182432{- | returns value evaluated at the row that is the
24192433first row of the window frame
@@ -2431,7 +2445,7 @@ lastValue = unsafeWindowFunction1 "last_value"
24312445row of the window frame (counting from 1); null if no such row
24322446-}
24332447nthValue :: WinFunHet '[null ty, 'NotNull 'PGint4] ('Null ty)
2434−nthValue = unsafeWindowFunctionHet "nth_value"
2448+nthValue = unsafeWindowFunctionN "nth_value"
24352449
24362450{-|
24372451Create date from year, month and day fields
@@ -2439,10 +2453,10 @@ Create date from year, month and day fields
24392453>>> printSQL (makeDate (1984 :* 7 *: 3))
24402454make_date(1984, 7, 3)
24412455-}
2442−makeDate :: FunctionHet
2456+makeDate :: FunctionN
24432457 '[ null 'PGint4, null 'PGint4, null 'PGint4 ]
24442458 ( null 'PGdate )
2445−makeDate = unsafeFunctionHet "make_date"
2459+makeDate = unsafeFunctionN "make_date"
24462460
24472461{-|
24482462Create time from hour, minute and seconds fields
@@ -2450,10 +2464,10 @@ Create time from hour, minute and seconds fields
24502464>>> printSQL (makeTime (8 :* 15 *: 23.5))
24512465make_time(8, 15, 23.5)
24522466-}
2453−makeTime :: FunctionHet
2467+makeTime :: FunctionN
24542468 '[ null 'PGint4, null 'PGint4, null 'PGfloat8 ]
24552469 ( null 'PGtime )
2456−makeTime = unsafeFunctionHet "make_time"
2470+makeTime = unsafeFunctionN "make_time"
24572471
24582472{-|
24592473Create timestamp from year, month, day, hour, minute and seconds fields
@@ -2461,11 +2475,11 @@ Create timestamp from year, month, day, hour, minute and seconds fields
24612475>>> printSQL (makeTimestamp (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
24622476make_timestamp(2013, 7, 15, 8, 15, 23.5)
24632477-}
2464−makeTimestamp :: FunctionHet
2478+makeTimestamp :: FunctionN
24652479 '[ null 'PGint4, null 'PGint4, null 'PGint4
24662480 , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
24672481 ( null 'PGtimestamp )
2468−makeTimestamp = unsafeFunctionHet "make_timestamp"
2482+makeTimestamp = unsafeFunctionN "make_timestamp"
24692483
24702484{-|
24712485Create timestamp with time zone from
@@ -2475,11 +2489,11 @@ the current time zone is used
24752489>>> printSQL (makeTimestamptz (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
24762490make_timestamptz(2013, 7, 15, 8, 15, 23.5)
24772491-}
2478−makeTimestamptz :: FunctionHet
2492+makeTimestamptz :: FunctionN
24792493 '[ null 'PGint4, null 'PGint4, null 'PGint4
24802494 , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
24812495 ( null 'PGtimestamptz )
2482−makeTimestamptz = unsafeFunctionHet "make_timestamptz"
2496+makeTimestamptz = unsafeFunctionN "make_timestamptz"
24832497
24842498{-|
24852499Affine space operations on time types.
@@ -2526,6 +2540,8 @@ data TimeUnit
25262540 | Microseconds | Milliseconds
25272541 | Decades | Centuries | Millennia
25282542 deriving (Eq, Ord, Show, Read, Enum, GHC.Generic)
2543+instance SOP.Generic TimeUnit
2544+instance SOP.HasDatatypeInfo TimeUnit
25292545instance RenderSQL TimeUnit where
25302546 renderSQL = \case
25312547 Years -> "years"
@@ -2556,7 +2572,7 @@ instance JSON.ToJSON hask => Literal (Jsonb hask) where
25562572 literal = cast jsonb . UnsafeExpression
25572573 . singleQuotedUtf8 . toStrict . JSON.encode . getJsonb
25582574instance Literal Char where
2559− literal chr = cast (char @1) . UnsafeExpression $
2575+ literal chr = UnsafeExpression $
25602576 "E\'" <> fromString (escape chr) <> "\'"
25612577instance Literal String where literal = fromString
25622578instance Literal Int16 where literal = fromIntegral