SQL Functions
LiveRamp's Data Collaboration Platform supports the SQL functions listed on this page.
Tip
For information about user-defined functions (), see "User-Defined Functions."
Limitations:
Many SQL functions cannot be applied to a sensitive column, such as a rampid column.
Window Functions cannot be applied to an asset with a query threshold (minimum aggregation).
Aggregate Functions
Aggregate functions return a single value based on multiple rows/values of input.
Function | Description |
---|---|
Return the result of the bitwise AND of two expressions. | |
Return the result of the bitwise exclusive OR (XOR) of two expressions. | |
Return the result of the bitwise OR of two expressions. | |
Return the result of the bitwise NOT of the expression. | |
Estimate cardinality (the number of elements of a set) using the HyperLogLog++ algorithm. | |
Return the approximate percentile of a numeric column. You must specify a column and a percentage. The percentage value or percentage array values must be between 0 and 1. Note
| |
Calculate the mean from a group of values. | |
Return the collected list of non-unique elements. | |
Return the collected set of unique elements. | |
Return the total number of rows specified by the expression. Multi-column counts are not supported. | |
Return the position of the specified value in relation to all values in its partition. The | |
Return the maximum value specified in the expression. | |
Return the minimum value specified in the expression. | |
Return the approximate percentile of a numeric column. You must specify a column and a percentage. The percentage value or percentage array values must be between 0 and 1. Note
| |
Shift left (base, expr). For example: SELECT shiftleft(4, 1); | |
Shift right (base, expr). For example: SELECT shiftright(2, 1); | |
Calculate the sum from a group of values. |
Array Functions
Array functions return an array with an element for each row in a subquery.
Function | Description |
---|---|
Return an array with the specified elements. | |
Return a list of non-unique elements. The results are likely to be different each time (non-deterministic) because the row order is shuffled. | |
Return true if the array contains the specified value. This function may not work with some aggregations because the corresponding unnest operator has some limitations on BigQuery. | |
Remove any duplicate values from the returned array. | |
Return an array of the distinct elements in two specified columns and remove any duplicates. | |
Concatenate the elements specified in an array and replace null values with an optional string. | |
Return an array based on a start, end, and (optional) step integer expression. This function's parameters don't support the float data type. The generate_array and sequence functions work the same way. | |
Return an array based on a start, end, and (optional) step integer expression. This function's parameters don't support the float data type. The generate_array and sequence functions work the same way. | |
Return the size of an array or a map. | |
Sort the input array in ascending or descending order |
Bitwise Functions
Bitwise functions perform bitwise operations on numbers or numeric records.
Function | Description |
---|---|
Return the bitwise AND of non-null input values. | |
Return the number of bits set in the expression as an unsigned 64-bit integer. | |
Return the result of the bitwise OR of non-null input values. | |
Return the bitwise XOR of non-null input values. |
Conversion Functions
Conversion functions convert an expression to a different data type.
Function | Description |
---|---|
Cast the specified value as the specified data type. | |
Return the ASCII character that is the binary equivalent of the value specified in the expression. If the number is larger than 256, return the equivalent % of 256: chr(n % 256). | |
Cast the specified value to the date data type. The value can be a timestamp or a string in ISO 8601 format. | |
Cast the specified value to the double-precision floating-point format. | |
Cast the specified value as the int data type. | |
Cast the specified value as the string data type. | |
Cast the specified value to the timestamp data type. |
Date and Timestamp Functions
Date and Timestamp functions calculate and manipulate date and time values.
Function | Description |
---|---|
Return the sum of the first and second expressions. You can use this mathematical function for date addition in the following formats:
| |
Return the current date. | |
Return the current timestamp. | |
Return the local time zone of the current session. | |
Cast the specified value to the date data type. The value can be a timestamp or a string in the ISO 8601 format.
select s_rec_start_date, date(s_rec_start_date) + 1 from store | |
Return the date that is num_days after start_date. | |
Return the difference between the start date and the end date expressions based on the requested unit. date_diff( Where | |
Return the date from the specified number of days since the Unix epoch (1970-01-01). | |
Return the specified date or time part from a date, a time, or a timestamp in the following format: date_part( For example: Where | |
Return the date that is num_days before start_date. | |
Return the specified timestamp after truncating it to the specified format. date_trunc( For example: Where | |
Return the day of the week for the timestamp (where 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, and 7 = Saturday). | |
Return the specified UTC timestamp after converting it to the specified time zone. | |
Return the last day of the month based on the specified date. | |
Return the current timestamp. | |
Convert a string representation of a date to a DATE value.
This function is only supported on BigQuery. | |
Cast the specified value to the timestamp data type. | |
Return a timestamp based on the specified number of microseconds since the Unix epoch. | |
Return a timestamp based on the specified number of milliseconds since the Unix epoch. | |
Return a timestamp based on the specified number of seconds since the Unix epoch. | |
Return the specified date after truncating it to the time portion based on the specified format model. | |
Return the number of microseconds since the Unix epoch. | |
Return the number of milliseconds since the Unix epoch. | |
Return the number of seconds since the Unix epoch. | |
Return the day of the week for the timestamp (where 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, and 6 = Sunday). |
LiveRamp Data Collaboration Platform Functions
LiveRamp Data Collaboration Platform functions provide ways to set query thresholds and return information about RampIDs.
Function | Description |
---|---|
qt | Protect row-level data when creating a UDF or when querying a table or view. Include the following in your query statement or UDF creation statement:
Where:
For example, you could include Note
|
rampid_matched | Return false if the RampID value indicates that no RampID was matched against the individual. For example, you can use this function in a
NoteRampID columns are sensitive, so this function cannot be used in arbitrary filter expressions. You are permitted to use this function to filter out rows that lack a valid RampID. |
rampid_type | When used in a
|
Logical Functions
Logical functions perform a logical operation or comparison on the specified expressions.
Note
When using aggregation, equality and comparison operators are not supported with the qt function (except for the in function).
Function | Description |
---|---|
Return the logical NOT of the specified expression, such as returning false when true is specified. | |
Return true if the first expression is not equal to the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return true if the first expression is less than the second expression. The | |
Return true if the first expression is less than the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return true if the first expression is less than or equal to the second expression. Otherwise, return false. The expressions must be of the same type. The | |
The | |
Return true if the first expression is not equal to the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return true if the first expression is equal to the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return true if the first expression is equal to the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return true if the first expression is greater than the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return true if the first expression is greater than or equal to the second expression. Otherwise, return false. The expressions must be of the same type. The | |
Return the logical AND of two expressions. | |
Evaluate whether the values in the first expression are between the second and third expressions. The | |
Return a specified result when a condition is met. Otherwise, return the value specified by the ELSE clause. The | |
Return the first non-null argument. Otherwise, return null. | |
Return the second expression if the first expression is true. Otherwise, return the third expression. The | |
Return the first argument if it's not null. Otherwise, return the second argument. The | |
Return true if the specified value equals any of the specified arguments. | |
Return true if the specified argument is not null. Otherwise, return false. | |
Return true if the specified argument is null. Otherwise, return false. | |
Return the logical NOT of the expression. | |
Return null if the first expression is equal to the second expression. The | |
Return the logical OR of the expression. | |
Return a specified result when branched conditions are met. Otherwise, return the value specified by the ELSE clause. The expressions must be of the Boolean type. The |
Mathematical Functions
Mathematical functions perform calculations on the specified values.
Function | Description |
---|---|
Return the difference between the first and second expressions. | |
Return the product of the first and second expressions. | |
Divide the first expression by the second expression and return the floating-point representation of the result. | |
Return the sum of the first and second expressions. You can also use this function for date addition. For more information, see "Datetime Functions" above. | |
Return the absolute value of the specified numeric value. | |
Return the inverse cosine of the specified value. | |
Return the inverse hyperbolic cosine of the specified value. | |
Return the inverse sine of the specified value. | |
Return the inverse hyperbolic sine of the specified value. | |
Return the inverse tangent of the specified value. | |
Returns the angle in radians between the positive x-axis of a plane and the point given by the specified coordinates. | |
Return the smallest integer that is not smaller than the specified value. | |
Return the smallest integer that is not smaller than the specified value. | |
Return the Pearson correlation coefficient between the specified set of number pairs. | |
Return the cosine of the specified value. | |
Return the hyperbolic cosine of the specified value. | |
Return the population covariance of the specified set of number pairs. | |
Return the sample covariance of the specified set of number pairs. | |
Divide the first expression by the second expression and return the resulting integer. | |
Return Euler's number. | |
Return e to the power of the specified value. | |
Return the largest integer that is not greater than the specified value. | |
Return the greatest value of all the specified parameters. | |
Return the smallest value of all the specified parameters. You can use this function with numeric (such as integer and float), date, and timestamp expressions. | |
Return the logarithm of the specified expression with base 10. | |
Return the remainder from the division of the first expression by the second expression. | |
Return an approximate value of pi. | |
Return the value of the first expression raised to the power of the second expression. | |
Return the value of the first expression raised to the power of the second expression. | |
Return a random value with independent and identically distributed uniformly distributed values within [0, 1]. Seed values are not supported. When run across different data warehouses, this function does not support resulting values via common table expressions (CTEs). You can use this function to generate a pseudo-random uniform number between 0 and 1 when sampling table rows. | |
Return a random value with independent and identically distributed uniformly distributed values within [0, 1]. Seed values are not supported. When run across different data warehouses, this function does not support resulting values via common table expressions (CTEs). You can use this function to generate a pseudo-random uniform number between 0 and 1 when sampling table rows. | |
Return the value of the first expression rounded to the specified decimal places. | |
| |
Return the sine of the specified value. | |
Return the hyperbolic sine of the specified value. | |
Return the square root of the specified value. | |
Return the sample standard deviation of the specified values. | |
Return the population standard deviation of the specified values. | |
Return the sample standard deviation of the specified values. | |
Return the tangent of the specified value. | |
Return the hyperbolic tangent of the specified value. | |
Return the population variance of the specified values. | |
Return the sample variance of the specified values. | |
Return the sample variance of the specified values. |
String Functions
String functions perform operations on string values.
Function | Description |
---|---|
Concatenate the specified values or arrays. | |
Return the ASCII code of the first character of the specified value. | |
Return the character length of the specified string. | |
Return the character length of the specified string. | |
Return the concatenation of the specified values. | |
Return the specified set of characters after capitalizing the first letter of each word and setting other characters to lowercase. | |
Return the numeric position of the first letter of the second specified string within the first string. | |
Return the character length of the specified string or the number of bytes of the specified binary data. | |
Return true if the specified string matches the specified pattern. Otherwise, return false. | |
Return the specified string in all lowercase characters. | |
Return the value padded to the left with a specified number of characters. (Optional) You can specify the character to pad with. | |
Return the specified string after removing any leading space characters. | |
Return the byte length of the specified string or the number of bytes of specified binary data. | |
Return the first string in the specified value that matches the specified REGEX. This function does not support an optional group index argument. Only one capture group is allowed. | |
Return the specified string repeated the specified number of times. | |
Replace occurrences of the specified string and replace them with another string. | |
Return the value padded to the right with a specified number of characters. (Optional) You can specify the character to pad with. | |
Return the specified string after removing any trailing space characters. | |
Return the Soundex code (a phonetic representation) for the specified string. | |
Split a string at instances of REGEX values and return an array. (Optional) Specify an integer to limit the number of times to apply the REGEX. | |
Cast the specified value as the string data type. | |
Return part of the specified string based on a specified starting position and length. | |
Return part of the specified string based on a specified starting position and length.
| |
Return the specified string after replacing any characters specified in a second string with the corresponding values in a third string. | |
Return the specified string after removing any leading and trailing space characters. | |
Return the specified string in all uppercase characters. |
Window Functions
Window functions return a value for each row based on values from a set of table rows.
Window functions cannot be applied to an asset with a query threshold (minimum aggregation).
Function | Description |
---|---|
Return the rank of a value in a group of values. Each result represents the previously assigned rank +1. The | |
Return the value of the preceding row. The | |
Return the value of the input string at the row offset (integer) after the current row in the window. The | |
Return the value of the input at the offsetth row from beginning of the window frame. The | |
Divide window partition rows into n buckets from 1 through n. | |
Return the percentage ranking of a value in a group of values. | |
Return the ranking of a value in a group of values. Each result represents the number of rows that precede or is equal to the current row of the partition +1. The | |
Assign a unique and sequential number to each row based on the ordering of rows within the window partition. The |