系统函数 (Azure Cosmos DB)System functions (Azure Cosmos DB)

Cosmos DB 提供多个内置 SQL 函数。Cosmos DB provides many built-in SQL functions. 内置函数的类别如下所示。The categories of built-in functions are listed below.

函数组Function group 说明Description 操作Operations
数组函数Array functions 该数组函数对数组输入值执行操作,并返回数值、布尔值或数组值。The array functions perform an operation on an array input value and return numeric, Boolean, or array value. ARRAY_CONCATARRAY_CONTAINSARRAY_LENGTHARRAY_SLICEARRAY_CONCAT, ARRAY_CONTAINS, ARRAY_LENGTH, ARRAY_SLICE
日期和时间函数Date and Time functions 使用日期和时间函数可以获取采用以下两种格式的当前 UTC 日期和时间:一个时间戳,其值为以毫秒为单位的 Unix 纪元;一个符合 ISO 8601 格式的字符串。The date and time functions allow you to get the current UTC date and time in two forms; a numeric timestamp whose value is the Unix epoch in milliseconds or as a string which conforms to the ISO 8601 format. GetCurrentDateTimeGetCurrentTimestampGetCurrentDateTime, GetCurrentTimestamp
数学函数Mathematical functions 每个数学函数均执行一个计算,通常基于作为参数提供的输出值,并返回数值。The mathematical functions each perform a calculation, usually based on input values that are provided as arguments, and return a numeric value. ABSACOSASINATANATN2CEILINGCOSCOTDEGREESEXPFLOORLOGLOG10PIPOWERRADIANSRANDROUNDSIGNSINSQRTSQUARETANTRUNCABS, ACOS, ASIN, ATAN, ATN2, CEILING, COS, COT, DEGREES, EXP, FLOOR, LOG, LOG10, PI, POWER, RADIANS, RAND, ROUND, SIGN, SIN, SQRT, SQUARE, TAN, TRUNC
空间函数Spatial functions 该空间函数对控件对象输入值执行操作,并返回数值或布尔值。The spatial functions perform an operation on a spatial object input value and return a numeric or Boolean value. ST_DISTANCEST_INTERSECTSST_ISVALIDST_ISVALIDDETAILEDST_WITHINST_DISTANCE, ST_INTERSECTS, ST_ISVALID, ST_ISVALIDDETAILED, ST_WITHIN
字符串函数String functions 该字符串函数对字符串输入值执行操作,并返回字符串、数值或布尔值。The string functions perform an operation on a string input value and return a string, numeric or Boolean value. CONCATCONTAINSENDSWITHINDEX_OFLEFTLENGTHLOWERLTRIMREPLACEREPLICATEREVERSERIGHTRTRIMSTARTSWITHStringToArrayStringToBooleanStringToNullStringToNumberStringToObjectSUBSTRINGToStringTRIMUPPERCONCAT, CONTAINS, ENDSWITH, INDEX_OF, LEFT, LENGTH, LOWER, LTRIM, REPLACE, REPLICATE, REVERSE, RIGHT, RTRIM, STARTSWITH, StringToArray, StringToBoolean, StringToNull, StringToNumber, StringToObject, SUBSTRING, ToString, TRIM, UPPER
类型检查函数Type checking functions 类型检查函数使你能够检查 SQL 查询内表达式的类型。The type checking functions allow you to check the type of an expression within SQL queries. IS_ARRAYIS_BOOLIS_DEFINEDIS_NULLIS_NUMBERIS_OBJECTIS_PRIMITIVEIS_STRINGIS_ARRAY, IS_BOOL, IS_DEFINED, IS_NULL, IS_NUMBER, IS_OBJECT, IS_PRIMITIVE, IS_STRING

内置函数与用户定义函数 (UDF)Built-in versus User Defined Functions (UDFs)

如果当前正在使用的用户定义的函数 (UDF) 有内置函数可用,则相应的内置函数会更快更有效地运行。If you're currently using a user-defined function (UDF) for which a built-in function is now available, the corresponding built-in function will be quicker to run and more efficient.

内置函数与 ANSI SQL 函数Built-in versus ANSI SQL functions

Cosmos DB 函数与 ANSI SQL 函数之间的主要差别在于,Cosmos DB 函数能够很好地处理无架构数据和混合架构数据。The main difference between Cosmos DB functions and ANSI SQL functions is that Cosmos DB functions are designed to work well with schemaless and mixed-schema data. 例如,如果某个属性缺失或包含类似于 unknown 的非数字值,则会跳过该项,而不是返回错误。For example, if a property is missing or has a non-numeric value like unknown, the item is skipped instead of returning an error.

后续步骤Next steps