Other functions
The following table describes other functions:
Function | Features |
CAST | Converts data to a target data type. |
COALESCE | Returns the first non-NULL value in the parameters. |
GREATEST | Returns the largest value in the parameters. |
IF | Checks if a specified condition is true. |
IS_CELLPHONE_NUMBER | Checks if a specified string is a mobile phone number. |
LEAST | Returns the smallest value in the parameters. |
MAX_PT | Returns the maximum value of the level-1 partition of a partitioned table. |
CAST
Description
Converts the result of an expression to a target data type.
Parameters
expr: Required. Any data type. The expression to convert.
type: Required. String. The target data type. Valid values: STRING, BIGINT, DECIMAL, BOOLEAN, DATETIME, and DATE.
Return value
Returns the value converted to the target data type. If expr or type is NULL, this function returns NULL.
Supported compute engines
MaxCompute (ODPS), MYSQL, RDS, HIVE, AnalyticDB for PostgreSQL (ADB_PG), PolarDB for PostgreSQL (POLAR_PG), POSTGRESQL, and SPARK.
COALESCE
Description
Returns the first non-NULL value among the input parameters.
Parameters
expr1: Required. Any data type. The first expression to evaluate.
exprN: A parameter of any data type, specifying the Nth value to validate.
Return value
Returns the first non-NULL value among the input parameters. If all parameters are NULL, this function returns NULL.
Supported compute engines
MaxCompute (ODPS), MYSQL, RDS, HIVE, AnalyticDB for PostgreSQL (ADB_PG), PolarDB for PostgreSQL (POLAR_PG), POSTGRESQL, and SPARK.
GREATEST
Description
Returns the largest value among the input parameters. If the input parameters have different data types, they are converted for comparison. A comparison that involves numbers, strings, and datetimes converts all values to the number type. A comparison between strings and datetimes converts both values to the datetime type.
Parameters
expr1: Required. Any data type. The first expression to compare.
exprN: Optional. Any data type. One or more additional expressions to compare.
Return value
Returns the largest value among the input parameters. If any parameter is NULL, this function returns NULL. By default, MaxCompute (ODPS) treats NULL as the minimum value. In MaxCompute, this function returns NULL if a parameter is NULL only when the `set odps.sql.hive.compatible=true` command is run.
Supported compute engines
MaxCompute (ODPS), MYSQL, RDS, HIVE, AnalyticDB for PostgreSQL (ADB_PG), PolarDB for PostgreSQL (POLAR_PG), POSTGRESQL, and SPARK.
IF
Description
If testCondition is true, this function returns valueTrue. Otherwise, it returns valueFalseOrNull.
Parameters
testCondition: Required. Boolean. The expression to evaluate.
valueTrue: Required. Any data type. The value to return if testCondition is true.
valueFalseOrNull: Optional. Any data type. The value to return if testCondition is false.
Return value
The data type of the return value is the same as the data type of the valueTrue or valueFalseOrNull parameters.
Supported compute engines
MaxCompute (ODPS), MYSQL, RDS, HIVE, and SPARK.
IS_CELLPHONE_NUMBER
Description
Checks if a specified string is a mobile phone number.
Parameters
value: Required. String. The string to check.
Return value
Returns true if the specified string is a mobile phone number. Otherwise, it returns false.
Supported compute engines
MaxCompute (ODPS), MYSQL, RDS, HIVE, AnalyticDB for PostgreSQL (ADB_PG), PolarDB for PostgreSQL (POLAR_PG), POSTGRESQL, and SPARK.
LEAST
Description
Returns the smallest value among the input parameters. If the input parameters have different data types, they are converted for comparison. A comparison that involves numbers, strings, and datetimes converts all values to the number type. A comparison between strings and datetimes converts both values to the datetime type.
Parameters
expr1: Required. Any data type. The first expression to compare.
exprN: Optional. Any data type. One or more additional expressions to compare.
Return value
Returns the smallest value among the input parameters. If any parameter is NULL, this function returns NULL.
Supported compute engines
MaxCompute (ODPS), MYSQL, RDS, HIVE, AnalyticDB for PostgreSQL (ADB_PG), PolarDB for PostgreSQL (POLAR_PG), POSTGRESQL, and SPARK.
MAX_PT
Description
Returns the maximum value of a level-1 partition in a partitioned table.
Parameters
tableFullName: Required. String. The name of the partitioned table.
Return value
Returns the maximum partition value.
Supported compute engines
MaxCompute (ODPS).