on dev help sign in
SQL function of 1 argument type
8df5d8dEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+44−94
@@ -287,11 +287,16 @@ newtype Expression
287instance RenderSQL (Expression outer grp commons schemas params from ty) where
287instance RenderSQL (Expression outer grp commons schemas params from ty) where
288 renderSQL = renderExpression
288 renderSQL = renderExpression
289
289
290−type Operator ty1 ty2 ty3
290+type Operator x1 x2 y
291 = forall outer grp commons schemas params from
291 = forall outer grp commons schemas params from
292− . Expression outer grp commons schemas params from ty1
292+ . Expression outer grp commons schemas params from x1
293+ -> Expression outer grp commons schemas params from x2
293− -> Expression outer grp commons schemas params from ty2
294+ -> Expression outer grp commons schemas params from y
295+
296+type (:-->) x y
297+ = forall outer grp commons schemas params from
298+ . Expression outer grp commons schemas params from x
294− -> Expression outer grp commons schemas params from ty3
299+ -> Expression outer grp commons schemas params from y
295
300
296{- | A `HasParameter` constraint is used to indicate a value that is
301{- | A `HasParameter` constraint is used to indicate a value that is
297supplied externally to a SQL statement.
302supplied externally to a SQL statement.
@@ -529,17 +534,15 @@ array xs = UnsafeExpression $
529
534
530-- | >>> printSQL $ cardinality (array [null_, false, true])
535-- | >>> printSQL $ cardinality (array [null_, false, true])
531-- cardinality(ARRAY[NULL, FALSE, TRUE])
536-- cardinality(ARRAY[NULL, FALSE, TRUE])
532−cardinality
537+cardinality :: nullity ('PGvararray ty) :--> nullity 'PGint8
533− :: Expression outer grp commons schemas params from (nullity ('PGvararray ty))
534− -> Expression outer grp commons schemas params from (nullity 'PGint8)
535cardinality = unsafeFunction "cardinality"
538cardinality = unsafeFunction "cardinality"
536
539
537-- | >>> printSQL $ array [null_, false, true] & index 2
540-- | >>> printSQL $ array [null_, false, true] & index 2
538-- (ARRAY[NULL, FALSE, TRUE])[2]
541-- (ARRAY[NULL, FALSE, TRUE])[2]
539index
542index
540− :: Word64 -- ^ index
543+ :: Word64 -- ^ index
541− -> Expression outer grp commons schemas params from (nullity ('PGvararray ty)) -- ^ array
544+ -> nullity ('PGvararray ty) -- ^ array
542− -> Expression outer grp commons schemas params from (NullifyType ty)
545+ :--> NullifyType ty
543index n expr = UnsafeExpression $
546index n expr = UnsafeExpression $
544 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
547 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
545
548
@@ -632,21 +635,13 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
632
635
633-- | >>> printSQL $ unsafeUnaryOp "NOT" true
636-- | >>> printSQL $ unsafeUnaryOp "NOT" true
634-- (NOT TRUE)
637-- (NOT TRUE)
635−unsafeUnaryOp
638+unsafeUnaryOp :: ByteString {- ^ operator -} -> x :--> y
636− :: ByteString
637− -- ^ operator
638− -> Expression outer grp commons schemas params from (ty0)
639− -> Expression outer grp commons schemas params from (ty1)
640unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
639unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
641 op <+> renderSQL x
640 op <+> renderSQL x
642
641
643-- | >>> printSQL $ unsafeFunction "f" true
642-- | >>> printSQL $ unsafeFunction "f" true
644-- f(TRUE)
643-- f(TRUE)
645−unsafeFunction
644+unsafeFunction :: ByteString {- ^ function -} -> x :--> y
646− :: ByteString
647− -- ^ function
648− -> Expression outer grp commons schemas params from xty
649− -> Expression outer grp commons schemas params from yty
650unsafeFunction fun x = UnsafeExpression $
645unsafeFunction fun x = UnsafeExpression $
651 fun <> parenthesized (renderSQL x)
646 fun <> parenthesized (renderSQL x)
652
647
@@ -780,11 +775,7 @@ rem_ = unsafeBinaryOp "%"
780-- in printSQL expression
775-- in printSQL expression
781-- :}
776-- :}
782-- trunc(pi())
777-- trunc(pi())
783−trunc
784− :: frac `In` PGFloating
778+trunc :: frac `In` PGFloating => nullity frac :--> nullity frac
785− => Expression outer grp commons schemas params from (nullity frac)
786− -- ^ fractional number
787− -> Expression outer grp commons schemas params from (nullity frac)
788trunc = unsafeFunction "trunc"
779trunc = unsafeFunction "trunc"
789
780
790-- | >>> :{
781-- | >>> :{
@@ -794,11 +785,7 @@ trunc = unsafeFunction "trunc"
794-- in printSQL expression
785-- in printSQL expression
795-- :}
786-- :}
796-- round(pi())
787-- round(pi())
797−round_
798− :: frac `In` PGFloating
788+round_ :: frac `In` PGFloating => nullity frac :--> nullity frac
799− => Expression outer grp commons schemas params from (nullity frac)
800− -- ^ fractional number
801− -> Expression outer grp commons schemas params from (nullity frac)
802round_ = unsafeFunction "round"
789round_ = unsafeFunction "round"
803
790
804-- | >>> :{
791-- | >>> :{
@@ -808,11 +795,7 @@ round_ = unsafeFunction "round"
808-- in printSQL expression
795-- in printSQL expression
809-- :}
796-- :}
810-- ceiling(pi())
797-- ceiling(pi())
811−ceiling_
812− :: frac `In` PGFloating
798+ceiling_ :: frac `In` PGFloating => nullity frac :--> nullity frac
813− => Expression outer grp commons schemas params from (nullity frac)
814− -- ^ fractional number
815− -> Expression outer grp commons schemas params from (nullity frac)
816ceiling_ = unsafeFunction "ceiling"
799ceiling_ = unsafeFunction "ceiling"
817
800
818-- | A `Condition` is an `Expression`, which can evaluate
801-- | A `Condition` is an `Expression`, which can evaluate
@@ -833,9 +816,7 @@ false = UnsafeExpression "FALSE"
833
816
834-- | >>> printSQL $ not_ true
817-- | >>> printSQL $ not_ true
835-- (NOT TRUE)
818-- (NOT TRUE)
836−not_
819+not_ :: nullity 'PGbool :--> nullity 'PGbool
837− :: Expression outer grp commons schemas params from (nullity 'PGbool)
838− -> Expression outer grp commons schemas params from (nullity 'PGbool)
839not_ = unsafeUnaryOp "NOT"
820not_ = unsafeUnaryOp "NOT"
840
821
841-- | >>> printSQL $ true .&& false
822-- | >>> printSQL $ true .&& false
@@ -1125,25 +1106,25 @@ instance Monoid
1125-- | >>> printSQL $ lower "ARRRGGG"
1106-- | >>> printSQL $ lower "ARRRGGG"
1126-- lower(E'ARRRGGG')
1107-- lower(E'ARRRGGG')
1127lower
1108lower
1128− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1109+ :: nullity 'PGtext
1129 -- ^ string to lower case
1110 -- ^ string to lower case
1130− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1111+ :--> nullity 'PGtext
1131lower = unsafeFunction "lower"
1112lower = unsafeFunction "lower"
1132
1113
1133-- | >>> printSQL $ upper "eeee"
1114-- | >>> printSQL $ upper "eeee"
1134-- upper(E'eeee')
1115-- upper(E'eeee')
1135upper
1116upper
1136− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1117+ :: nullity 'PGtext
1137 -- ^ string to upper case
1118 -- ^ string to upper case
1138− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1119+ :--> nullity 'PGtext
1139upper = unsafeFunction "upper"
1120upper = unsafeFunction "upper"
1140
1121
1141-- | >>> printSQL $ charLength "four"
1122-- | >>> printSQL $ charLength "four"
1142-- char_length(E'four')
1123-- char_length(E'four')
1143charLength
1124charLength
1144− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1125+ :: nullity 'PGtext
1145 -- ^ string to measure
1126 -- ^ string to measure
1146− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1127+ :--> nullity 'PGint4
1147charLength = unsafeFunction "char_length"
1128charLength = unsafeFunction "char_length"
1148
1129
1149-- | The `like` expression returns true if the @string@ matches
1130-- | The `like` expression returns true if the @string@ matches
@@ -1294,9 +1275,7 @@ jsonLit = cast json . UnsafeExpression
1294-- otherwise, a scalar value is produced. For any scalar type other than a
1275-- otherwise, a scalar value is produced. For any scalar type other than a
1295-- number, a Boolean, or a null value, the text representation will be used, in
1276-- number, a Boolean, or a null value, the text representation will be used, in
1296-- such a fashion that it is a valid json value.
1277-- such a fashion that it is a valid json value.
1297−toJson
1278+toJson :: nullity ty :--> nullity 'PGjson
1298− :: Expression outer grp commons schemas params from (nullity ty)
1299− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1300toJson = unsafeFunction "to_json"
1279toJson = unsafeFunction "to_json"
1301
1280
1302-- | Returns the value as jsonb. Arrays and composites are converted
1281-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1305,23 +1284,18 @@ toJson = unsafeFunction "to_json"
1305-- otherwise, a scalar value is produced. For any scalar type other than a
1284-- otherwise, a scalar value is produced. For any scalar type other than a
1306-- number, a Boolean, or a null value, the text representation will be used, in
1285-- number, a Boolean, or a null value, the text representation will be used, in
1307-- such a fashion that it is a valid jsonb value.
1286-- such a fashion that it is a valid jsonb value.
1308−toJsonb
1287+toJsonb :: nullity ty :--> nullity 'PGjsonb
1309− :: Expression outer grp commons schemas params from (nullity ty)
1310− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1311toJsonb = unsafeFunction "to_jsonb"
1288toJsonb = unsafeFunction "to_jsonb"
1312
1289
1313-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1290-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1314-- becomes a JSON array of arrays.
1291-- becomes a JSON array of arrays.
1315arrayToJson
1292arrayToJson
1316 :: PGArray "arrayToJson" arr
1293 :: PGArray "arrayToJson" arr
1317− => Expression outer grp commons schemas params from (nullity arr)
1294+ => nullity arr :--> nullity 'PGjson
1318− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1319arrayToJson = unsafeFunction "array_to_json"
1295arrayToJson = unsafeFunction "array_to_json"
1320
1296
1321-- | Returns the row as a JSON object.
1297-- | Returns the row as a JSON object.
1322−rowToJson
1298+rowToJson :: nullity ('PGcomposite ty) :--> nullity 'PGjson
1323− :: Expression outer grp commons schemas params from (nullity ('PGcomposite ty))
1324− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1325rowToJson = unsafeFunction "row_to_json"
1299rowToJson = unsafeFunction "row_to_json"
1326
1300
1327-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1301-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
@@ -1384,8 +1358,7 @@ jsonbBuildObject
1384-- array has exactly two elements, which are taken as a key/value pair.
1358-- array has exactly two elements, which are taken as a key/value pair.
1385jsonObject
1359jsonObject
1386 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1360 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1387− => Expression outer grp commons schemas params from (nullity arr)
1361+ => nullity arr :--> nullity 'PGjson
1388− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1389jsonObject = unsafeFunction "json_object"
1362jsonObject = unsafeFunction "json_object"
1390
1363
1391-- | Builds a binary JSON object out of a text array. The array must have either
1364-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1394,8 +1367,7 @@ jsonObject = unsafeFunction "json_object"
1394-- array has exactly two elements, which are taken as a key/value pair.
1367-- array has exactly two elements, which are taken as a key/value pair.
1395jsonbObject
1368jsonbObject
1396 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1369 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1397− => Expression outer grp commons schemas params from (nullity arr)
1370+ => nullity arr :--> nullity 'PGjsonb
1398− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1399jsonbObject = unsafeFunction "jsonb_object"
1371jsonbObject = unsafeFunction "jsonb_object"
1400
1372
1401-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1373-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1426,15 +1398,11 @@ Table 9.46: JSON processing functions
1426-----------------------------------------}
1398-----------------------------------------}
1427
1399
1428-- | Returns the number of elements in the outermost JSON array.
1400-- | Returns the number of elements in the outermost JSON array.
1429−jsonArrayLength
1401+jsonArrayLength :: nullity 'PGjson :--> nullity 'PGint4
1430− :: Expression outer grp commons schemas params from (nullity 'PGjson)
1431− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1432jsonArrayLength = unsafeFunction "json_array_length"
1402jsonArrayLength = unsafeFunction "json_array_length"
1433
1403
1434-- | Returns the number of elements in the outermost binary JSON array.
1404-- | Returns the number of elements in the outermost binary JSON array.
1435−jsonbArrayLength
1405+jsonbArrayLength :: nullity 'PGjsonb :--> nullity 'PGint4
1436− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1437− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1438jsonbArrayLength = unsafeFunction "jsonb_array_length"
1406jsonbArrayLength = unsafeFunction "jsonb_array_length"
1439
1407
1440-- | Returns JSON value pointed to by the given path (equivalent to #>
1408-- | Returns JSON value pointed to by the given path (equivalent to #>
@@ -1479,30 +1447,22 @@ jsonbExtractPathAsText x xs =
1479
1447
1480-- | Returns the type of the outermost JSON value as a text string. Possible
1448-- | Returns the type of the outermost JSON value as a text string. Possible
1481-- types are object, array, string, number, boolean, and null.
1449-- types are object, array, string, number, boolean, and null.
1482−jsonTypeof
1450+jsonTypeof :: nullity 'PGjson :--> nullity 'PGtext
1483− :: Expression outer grp commons schemas params from (nullity 'PGjson)
1484− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1485jsonTypeof = unsafeFunction "json_typeof"
1451jsonTypeof = unsafeFunction "json_typeof"
1486
1452
1487-- | Returns the type of the outermost binary JSON value as a text string.
1453-- | Returns the type of the outermost binary JSON value as a text string.
1488-- Possible types are object, array, string, number, boolean, and null.
1454-- Possible types are object, array, string, number, boolean, and null.
1489−jsonbTypeof
1455+jsonbTypeof :: nullity 'PGjsonb :--> nullity 'PGtext
1490− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1491− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1492jsonbTypeof = unsafeFunction "jsonb_typeof"
1456jsonbTypeof = unsafeFunction "jsonb_typeof"
1493
1457
1494-- | Returns its argument with all object fields that have null values omitted.
1458-- | Returns its argument with all object fields that have null values omitted.
1495-- Other null values are untouched.
1459-- Other null values are untouched.
1496−jsonStripNulls
1460+jsonStripNulls :: nullity 'PGjson :--> nullity 'PGjson
1497− :: Expression outer grp commons schemas params from (nullity 'PGjson)
1498− -> Expression outer grp commons schemas params from (nullity 'PGjson)
1499jsonStripNulls = unsafeFunction "json_strip_nulls"
1461jsonStripNulls = unsafeFunction "json_strip_nulls"
1500
1462
1501-- | Returns its argument with all object fields that have null values omitted.
1463-- | Returns its argument with all object fields that have null values omitted.
1502-- Other null values are untouched.
1464-- Other null values are untouched.
1503−jsonbStripNulls
1465+jsonbStripNulls :: nullity 'PGjsonb :--> nullity 'PGjsonb
1504− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1505− -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1506jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1466jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1507
1467
1508-- | @ jsonbSet target path new_value create_missing @
1468-- | @ jsonbSet target path new_value create_missing @
@@ -1543,9 +1503,7 @@ jsonbInsert tgt path val insertAfter = case insertAfter of
1543 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1503 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1544
1504
1545-- | Returns its argument as indented JSON text.
1505-- | Returns its argument as indented JSON text.
1546−jsonbPretty
1506+jsonbPretty :: nullity 'PGjsonb :--> nullity 'PGtext
1547− :: Expression outer grp commons schemas params from (nullity 'PGjsonb)
1548− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1549jsonbPretty = unsafeFunction "jsonb_pretty"
1507jsonbPretty = unsafeFunction "jsonb_pretty"
1550
1508
1551(@@) :: Operator (nullity 'PGtsvector) (nullity 'PGtsquery) ('Null 'PGbool)
1509(@@) :: Operator (nullity 'PGtsvector) (nullity 'PGtsquery) ('Null 'PGbool)
@@ -1557,27 +1515,21 @@ jsonbPretty = unsafeFunction "jsonb_pretty"
1557(.|) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1515(.|) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1558(.|) = unsafeBinaryOp "||"
1516(.|) = unsafeBinaryOp "||"
1559
1517
1560−(.!)
1518+(.!) :: nullity 'PGtsquery :--> nullity 'PGtsquery
1561− :: Expression outer grp commons schemas params from (nullity 'PGtsquery)
1562− -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1563(.!) = unsafeUnaryOp "!!"
1519(.!) = unsafeUnaryOp "!!"
1564
1520
1565(<->) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1521(<->) :: Operator (nullity 'PGtsquery) (nullity 'PGtsquery) (nullity 'PGtsquery)
1566(<->) = unsafeBinaryOp "<->"
1522(<->) = unsafeBinaryOp "<->"
1567
1523
1568arrayToTSvector
1524arrayToTSvector
1569− :: Expression outer grp commons schemas params from (nullity ('PGvararray ('NotNull 'PGtext)))
1525+ :: nullity ('PGvararray ('NotNull 'PGtext))
1570− -> Expression outer grp commons schemas params from (nullity 'PGtsvector)
1526+ :--> nullity 'PGtsvector
1571arrayToTSvector = unsafeFunction "array_to_tsvector"
1527arrayToTSvector = unsafeFunction "array_to_tsvector"
1572
1528
1573−tsvectorLength
1529+tsvectorLength :: nullity 'PGtsvector :--> nullity 'PGint4
1574− :: Expression outer grp commons schemas params from (nullity 'PGtsvector)
1575− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1576tsvectorLength = unsafeFunction "length"
1530tsvectorLength = unsafeFunction "length"
1577
1531
1578−numnode
1532+numnode :: nullity 'PGtsquery :--> nullity 'PGint4
1579− :: Expression outer grp commons schemas params from (nullity 'PGtsquery)
1580− -> Expression outer grp commons schemas params from (nullity 'PGint4)
1581numnode = unsafeFunction "numnode"
1533numnode = unsafeFunction "numnode"
1582
1534
1583plainToTSquery
1535plainToTSquery
@@ -1598,9 +1550,7 @@ websearchToTSquery
1598 -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1550 -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1599websearchToTSquery = unsafeFunction2 "websearch_to_tsquery"
1551websearchToTSquery = unsafeFunction2 "websearch_to_tsquery"
1600
1552
1601−queryTree
1553+queryTree :: nullity 'PGtsquery :--> nullity 'PGtext
1602− :: Expression outer grp commons schemas params from (nullity 'PGtsquery)
1603− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1604queryTree = unsafeFunction "query_tree"
1554queryTree = unsafeFunction "query_tree"
1605
1555
1606toTSquery
1556toTSquery