Available for:
Questions / Feedback?

# Projection Functions

## ANY_VALUE(expression)

Returns any value from the input or NULL if there are zero input rows. The value returned is non-deterministic, which means you might receive a different result each time you use this function.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to retrieve a value from.

## APPROX_COUNT_DISTINCT(expression)

Returns the approximate result for COUNT(DISTINCT expression). The value returned is a statistical estimate-not necessarily the actual value. This function is less accurate than COUNT(DISTINCT expression), but performs better on huge input.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the approximate count distinct on.

## APPROX_QUANTILES(expression, number)

Returns the approximate boundaries for a group of expression values, where number represents the number of quantiles to create. This function returns an array of number + 1 elements, where the first element is the approximate minimum and the last element is the approximate maximum.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the approximate quantiles on.
• number: The number of quantiles to create.

## APPROX_TOP_COUNT(expression, number)

Returns the approximate top elements of expression. The number parameter specifies the number of elements returned.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the approximate top count on.
• number: The number of elements to be returned.

## APPROX_TOP_SUM(expression, weight, number)

Returns the approximate top elements of expression, based on the sum of an assigned weight. The number parameter specifies the number of elements returned. If the weight input is negative or NaN, this function returns an error.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the approximate top sum on.
• weight: The assigned weight.
• number: The number of elements to be returned.

## ARRAY(subquery)

The ARRAY function returns an ARRAY with one element for each row in a subquery.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• subquery: The subquery to execute.

## ARRAY_CONCAT(array_expr1 [, array_expr2 [, ...]])

Concatenates one or more arrays with the same element type into a single array.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• array_expr1: The first array to concatenate.
• array_expr2: The second array to concatenate.

## ARRAY_LENGTH(array_expr)

Returns the size of the array. Returns 0 for an empty array. Returns NULL if the array_expression is NULL.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• array_expr: The array expression to get the size of.

## ARRAY_TO_STRING(array_expr, delimiter [, null_text])

Returns a concatenation of the elements in array_expression as a STRING. The value for array_expression can either be an array of STRING or BYTES data types.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• array_expr: The array expression to convert to string.
• delimiter: The delimiter string used to delimit the array values.
• null_text: If the null_text parameter is used, the function replaces any NULL values in the array with the value of null_text. If the null_text parameter is not used, the function omits the NULL value and its preceding delimiter.

## GENERATE_ARRAY(start_expr, end_expr [, step_expr])

Returns an array of values. The start_expression and end_expression parameters determine the inclusive start and end of the array.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• start_expr: The starting value.
• end_expr: The ending value.
• step_expr: The increment used to generate array values.

## GENERATE_DATE_ARRAY(start_date, end_date [, INTERVAL int_expr date_part])

Returns an array of dates. The start_date and end_date parameters determine the inclusive start and end of the array.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• start_date: The starting date.
• end_date: The ending date.
• int_expr: The increment used to generate dates.
• date_part: The date part used to increment the generated dates. Valid values are: DAY, WEEK, MONTH, QUARTER, and YEAR.

## ARRAY_REVERSE(array_expr)

Returns the input ARRAY with elements in reverse order.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• array_expr: The array to reverse.

## ARRAY_AGG(expression)

Returns an ARRAY of expression values.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression values to generate an array from.

## ARRAY_CONCAT_AGG(expression1[, expression2 [,...]])

Concatenates elements from expression of type ARRAY, returning a single ARRAY as a result. This function ignores NULL input arrays, but respects the NULL elements in non-NULL input arrays (an error is raised, however, if an array in the final query result contains a NULL element).
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression1: The first expression to concatenate.
• expression2: The first expression to concatenate.

## AVG([DISTINCT] expression)

Returns the average on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the average.

## BIT_AND(numeric_expression)

Returns the result of a bitwise AND operation between each instance of numeric_expr across all rows. NULL values are ignored. This function returns NULL if all instances of numeric_expr evaluate to NULL.

• numeric_expression: The numeric expression to perform the bitwise operation.

## BIT_COUNT(expression)

The input, expression, must be an integer or BYTES. Returns the number of bits that are set in the input expression. For integers, this is the number of bits in two's complement form.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the bit count operation on.

## BIT_OR(numeric_expression)

Returns the result of a bitwise OR operation between each instance of numeric_expr across all rows. NULL values are ignored. This function returns NULL if all instances of numeric_expr evaluate to NULL.

• numeric_expression: The numeric expression to perform the bitwise operation.

## BIT_XOR(numeric_expression)

Returns the result of a bitwise XOR operation between each instance of numeric_expr across all rows. NULL values are ignored. This function returns NULL if all instances of numeric_expr evaluate to NULL.

• numeric_expression: The numeric expression to perform the bitwise operation.

## CORR(numeric_expression1, numeric_expression2)

Returns the Pearson correlation coefficient of a set of number pairs.

• numeric_expression1: The first series.
• numeric_expression2: The second series.

## COUNTIF(expression)

Returns the count of TRUE values for expression. Returns 0 if there are zero input rows or expression evaluates to FALSE for all rows.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to evaluate.

## COVAR_POP(numeric_expression1, numeric_expression2)

Computes the population covariance of the values computed by numeric_expression1 and numeric_expression2.

• numeric_expression: The first series.
• numeric_expression: The second series.

## COVAR_SAMP(numeric_expression1, numeric_expression2)

Computes the sample covariance of the values computed by numeric_expression1 and numeric_expression2.

• numeric_expression: The first series.
• numeric_expression: The second series.

## FIRST(column)

Returns the first sequential value in the scope of the function.
Note: this function is only available when UseLegacySQL=True.

• column: Any column expression.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.
Note: this function only supports [IGNORE NULLS] when using Standard SQL (UseLegacySQL=False).

• value_expression: Any value expression

## GROUP_CONCAT(string_expression [, separator])

Concatenates multiple strings into a single string, where each value is separated by the optional separator parameter. If separator is omitted, returns a comma-separated string.
Note: this function is only available when UseLegacySQL=True.

• string_expression: The string expression to concat.
• separator: The separator.

## GROUP_CONCAT_UNQUOTED(string_expression [, separator])

Concatenates multiple strings into a single string, where each value is separated by the optional separator parameter. If separator is omitted, BigQuery returns a comma-separated string. Unlike GROUP_CONCAT, this function will not add double quotes to returned values that include a double quote character. For example, the string a"b would return as a"b.
Note: this function is only available when UseLegacySQL=True.

• string_expression: The string expression to concat.
• separator: The separator.

## LAST(column)

Returns the last sequential value in the scope of the function.
Note: this function is only available when UseLegacySQL=True.

• column: Any column expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.
Note: this function only supports [IGNORE NULLS] when using Standard SQL (UseLegacySQL=False).

• value_expression: Any value expression

## LOGICAL_AND(expression)

Returns the logical AND of all non-NULL expressions. Returns NULL if there are zero input rows or expression evaluates to NULL for all rows.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the logical AND on.

## LOGICAL_OR(expression)

Returns the logical OR of all non-NULL expressions. Returns NULL if there are zero input rows or expression evaluates to NULL for all rows.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to perform the logical OR on.

## NEST(expression)

Aggregates all values in the current aggregation scope into a repeated field. For example, the query SELECT x, NEST(y) FROM ... GROUP BY x returns one output record for each distinct x value, and contains a repeated field for all y values paired with x in the query input. The NEST function requires a GROUP BY clause.
Note: this function is only available when UseLegacySQL=True.

• expression: Any expression.

## NOW()

Returns the current UNIX timestamp in microseconds.
Note: this function is only available when UseLegacySQL=True.

## NTH(n, field)

Returns the nth sequential value in the scope of the function, where n is a constant. The NTH function starts counting at 1, so there is no zeroth term. If the scope of the function has less than n values, the function returns NULL.
Note: this function is only available when UseLegacySQL=True.

• n: The nth sequential value.
• field: The column name.

## NTH_VALUE(value_expression, constant_integer_expression)

Returns the value of value_expression at the Nth row of the current window frame, where Nth is defined by constant_integer_expression. Returns NULL if there is no such row.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value_expression: Any value expression.
• constant_integer_expression: The nth sequential value.

## QUANTILES(expression [, buckets])

Computes approximate minimum, maximum, and quantiles for the input expression. NULL input values are ignored. Empty or exclusively-NULL input results in NULL output. The number of quantiles computed is controlled with the optional buckets parameter, which includes the minimum and maximum in the count.
Note: this function is only available when UseLegacySQL=True.

• expression: The numeric expression to compute quantiles on.
• buckets: The number of buckets.

## STDDEV(numeric_expression)

Returns the standard deviation of the values computed by numeric_expr. Rows with a NULL value are not included in the calculation.

• numeric_expression: The series to calculate STDDEV on.

## STDDEV_POP(numeric_expression)

Computes the population standard deviation of the value computed by numeric_expr.

• numeric_expression: The series to calculate STDDEV on.

## STDDEV_SAMP([DISTINCT] numeric_expression)

Computes the sample standard deviation of the value computed by numeric_expr.

• numeric_expression: The series to calculate STDDEV on.

## STRING_AGG(expression[, delimiter])

Returns a value (either STRING or BYTES) obtained by concatenating non-null values. If a delimiter is specified, concatenated values are separated by that delimiter; otherwise, a comma is used as a delimiter.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The string expression to concatenate.
• delimiter: The delimiter to separate concatenated values.

## SUM([DISTINCT] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## TOP(column [, max_values][, multiplier])

TOP is a function that is an alternative to the GROUP BY clause. It is used as simplified syntax for GROUP BY ... ORDER BY ... LIMIT .... Generally, the TOP function performs faster than the full ... GROUP BY ... ORDER BY ... LIMIT ... query, but may only return approximate results.
Note: this function is only available when UseLegacySQL=True.

• numeric_expression: The series to calculate STDDEV on.
• max_values: The maximum number of results to return. Default is 20.
• multiplier: A positive integer that increases the value(s) returned by COUNT(*) by the multiple specified.

## UNIQUE(expression)

Returns the set of unique, non-NULL values in the scope of the function in an undefined order.
Note: this function is only available when UseLegacySQL=True.

• expression: Any expression.

## VARIANCE(numeric_expression)

Computes the variance of the values computed by numeric_expr. Rows with a NULL value are not included in the calculation.

• numeric_expression: The series to calculate VARIANCE on.

## VAR_POP(numeric_expression)

Computes the population variance of the values computed by numeric_expr.

• numeric_expression: The series to calculate VARIANCE on.

## VAR_SAMP([DISTINCT] numeric_expression)

Computes the sample variance of the values computed by numeric_expr.

• numeric_expression: The series to calculate VARIANCE on.

## RANK()

Returns the ordinal (1-based) rank of each row within the ordered partition. All peer rows receive the same rank value. The next row or set of peer rows receives a rank value which increments by the number of peers with the previous rank value, instead of a rank value which always increments by 1.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

## PERCENT_RANK()

Return the percentile rank of a row defined as (RK-1)/(NR-1), where RK is the RANK of the row and NR is the number of rows in the partition. Returns 0 if NR=1.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

## NTILE(constant_integer_expression)

This function divides the rows into constant_integer_expression buckets based on row ordering and returns the 1-based bucket number that is assigned to each row. The number of rows in the buckets can differ by at most 1. The remainder values (the remainder of number of rows divided by buckets) are distributed one for each bucket, starting with bucket 1. If constant_integer_expression evaluates to NULL, 0 or negative, an error is provided.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• constant_integer_expression: The number of buckets to divide the rows into.

## LEAD(value_expression [, offset [, default_expression]])

Returns the value of the value_expression on a subsequent row. Changing the offset value changes which subsequent row is returned; the default value is 1, indicating the next row in the window frame. An error occurs if offset is NULL or a negative value.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value_expression: The value expression.
• offset: The offset to use. Must be a non-negative integer.
• default_expression: The default expression. Must be compatible with the value_expression type.

## LAG(value_expression [, offset [, default_expression]])

Returns the value of the value_expression on a subsequent row. Changing the offset value changes which subsequent row is returned; the default value is 1, indicating the next row in the window frame. An error occurs if offset is NULL or a negative value.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value_expression: The value expression.
• offset: The offset to use. Must be a non-negative integer.
• default_expression: The default expression. Must be compatible with the value_expression type.

## PERCENTILE_CONT(value_expression [, percentile [{RESPECT | IGNORE} NULLS]])

Computes the specified percentile value for the value_expression, with linear interpolation.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value_expression: A numeric expression.
• percentile: A literal in the range [0, 1].

## PERCENTILE_DISC(value_expression, percentile [{RESPECT | IGNORE} NULLS])

Computes the specified percentile value for a discrete value_expression. The returned value is the first sorted value of value_expression with cumulative distribution greater than or equal to the given percentile value.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value_expression: Any orderable type.
• percentile: A literal in the range [0, 1].

## COALESCE(expr1 [, expr2 [, ...]])

Returns the value of the first non-null expression. The remaining expressions are not evaluated. All input expressions must be implicitly coercible to a common supertype.
Note: this function currently accepts up to 9 expressions.

• expr1: Any expression
• expr2: Any expression

## NULLIF(expression, expression_to_match)

Returns NULL if expression = expression_to_match is true, otherwise returns expression. expression and expression_to_match must be implicitly coercible to a common supertype; equality comparison is done on coerced values.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: Any expression
• expression_to_match: Any expression to be matched

## CUME_DIST()

Return the relative rank of a row defined as NP/NR. NP is defined to be the number of rows that either precede or are peers with the current row. NR is the number of rows in the partition.
Note: this function returns a double when using Legacy SQL (UseLegacySQL=True).

## DENSE_RANK()

Returns the ordinal (1-based) rank of each row within the window partition. All peer rows receive the same rank value, and the subsequent rank value is incremented by one.

## ROW_NUMBER()

Does not require the ORDER BY clause. Returns the sequential row ordinal (1-based) of each row for each ordered partition. If the ORDER BY clause is unspecified then the result is non-deterministic.

## IFNULL(expr, null_result)

If expr is NULL, return null_result. Otherwise, return expr. If expr is not NULL, null_result is not evaluated. expr and null_result must be implicitly coercible to a common supertype. Synonym for COALESCE(expr, null_result)

• expr: Any expression
• null_result: The result to return if expr is null

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## SAFE_CAST(expression)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.SAFE_CAST is identical to CAST, except it returns NULL instead of raising an error.

• expression: The expression to cast.

## CURRENT_DATE()

Returns a human-readable string of the current date in the format %Y-%m-%d.

## DATE(timestamp [, timezone])

Converts a timestamp_expression to a DATE data type.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The timestamp from which to return the date.
• timezone: The timezone to use when converting the timestamp. If not specified, the default timezone, UTC, is used.

## DATEDIFF(timestamp1, timestamp2)

Returns the number of days between two TIMESTAMP data types. The result is positive if the first TIMESTAMP data type comes after the second TIMESTAMP data type, and otherwise the result is negative.
Note: this function is only available when UseLegacySQL=True.

• timestamp1: The first timestamp.
• timestamp2: The second timestamp.

## DATE_DIFF(date1, date2, date_part)

Computes the number of specified date_part differences between two date expressions. This can be thought of as the number of date_part boundaries crossed between the two dates. If the first date occurs before the second date, then the result is negative.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• date1: The first date.
• date2: The second date.
• date_part: The date part. Supported values are: DAY, MONTH, QUARTER, YEAR.

## DATE_TRUNC(date, date_part)

Truncates the date to the specified granularity.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• date: The date to truncate.
• date_part: The date part. Supported values are: DAY, WEEK, ISOWEEK, MONTH, QUARTER, YEAR, ISOYEAR.

## FORMAT_DATE(format_string, date_expr)

Formats the date_expr according to the specified format_string.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to format the date_expr.
• date_expr: The date to format.

## PARSE_DATE(format_string, date_string)

Uses a format_string and a string representation of a date to return a DATE object.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to parse the date_string.
• date_string: The date string to parse.

## CURRENT_DATETIME([timezone])

Returns the current time as a DATETIME object.

• timezone: The timezone to use when retrieving the current datetime object.

## DATETIME(timestamp [, timezone])

Constructs a DATETIME object using a TIMESTAMP object.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The timestamp from which to return the datetime.
• timezone: The timezone to use when converting the timestamp. If not specified, the default timezone, UTC, is used.

## DATETIME_DIFF(datetime1, datetime2, date_part)

Computes the number of specified date_part differences between two date expressions. This can be thought of as the number of date_part boundaries crossed between the two dates. If the first date occurs before the second date, then the result is negative.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• datetime1: The first datetime.
• datetime2: The second datetime.
• date_part: The date part. Possible values include: MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, and YEAR.

## DATETIME_TRUNC(datetime, part)

Truncates the datetime to the specified granularity.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• date: The datetime to truncate.
• part: The date part. Possible values include: MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, ISOWEEK, MONTH, QUARTER, YEAR, and ISOYEAR.

## FORMAT_DATETIME(format_string, datetime_expr)

Formats the date_expr according to the specified format_string.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to format the date_expr.
• datetime_expr: The datetime to format.

## PARSE_DATETIME(format_string, datetime_string)

Uses a format_string and a string representation of a date to return a DATETIME object.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to parse the date_string.
• datetime_string: The datetime string to parse.

## CURRENT_TIME()

Returns a human-readable string of the server's current time in the format %H:%M:%S.

## TIME(timestamp [, timezone])

Constructs a DATETIME object using a TIMESTAMP object.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The timestamp from which to return the datetime.
• timezone: The timezone to use when converting the timestamp. If not specified, the default timezone, UTC, is used.

## TIME_DIFF(time1, time2, time_part)

Computes the number of specified time_part differences between two time expressions. This can be thought of as the number of time_part boundaries crossed between the two times. If the first time occurs before the second time, then the result is negative.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• time1: The first time.
• time2: The second time.
• time_part: The time part. Possible values include: MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR.

## TIME_TRUNC(time, part)

Truncates the time to the specified granularity.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• time: The time to truncate.
• part: The time part. Possible values include: MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR.

## FORMAT_TIME(format_string, time_expr)

Formats the date_expr according to the specified format_string.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to format the date_expr.
• time_expr: The time to format.

## PARSE_TIME(format_string, time_string)

Uses a format_string and a string representation of a time to return a TIME object.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to parse the time_string.
• time_string: The time string to parse.

## CURRENT_TIMESTAMP()

Returns a TIMESTAMP data type of the server's current time in the format %Y-%m-%d %H:%M:%S.

## TIMESTAMP_DIFF(timestamp1, timestamp2, time_part)

Computes the number of specified time_part differences between two timestamp expressions. This can be thought of as the number of time_part boundaries crossed between the two timestamp. If the first timestamp occurs before the second timestamp, then the result is negative.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp1: The first timestamp.
• timestamp2: The second timestamp.
• time_part: The timestamp part. Possible values include: MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR.

## FORMAT_TIMESTAMP(format_string, timestamp_expr)

Formats the date_expr according to the specified format_string.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to format the date_expr.
• timestamp_expr: The timestamp to format.

## PARSE_TIMESTAMP(format_string, timestamp_string)

Uses a format_string and a string representation of a timestamp to return a TIMESTAMP object.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• format_string: The format string used to parse the timestamp_string.
• timestamp_string: The timestamp string to parse.

## DAY(timestamp)

Returns the day of the month of a TIMESTAMP data type as an integer between 1 and 31, inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the day of the month.

## DAYOFWEEK(timestamp)

Returns the day of the week of a TIMESTAMP data type as an integer between 1 (Sunday) and 7 (Saturday), inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the day of the week.

## DAYOFYEAR(timestamp)

Returns the day of the year of a TIMESTAMP data type as an integer between 1 and 366, inclusively. The integer 1 refers to January 1.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the day of the year.

## FORMAT_UTC_USEC(unix_timestamp)

Returns a human-readable string representation of a UNIX timestamp in the format YYYY-MM-DD HH:MM:SS.uuuuuu.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The unix timestamp to format.

## HOUR(timestamp)

Returns the hour of a TIMESTAMP data type as an integer between 0 and 23, inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the hour as an integer.

## MINUTE(timestamp)

Returns the minutes of a TIMESTAMP data type as an integer between 0 and 59, inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the minutes as an integer.

## MONTH(timestamp)

Returns the month of a TIMESTAMP data type as an integer between 1 and 12, inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the month as an integer.

## MSEC_TO_TIMESTAMP(unix_timestamp)

Converts a UNIX timestamp in milliseconds to a TIMESTAMP data type.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The unix timestamp to convert.

## PARSE_UTC_USEC(date_string)

Converts a date string to a UNIX timestamp in microseconds. date_string must have the format YYYY-MM-DD HH:MM:SS[.uuuuuu]. The fractional part of the second can be up to 6 digits long or can be omitted.
Note: this function is only available when UseLegacySQL=True.

• date_string: The date string to convert.

## QUARTER(timestamp)

Returns the quarter of the year of a TIMESTAMP data type as an integer between 1 and 4, inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the quarter as an integer.

## SEC_TO_TIMESTAMP(unix_timestamp)

Converts a UNIX timestamp in seconds to a TIMESTAMP data type.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to convert.

## SECOND(timestamp)

Returns the seconds of a TIMESTAMP data type as an integer between 0 and 59, inclusively. During a leap second, the integer range is between 0 and 60, inclusively.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the second as an integer.

## STRFTIME_UTC_USEC(unix_timestamp, date_format_str)

Returns a human-readable date string in the format date_format_str.date_format_str can include date-related punctuation characters (such as / and -) and special characters accepted by the strftime function in C++ (such as %d for day of month).
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to convert.
• date_format_str: The date format string.

## TIMESTAMP_SECONDS(unix_timestamp)

Interprets INT64_expression as the number of seconds since 1970-01-01 00:00:00 UTC.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The unix timestamp to convert.

## TIMESTAMP_MILLIS(unix_timestamp)

Interprets INT64_expression as the number of milliseconds since 1970-01-01 00:00:00 UTC.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The unix timestamp to convert.

## TIMESTAMP_MICROS(unix_timestamp)

Interprets INT64_expression as the number of microseconds since 1970-01-01 00:00:00 UTC.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The unix timestamp to convert.

## TIMESTAMP_TO_MSEC(timestamp)

Converts a TIMESTAMP data type to a UNIX timestamp in milliseconds.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp to convert.

## TIMESTAMP_TO_SEC(timestamp)

Converts a TIMESTAMP data type to a UNIX timestamp in seconds.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp to convert.

## TIMESTAMP_TO_USEC(timestamp)

Converts a TIMESTAMP data type to a UNIX timestamp in microseconds.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp to convert.

## UNIX_DATE(date_string)

Returns the number of days since 1970-01-01.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• date_string: The date string to convert.

## UNIX_SECONDS(timestamp)

Returns the number of seconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The timestamp to convert.

## UNIX_MILLIS(timestamp)

Returns the number of milliseconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The timestamp to convert.

## UNIX_MICROS(timestamp)

Returns the number of microseconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• timestamp: The timestamp to convert.

## USEC_TO_TIMESTAMP(unix_timestamp)

Converts a UNIX timestamp in microseconds to a TIMESTAMP data type.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to convert.

## UTC_USEC_TO_DAY(unix_timestamp)

Shifts a UNIX timestamp in microseconds to the beginning of the day it occurs in.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to shift.

## UTC_USEC_TO_HOUR(unix_timestamp)

Shifts a UNIX timestamp in microseconds to the beginning of the hour it occurs in.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to shift.

## UTC_USEC_TO_MONTH(unix_timestamp)

Shifts a UNIX timestamp in microseconds to the beginning of the month it occurs in.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to shift.

## UTC_USEC_TO_WEEK(unix_timestamp, day_of_week)

Returns a UNIX timestamp in microseconds that represents a day in the week of the unix_timestamp argument.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to shift.
• day_of_week: A day of the week from 0 (Sunday) to 6 (Saturday).

## UTC_USEC_TO_YEAR(unix_timestamp)

Returns a UNIX timestamp in microseconds that represents the year of the unix_timestamp argument.
Note: this function is only available when UseLegacySQL=True.

• unix_timestamp: The unix timestamp to convert.

## WEEK(timestamp)

Returns the week of a TIMESTAMP data type as an integer between 1 and 53, inclusively. Weeks begin on Sunday, so if January 1 is on a day other than Sunday, week 1 has fewer than 7 days and the first Sunday of the year is the first day of week 2.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the week as an integer.

## YEAR(timestamp)

Returns the year of a TIMESTAMP data type.
Note: this function is only available when UseLegacySQL=True.

• timestamp: The timestamp from which to return the year as an integer.

## ABS(expression)

Returns the absolute value of the argument.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## ACOS(expression)

Returns the arc cosine of the argument.

• expression: Any column or literal expression.

## ACOSH(expression)

Returns the arc hyperbolic cosine of the argument.

• expression: Any column or literal expression.

## ASIN(expression)

• expression: Any column or literal expression.

## ASINH(expression)

Returns the arc hyperbolic sine of the argument.

• expression: Any column or literal expression.

## ATAN(expression)

Returns arc tangent of the argument.

• expression: Any column or literal expression.

## ATANH(expression)

Returns the arc hyperbolic tangent of the argument.

• expression: Any column or literal expression.

## ATAN2(expression1, expression2)

Returns the arc tangent of the two arguments.

• expression1: Any column or literal expression.
• expression2: Any column or literal expression.

## CEIL(expression)

Rounds the argument up to the nearest whole number and returns the rounded value.

• expression: Any column or literal expression.

## CEILING(expression)

Synonym for CEIL function.

• expression: Any column or literal expression.

## COS(expression)

Returns the cosine of the argument.

• expression: Any column or literal expression.

## COSH(expression)

Returns the hyperbolic cosine of the argument.

• expression: Any column or literal expression.

## DEGREES(expression)

Returns expression, converted from radians to degrees.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## EXP(expression)

Returns the result of raising the constant "e" - the base of the natural logarithm - to the power of expression.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## FLOOR(expression)

Rounds the argument down to the nearest whole number and returns the rounded value.

• expression: Any column or literal expression.

## LN(expression)

Returns the natural logarithm of the argument.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## LOG(expression)

Returns the natural logarithm of the argument.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## LOG2(expression)

Returns the Base-2 logarithm of the argument.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## LOG10(expression)

Returns the Base-10 logarithm of the argument.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## PI()

Returns PI.
Note: this function is only available when UseLegacySQL=True.

## POW(expression1, expression2)

Returns the result of raising expression1 to the power of expression2.

• expression1: Any column or literal expression.
• expression2: Any column or literal expression.

## POWER(expression1, expression2)

Synonym of POW function.

• expression1: Any column or literal expression.
• expression2: Any column or literal expression.

Returns expression, converted from degrees to radians.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## RAND([expression])

Returns a random float value in the range 0.0 >= value < 1.0. Each int32_seed value always generates the same sequence of random numbers within a given query, as long as you don't use a LIMIT clause. If int32_seed is not specified, BigQuery uses the current timestamp as the seed value.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## ROUND(expression [, integer_digits])

Rounds the argument either up or down to the nearest whole number (or if specified, to the specified number of digits) and returns the rounded value.

• expression: Any column or literal expression.
• integer_digits: The number of digits to round to.

## GREATEST(value1[, value2 [, ...]])

Returns NULL if any of the inputs is NULL. Otherwise, returns NaN if any of the inputs is NaN. Otherwise, returns the largest value among X1,...,XN according to the < comparison.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value1: The first value to compare.
• value2: The second value to compare.

## LEAST(value1[, value2 [, ...]])

Returns NULL if any of the inputs is NULL. Otherwise, returns NaN if any of the inputs is NaN. Otherwise, returns the smallest value among X1,...,XN according to the > comparison.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• value1: The first value to compare.
• value2: The second value to compare.

## SIN(expression)

Returns the sine of the argument.

• expression: Any column or literal expression.

## SINH(expression)

Returns the hyperbolic sine of the argument.

• expression: Any column or literal expression.

## SQRT(expression)

Returns the square root of the expression.
Note: this function is only available when UseLegacySQL=True.

• expression: Any column or literal expression.

## TAN(expression)

Returns the tangent of the argument.

• expression: Any column or literal expression.

## TANH(expression)

Returns the hyperbolic tangent of the argument.

• expression: Any column or literal expression.

## TRUNC(expression [, integer_digits])

Rounds X to the nearest integer whose absolute value is not greater than Xs. When the integer_digits parameter is specified this function is similar to ROUND(X, N) but always rounds towards zero. Unlike ROUND(X, N) it never overflows.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: Any column or literal expression.
• integer_digits: The number of digits to round to.

## BYTE_LENGTH(str)

Returns the length of the value in bytes, regardless of whether the type of the value is STRING or BYTES.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str: The string to calculate the length on.

## CHAR_LENGTH(str)

Returns the length of the STRING in characters.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str: The string to calculate the length on.

## CONCAT(str1, str2 [, str3] [, ...])

Returns the concatenation of two or more strings, or NULL if any of the values are NULL.

• str1: The first string to concatenate.
• str2: The second string to concatenate.
• str3: The third string to concatenate.

## ENDS_WITH(str1, str2)

Takes two values. Returns TRUE if the second value is a suffix of the first.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str1: The string to search in.
• str2: The string to search for.

## FROM_BASE64(string_expr)

Converts the base64-encoded input string_expr into BYTES format. To convert BYTES to a base64-encoded STRING, use TO_BASE64.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• string_expr: The string to convert from base64 encoding.

## FROM_HEX(string_expr)

Converts a hexadecimal-encoded STRING into BYTES format. Returns an error if the input STRING contains characters outside the range (0..9, A..F, a..f). The lettercase of the characters does not matter. To convert BYTES to a hexadecimal-encoded STRING, use TO_HEX.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• string_expr: The string to convert from hexadecimal encoding.

## INSTR(str1, str2)

Returns the one-based index of the first occurrence of str2 in str1, or returns 0 if str2 does not occur in str1.
Note: this function is only available when UseLegacySQL=True.

• str1: The string to search in.
• str2: The string to search for.

## LEFT(str, numeric_expression)

Returns the leftmost numeric_expr characters of str. If the number is longer than str, the full string will be returned. Example: LEFT('seattle', 3) returns sea.
Note: this function is only available when UseLegacySQL=True.

• str: The string to perform the LEFT operation on.
• numeric_expression: The number of characters to return.

## LENGTH(str)

Returns a numerical value for the length of the string. Example: if str is '123456', LENGTH returns 6.

• str: The string to calculate the length on.

## LOWER(str)

Returns the original string with all characters in lower case.

• str: The string to lower.

Pads str1 on the left with str2, repeating str2 until the result string is exactly numeric_expr characters. Example: LPAD('1', 7, '?') returns ??????1.

• str1: The string to pad.
• numeric_expression: The number of str2 instances to pad.

## LTRIM(str1 [, str2])

Removes characters from the left side of str1. If str2 is omitted, LTRIM removes spaces from the left side of str1. Otherwise, LTRIM removes any characters in str2 from the left side of str1 (case-sensitive).

• str1: The string to trim.
• str2: The characters to trim from str1.

## REPEAT(str, repetitions)

Returns a value that consists of original_value, repeated. The repetitions parameter specifies the number of times to repeat original_value. Returns NULL if either original_value or repetitions are NULL. This function return an error if the repetitions value is negative.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str: The string to repeat.
• str2: The number of repititions.

## REPLACE(original_value, from_value, to_value)

Replaces all instances of from_value within original_value with to_value.

• original_value: The string to search in.
• from_value: The string to search for.
• to_value: The string to replace instances of from_value.

## REVERSE(str)

Returns the reverse of the input STRING or BYTES.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str: The string to reverse.

## RIGHT(str, numeric_expression)

Returns the rightmost numeric_expr characters of str. If the number is longer than the string, it will return the whole string. Example: RIGHT('kirkland', 4) returns land.
Note: this function is only available when UseLegacySQL=True.

• str: The string to perform the RIGHT operation on.
• numeric_expression: The number of characters to return.

Pads str1 on the right with str2, repeating str2 until the result string is exactly numeric_expr characters. Example: RPAD('1', 7, '?') returns 1??????.

• str1: The string to pad.
• numeric_expression: The number of str2 instances to pad.

## RTRIM(str1 [, str2])

Removes trailing characters from the right side of str1. If str2 is omitted, RTRIM removes trailing spaces from str1. Otherwise, RTRIM removes any characters in str2 from the right side of str1 (case-sensitive).

• str1: The string to trim.
• str2: The characters to trim from str1.

## SPLIT(str [, delimiter])

Splits a string into repeated substrings. If delimiter is specified, the SPLIT function breaks str into substrings, using delimiter as the delimiter.

• str: The string to split.
• delimiter: The delimiter to split the string on. Default delimiter is a comma (,).

## STARTS_WITH(str1, str2)

Takes two values. Returns TRUE if the second value is a prefix of the first.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str1: The string to search in.
• str2: The string to search for.

## STRPOS(str1, str2)

Returns the 1-based index of the first occurrence of value2 inside value1. Returns 0 if value2 is not found.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str1: The string to search in.
• str2: The string to search for.

## SUBSTR(str, index [, max_len])

Returns a substring of str, starting at index. If the optional max_len parameter is used, the returned string is a maximum of max_len characters long. Counting starts at 1, so the first character in the string is in position 1 (not zero). If index is 5, the substring begins with the 5th character from the left in str. If index is -4, the substring begins with the 4th character from the right in str. Example: SUBSTR('awesome', -4, 4) returns the substring some.

• str: The original string.
• index: The starting index.
• max_len: The maximum length of the return string.

## TO_BASE64(string_expr)

Converts a sequence of BYTES into a base64-encoded STRING. To convert a base64-encoded STRING into BYTES, use FROM_BASE64.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• string_expr: The string to convert to base64 encoding.

## TO_HEX(string_expr)

Converts a sequence of BYTES into a hexadecimal STRING. Converts each byte in the STRING as two hexadecimal characters in the range (0..9, a..f). To convert a hexadecimal-encoded STRING to BYTES, use FROM_HEX.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• string_expr: The string to convert to hexadecimal encoding.

## TRIM(str1 [, str2])

Removes all leading and trailing characters that match value2. If value2 is not specified, all leading and trailing whitespace characters (as defined by the Unicode standard) are removed. If the first argument is of type BYTES, the second argument is required. If value2 contains more than one character or byte, the function removes all leading or trailing characters or bytes contained in value2.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str1: The string to trim.
• str2: The optional string characters to trim from str1.

## UPPER(str)

Returns the original string with all characters in upper case.

• str: The string to upper.

## JSON_EXTRACT(json, json_path)

Selects a value in json according to the JSONPath expression json_path. json_path must be a string constant. Returns the value in JSON string format.

• json: The JSON to select a value from.
• json_path: The JSON path of the value contained in json.

## JSON_EXTRACT_SCALAR(json, json_path)

Selects a value in json according to the JSONPath expression json_path. json_path must be a string constant, and bracket notation is not supported. Returns a scalar JSON value.

• json: The JSON to select a value from.
• json_path: The JSON path of the value contained in json.

## REGEXP_CONTAINS(str, reg_exp)

Returns TRUE if value is a partial match for the regular expression, regex. You can search for a full match by using ^ (beginning of text) and \$ (end of text). If the regex argument is invalid, the function returns an error.
Note: this function is only available when UseLegacySQL=True.

• str: The string to match in the regular expression.
• reg_exp: The regular expression to match.

## REGEXP_EXTRACT(str, reg_exp)

Returns the portion of str that matches the capturing group within the regular expression.

• str: The string to match in the regular expression.
• reg_exp: The regular expression to match.

## REGEXP_EXTRACT_ALL(str, reg_exp)

Returns an array of all substrings of value that match the regular expression, regex. The REGEXP_EXTRACT_ALL function only returns non-overlapping matches. For example, using this function to extract ana from banana returns only one substring, not two.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• str: The string to match in the regular expression.
• reg_exp: The regular expression to match.

## REGEXP_REPLACE(orig_str, reg_exp, replace_str)

Returns a string where any substring of orig_str that matches reg_exp is replaced with replace_str. For example, REGEXP_REPLACE ('Hello', 'lo', 'p') returns Help.

• orig_str: The original string to match in the regular expression.
• reg_exp: The regular expression to match.
• replace_str: The replacement for the matched orig_str in the regular expression.

## FORMAT_IP(integer_value)

Converts 32 least significant bits of integer_value to human-readable IPv4 address string.
Note: this function is only available when UseLegacySQL=True.

• integer_value: The integer value to convert to an IPv4 address.

Converts a string representing IPv4 address to unsigned integer value. For example, PARSE_IP('0.0.0.1') will return 1. If string is not a valid IPv4 address, PARSE_IP will return NULL.
Note: this function is only available when UseLegacySQL=True.

## NET.IPV4_FROM_INT64(integer_value)

Converts an IPv4 address from integer format to binary (BYTES) format in network byte order. In the integer input, the least significant bit of the IP address is stored in the least significant bit of the integer, regardless of host or client architecture. For example, 1 means 0.0.0.1, and 0x1FF means 0.0.1.255.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• integer_value: The integer value to convert to an IPv4 address.

Converts an IPv4 address from binary (BYTES) format in network byte order to integer format. In the integer output, the least significant bit of the IP address is stored in the least significant bit of the integer, regardless of host or client architecture. For example, 1 means 0.0.0.1, and 0x1FF means 0.0.1.255. The output is in the range [0, 0xFFFFFFFF]. If the input length is not 4, this function throws an error. This function does not support IPv6.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

## FARM_FINGERPRINT(expression)

Computes the fingerprint of the STRING or BYTES input using the Fingerprint64 function from the open-source FarmHash library. The output of this function for a particular input will never change.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to use to compute the fingerprint.

## MD5(expression)

Computes the hash of the input using the MD5 algorithm. The input can either be STRING or BYTES. The string version treats the input as an array of bytes. This function returns 16 bytes.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to use to compute the hash.

## SHA1(expression)

Computes the hash of the input using the SHA-1 algorithm. The input can either be STRING or BYTES. The string version treats the input as an array of bytes. This function returns 20 bytes.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to use to compute the hash.

## SHA256(expression)

Computes the hash of the input using the SHA-256 algorithm. The input can either be STRING or BYTES. The string version treats the input as an array of bytes. This function returns 32 bytes.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to use to compute the hash.

## SHA512(expression)

Computes the hash of the input using the SHA-512 algorithm. The input can either be STRING or BYTES. The string version treats the input as an array of bytes. This function returns 64 bytes.
Note: this function is only available when using Standard SQL (UseLegacySQL=False).

• expression: The expression to use to compute the hash.

## TIMESTAMP(datetime_expression[, timezone])

Convert a date, datetime, or string to a TIMESTAMP data type.
Note: this function does not support the timezone parameter and requires datetime_expression to be a string when using Legacy SQL (UseLegacySQL=True).

• datetime_expression: The expression to be converted to a timestamp
• timezone: The timezone to be used. If no timezone is specified, the default timezone, UTC, is used