SQL Functions

All Functions

Function Name
Description

Computes the absolute value of a numeric expression.

Computes the arccosine (inverse cosine) of a value in radians.

Decrypts a string produced by AES encryption.

Encrypts a string using AES encryption.

Returns the approximate number of unique, non-null values in a column.

Returns whether a list contains a given value.

Returns the ASCII code for the first character of a string. If the string is empty, 0 is returned.

Computes the arcsine (inverse sine) of a value in radians.

Computes the Arctangent (inverse Tangent) of a value.

Computes the average of a set of values.

Returns the Base64 encoding of a binary string.

Converts the input expression to a binary value.

Returns the bitwise AND of non-NULL input values.

Gets length of bits of the input expression

Returns the bitwise OR of non-NULL input values.

Computes the boolean AND of two boolean expressions. Returns TRUE if both expressions evaluate to TRUE. Returns FALSE if one or both expression(s) evaluate(s) to FALSE.

Computes the boolean OR of two boolean expressions. Returns TRUE if one or both expressions evaluate to TRUE. Returns FALSE if both expressions evaluate to FALSE.

Trims leading and trailing characters from a string.

Evaluates a list of conditions and returns the first resulting true expression. If a true expression is not found, will return the ELSE statement, if present, or else will return NULL.

Converts a value of one data type to another data type. This function behaves similarly to the TO_<data_type> (i.e. TO_TIMESTAMP) functions.

Computes the cube root of a numeric expression

Returns the nearest equal or larger value of the input expression. Can also be called using CEIL().

Returns the length of an input string.

Returns the character length of the input string.

Converts a Unicode code point into the character that matches the input Unicode character. If an invalid code point is specified, an empty string is returned.

Evaluates the arguments in order and returns the value of the first expression that does not contain NULL.

Tests whether an expression column matches a pattern column. Comparisons are case-sensitive.

Concatenates two or more strings. NULL values are ignored.

Concatenate with separator. Returns a string resulting from the joining of two or more string values in an end-to-end manner. Uses the first argument as the separator between each string.

Converts a binary string from the given data type to a Spice type.

Converts a binary string to a UTF-8 value and replaces all characters that cannot be converted to UTF-8 with the specified replacement character.

Convert timestamp to the specified timezone.

Converts a value to a binary string of a supported data type.

Calculates the Pearson correlation coefficient of the values expression1 and expression2. The function name must be enclosed in double quotes (“CORR”).

Computes the cosine of a value in radians

Computes the hyperbolic cosine of a value in radians.

Computes the cotangent of a value in radians.

Returns the total number of records for the specified expression.

Returns the population covariance for non-NULL pairs across all input values.

Returns the sample covariance for non-NULL pairs across all input values.

Returns the cumulative distribution of the current row with regard to other values within the same window partition.

Returns the current date of the system.

Returns the current date of the system based on the UTC timezone.

Returns the current time for the system.

Returns the current timestamp for the system in UTC time only.

Compares two dates or timestamps and returns the difference in days.

Returns the sum of two expressions of time as another expression of time.

Returns the difference between two expressions of time as another expression of time.

Return subfields such as year or hour from date or timestamp values

Returns the difference of two expressions of time as another expression of time.

Truncates the date or timestamp to the indicated precision.

Returns the day of month of the date or timestamp.

Returns the day of month of the date or timestamp.

Returns the day of the week (from 1 to 7) of the date or timestamp.

Returns the day of the year (from 1 to 366) of the date or timestamp.

Converts radians to degrees.

Returns the rank of the current row within its partition and ordering. Rows that are equal will have the same rank.

Returns Euler’s number, a constant approximately equal to 2.718281828459045.

Returns whether a string ends with another string. The comparison is case-sensitive.

Calculates Euler’s number, e, raised to the power of the specified value.

Extracts the specified date or time part from the date or timestamp.

Returns the first value within an ordered group of a result set.

Explodes compound values into multiple rows. This function takes a LIST column and produces a lateral view (that is, an inline view that contains correlation referring to other tables that precede it in the FROM clause).

Returns the value from the specifed expression rounded to the nearest equal or smaller integer.

Returns a binary value for the given hexadecimal string

Returns the largest value from a list of expressions.

Returns a hash value of the arguments. HASH does not return NULL, even for NULL inputs.

Returns the hexadecimal encoding of an expression.

Uses HyperLogLog to return an approximation of the distinct cardinality of the input.

Extracts the hour number (from 0 to 23) for a given time or timestamp.

Tests whether an expression matches a pattern. The comparison is case-insensitive.

Returns the input string with the first letter of each word in uppercase and the subsequent letters in the word are in lowercase).

Returns the position of the first occurrence of a string when it is contained in another string. If no such occurrence is found, a zero is returned. The comparison is case-sensitive.

Compares two expressions to determine whether they have the same or different values. NULLs are considered as comparable values.

Tests whether the input expression is false. If it is, returns a value of true.

Determines if an expression is NULL or not NULL. Alias for the function ISNULL/ISNOTNULL.

Determines whether an expression is a valid numeric type (DECIMAL, DOUBLE, INT, BIGINT, VARBINARY).

Returns TRUE if the input expression evaluates to TRUE.

Returns TRUE if the input expression is an big integer value.

Returns TRUE if the input expression can be cast to a date.

Returns TRUE if the input expression is an integer value.

Returns whether the current user is a member of the specified role.

Returns whether an expression is valid UTF-8

Returns TRUE if the input expression is a varchar value.

Returns the row before the current one in a partition based on the ORDER BY clause without the need for a self-join. If there are no rows, this function returns NULL.

Returns the last day of the month for the specified date or timestamp.

Returns the input expression with all the characters converted to lowercase.

Returns the row after the current one in the same result set without the need for a self-join. If there are no rows, this function returns NULL.

Returns the smallest value from a list of expressions.

Returns the left-most substring. The function name must be enclosed in double quotes ("LEFT").

Returns the length of an input string. If the character encoding isn’t specified, it assumes to UTF8.

Computes the Levenshtein distance between two input expressions.

Tests whether an expression matches one or more patterns. Comparisons are case-sensitive.

Concatenates a group of rows into a list of strings and places a separator between them.

Searches for the first occurrence of the first argument in the second argument and if found, returns the position the of the first argument in the second argument. The first character in a string is position 1. Returns 0 if the substring isn’t found in the expression.

Returns the logarithm of the numeric input expression. If no base is specified, the natural log (ln) will be calculated.

Returns the log base 10 of the numeric input expression.

Returns the input expression with all the characters converted to lowercase.

Left pads a string with spaces or specified characters to reach the number of characters specified as a parameter.

Shifts the bits of the numeric expression to the left.

Removes leading spaces or characters from a string.

Returns all keys from a map expression.

Returns all values from a map expression.

Returns a masked version of a string.

Returns a masked version of a string with the first num_chars characters masked. By default, if you do not provide a mask value, the first four characters are masked.

Returns a consistent hash value based on the input string. This function returns NULL for non-string types.

Returns a masked version of a string with the last num_chars characters masked. By default, if you do not provide a mask value, the last four characters are masked.

Returns a masked version of a string with the first num_chars characters unmasked. By default, if you do not provide a value, the first four characters are shown.

Returns a masked version of a string with the last num_chars characters unmasked. By default, if you do not provide a value, the last four characters are shown.

Returns the maximum value among the non-NULL input expressions.

Computes the MD5 hash value of a string.

Computes the median of a dataset.

Returns the minimum value among the non-NULL input expressions.

Extracts the minute number (from 0 to 59) for a given time or timestamp.

Returns the remainder of the input expression divided by the second input expression.

Extracts the month number (from 1 to 12) for a given date or timestamp.

Returns the number of months between two date or timestamp values.

Returns an approximate distinct value number, similar to COUNT(DISTINCT col). NDV can return results faster than using the combination of COUNT and DISTINCT while using a constant amount of memory, resulting in less memory usage for columns with high cardinality.

Returns the date or timestamp of the first specified day of week that occurs after the input date.

Equally splits the rows in each partition into ranked parts specified by the integer value and starting from 1. This function requires the ORDER BY clause.

Compares two expressions. If the values in each expression are equal, returns NULL and, if they are not equal, returns the value of the first expression.

Returns the length of the string in bytes.

Computes a percentile value based on a continuous distribution of the column input.

Computes a specific percentile for sorted values in a column.

Returns the relative rank of the current row in the partition based on the ORDER BY clause. The displayed percentage ranges from 0.0 to 1.0.

Returns the value of pi, which is approximately 3.14592654.

Returns the position of the first occurrence of a substring within another string.

Returns the result of raising the input value to the specified power.

Extracts the quarter number (from 1 to 4) for a given date or timestamp.

Returns a result that can be used as a properly escaped data value in a SQL statement.

Convert a value in degrees to radians

Each call returns a random generated number between 0 and 1 for each row.

Returns the rank of the current row within its partition and placement order. Rows that are equal have the same rank. However, the count of tied rows is added to the next rank, instead of being incremented by one. The rank value starts at 1 and increases sequentially.

Extracts the first string in expression that matches the REGEXP expression and corresponds to the REGEX group index.

Returns true when the specified regular expression matches values in a column. Otherwise, returns false.

Returns true when the specified regular expression matches values in a column. Otherwise, returns false.

Finds strings that match the given regular expression and replaces the strings with the given string.

Splits an input string by using a regular expression according to a keyword and an integer value.

Builds a string by repeating the input for the specified number of times

Repeats the given string n times.

Removes all occurrences of a specified substring and replaces them with another string.

Reverses the order of characters in a string.

Returns the right-most substring. The function name must be enclosed in double quotes (“RIGHT”).

Returns the rounded value for the inputted value. If no scale is specified, the closest whole number is returned.

Returns the row number for the current row based on the ORDER BY clause within each partition. Rows containing identical values receive different row numbers.

Right pads a string with spaces or specified characters to reach the number of characters specified as a parameter.

Shifts the bits of the numeric expression to the right.

Removes trailing spaces or characters from a string.

Extracts the second number (from 0 to 59) for a given date or timestamp.

Computes the SHA-1 hash value of a string.

Computes the SHA-1 hash value of a string.

Computes the 256-bit SHA-2 hash value of a string.

Computes the 512-bit SHA-2 hash value of a string.

Returns the sign of the input expression.

Tests whether the entire expression matches a pattern.

Computes the sine of a value.

Computes the hyperbolic sine of the input expression.

Returns the number of entries in a map expression.

Returns a string that contains a phonetic representation of the input string.

Splits a given string at a specified character and returns the requested part.

Returns the square root of the non-negative numeric expression.

Returns whether a string starts with another string. The comparison is case-sensitive.

Returns the standard deviation of non-NULL values in a column with a numeric data type. If all records inside a group are NULL, returns NULL.

Returns the population standard deviation (square root of variance) of non-NULL values in a column with a numeric data type. If all records inside a group are NULL, returns NULL.

Returns the sample standard deviation (square root of sample variance) of non-NULL values in a column with a numeric data type. If all records inside a group are NULL, returns NULL.

Searches for the first occurrence of the substring in the given expression and returns the position of where the substring begins. Searching binary values is also supported.

Returns the portion of the string from the specified base expression starting at the specified characters.

Returns a substring of an expression before the specified number of delimiters occurs.

Returns the sum of non-NULL input expressions.

Computes the tangent of a value in radians.

Computes the hyperbolic tangent of the input expression.

Add (or subtract) an interval of time from a date/timestamp value or column.

Return the amount of time between two date or timestamp values

Converts a string that is encoded in the specified character set to UTF-8.

Converts the input expression to a character/string using the specified format.

Converts the input expressions to the corresponding date.

Returns a hexadecimal string for the given binary value.

Converts a string into a number (double) in the specified format.

Converts the input expressions to the corresponding time.

Converts the input expressions to the corresponding timestamp.

Translates the base expression from the source characters/expression to the target characters/expression.

Removes leading, trailing, or both spaces or characters from a string.

Rounds the input expression down the nearest of equal integer depending on the specified number of places before or after the decimal point.

Reports the type (in string format) of the input expression.

Returns the input expression with all the characters converted to uppercase.

Decodes a Base64-encoded string.

Converts the hexadecimal number into the bytes represented by a number.

Returns the Unix epoch time representation of an ISO 8601 timestamp.

Returns the input expression with all the characters converted to uppercase.

Returns the population variance of non-NULL records.

Returns the sample variance of non-NULL records.

Extracts the week number (from 0 to 53) for a given date or timestamp.

Returns the week of year of the date or timestamp.

Returns the bitwise XOR of two integers.

Extracts the year for a given date or timestamp.

Last updated