The Google BigQuery API offers additional SQL operators and functions. A complete list of the available syntax is located at: https://cloud.google.com/bigquery/query-reference
A SELECT statement can consist of the following basic clauses.
SELECT
INTO
FROM
JOIN
WHERE
GROUP BY
HAVING
UNION
ORDER BY
LIMIT
The following syntax diagram outlines the syntax supported by the SQL engine of the provider:
SELECT {
[ TOP <numeric_literal> | DISTINCT ]
{
*
| {
<expression> [ [ AS ] <column_reference> ]
| { <table_name> | <correlation_name> } .*
} [ , ... ]
}
[ INTO csv:// [ filename= ] <file_path> [ ;delimiter=tab ] ]
{
FROM <table_reference> [ [ AS ] <identifier> ]
} [ , ... ]
[ [
INNER | { { LEFT | RIGHT | FULL } [ OUTER ] }
] JOIN <table_reference> [ ON <search_condition> ] [ [ AS ] <identifier> ]
] [ ... ]
[ WHERE <search_condition> ]
[ GROUP BY <column_reference> [ , ... ]
[ HAVING <search_condition> ]
[ UNION [ ALL ] <select_statement> ]
[
ORDER BY
<column_reference> [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ]
]
[
LIMIT <expression>
[
{ OFFSET | , }
<expression>
]
]
} | SCOPE_IDENTITY()
<expression> ::=
| <column_reference>
| @ <parameter>
| ?
| COUNT( * | { [ DISTINCT ] <expression> } )
| { AVG | MAX | MIN | SUM | COUNT } ( <expression> )
| NULLIF ( <expression> , <expression> )
| COALESCE ( <expression> , ... )
| CASE <expression>
WHEN { <expression> | <search_condition> } THEN { <expression> | NULL } [ ... ]
[ ELSE { <expression> | NULL } ]
END
| <literal>
| <sql_function>
<search_condition> ::=
{
<expression> { = | > | < | >= | <= | <> | != | LIKE | NOT LIKE | IN | NOT IN | IS NULL | IS NOT NULL | AND | OR | CONTAINS | BETWEEN } [ <expression> ]
} [ { AND | OR } ... ]
Return all columns:
SELECT * FROM publicdata.samples.github_nested
Rename a column:
SELECT [repository.name] AS MY_repository.name FROM publicdata.samples.github_nested
Cast a column's data as a different data type:
SELECT CAST(repository.watchers AS VARCHAR) AS Str_repository.watchers FROM publicdata.samples.github_nested
Search data:
SELECT * FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework';
The Google BigQuery APIs support the following operators in the WHERE clause: =, >, <, >=, <=, <>, !=, LIKE, NOT LIKE, IN, NOT IN, IS NULL, IS NOT NULL, AND, OR.
SELECT * FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework';
Return the number of items matching the query criteria:
SELECT COUNT(*) AS MyCount FROM publicdata.samples.github_nested
Return the unique items matching the query criteria:
SELECT DISTINCT repository.name FROM publicdata.samples.github_nested
Summarize data:
SELECT repository.name, MAX(repository.watchers) FROM publicdata.samples.github_nested GROUP BY repository.name
See Aggregate Functions below for details.
Retrieve data from multiple tables.
SELECT * FROM CRMAccounts INNER JOIN ERPCustomers ON CRMAccounts.BillingState = ERPCustomers.BillingState
See JOIN Queries below for details.
Sort a result set in ascending order:
SELECT actor.attributes.email, repository.name FROM publicdata.samples.github_nested ORDER BY repository.name ASC
Restrict a result set to the specified number of rows:
SELECT actor.attributes.email, repository.name FROM publicdata.samples.github_nested LIMIT 10
Parameterize a query to pass in inputs at execution time. This enables you to create prepared statements and mitigate SQL injection attacks.
SELECT * FROM publicdata.samples.github_nested WHERE repository.name = @param
The Google BigQuery API offers additional SQL operators and functions. A complete list of the available syntax is located at: https://cloud.google.com/bigquery/query-reference
Below are several examples of SQL aggregate functions. You can use these with a GROUP BY clause to aggregate rows based on the specified GROUP BY criterion. This can be a reporting tool.
Returns the number of rows matching the query criteria.
SELECT COUNT(*) FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework'
Returns the average of the column values.
SELECT repository.name, AVG(repository.watchers) FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework'
GROUP BY repository.name
Returns the minimum column value.
SELECT MIN(repository.watchers), repository.name FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework'
GROUP BY repository.name
Returns the maximum column value.
SELECT repository.name, MAX(repository.watchers) FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework'
GROUP BY repository.name
Returns the total sum of the column values.
SELECT SUM(repository.watchers) FROM publicdata.samples.github_nested WHERE repository.name = 'EntityFramework'
Returns the Pearson correlation coefficient of a set of number pairs.
SELECT repository.name, CORR(repository.watchers, repository.size) FROM publicdata.samples.github_nested
Computes the population covariance of the values computed by a set of number pairs.
SELECT repository.name, COVAR_POP(repository.watchers, repository.size) FROM publicdata.samples.github_nested
Computes the sample covariance of the values computed by a set of number pairs.
SELECT repository.name, COVAR_SAMP(repository.watchers, repository.size) FROM publicdata.samples.github_nested
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.
SELECT repository.name, NTH(n, actor.attributes.email) FROM publicdata.samples.github_nested
Returns the standard deviation of the computed values. Rows with a NULL value are not included in the calculation.
SELECT repository.name, STDDEV(repository.watchers) FROM publicdata.samples.github_nested
The provider supports the complete join syntax in Google BigQuery. Google BigQuery supports inner joins, outer joins, and cross joins. The default is inner. Multiple join operations are supported.
SELECT field_1 [..., field_n] FROM table_1 [[AS] alias_1] [[INNER|[FULL|RIGHT|LEFT] OUTER|CROSS] JOIN [EACH] table_2 [[AS] alias_2] [ON join_condition_1 [... AND join_condition_n]] ]+
Note that the default join is an inner join. The following limitations exist on joins in Google BigQuery:
Cross joins must not contain an ON clause.
Normal joins require that the right-side table must contain less than 8 MB of compressed data. If you are working with tables larger than 8 MB, use the EACH modifier. Note that EACH cannot be used in cross joins.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Returns the Pearson correlation coefficient of a set of number pairs.
numeric_expression1: The first series.
numeric_expression2: The second series.
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.
Computes the population covariance of the values computed by numeric_expression1 and numeric_expression2.
numeric_expression: The first series.
numeric_expression: The second series.
Computes the sample covariance of the values computed by numeric_expression1 and numeric_expression2.
numeric_expression: The first series.
numeric_expression: The second series.
Returns the first sequential value in the scope of the function. Note: this function is only available when UseLegacySQL=True.
column: Any column expression.
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
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.
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.
Returns the last sequential value in the scope of the function. Note: this function is only available when UseLegacySQL=True.
column: Any column expression
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
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.
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.
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.
Returns the current UNIX timestamp in microseconds. Note: this function is only available when UseLegacySQL=True.
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.
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.
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.
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.
Computes the population standard deviation of the value computed by numeric_expr.
numeric_expression: The series to calculate STDDEV on.
Computes the sample standard deviation of the value computed by numeric_expr.
numeric_expression: The series to calculate STDDEV on.
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.
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 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.
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.
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.
Computes the population variance of the values computed by numeric_expr.
numeric_expression: The series to calculate VARIANCE on.
Computes the sample variance of the values computed by numeric_expr.
numeric_expression: The series to calculate VARIANCE on.
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).
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).
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.
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.
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.
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].
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].
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
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
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).
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.
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.
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 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.
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.
Returns a human-readable string of the current date in the format %Y-%m-%d.
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.
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.
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.
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.
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.
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.
Returns the current time as a DATETIME object.
timezone: The timezone to use when retrieving the current datetime object.
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.
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.
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.
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.
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.
Returns a human-readable string of the server's current time in the format %H:%M:%S.
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.
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.
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.
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.
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.
Returns a TIMESTAMP data type of the server's current time in the format %Y-%m-%d %H:%M:%S.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
Returns the absolute value of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the arc cosine of the argument.
expression: Any column or literal expression.
Returns the arc hyperbolic cosine of the argument.
expression: Any column or literal expression.
Returns arcsine in radians.
expression: Any column or literal expression.
Returns the arc hyperbolic sine of the argument.
expression: Any column or literal expression.
Returns arc tangent of the argument.
expression: Any column or literal expression.
Returns the arc hyperbolic tangent of the argument.
expression: Any column or literal expression.
Returns the arc tangent of the two arguments.
expression1: Any column or literal expression.
expression2: Any column or literal expression.
Rounds the argument up to the nearest whole number and returns the rounded value.
expression: Any column or literal expression.
Synonym for CEIL function.
expression: Any column or literal expression.
Returns the cosine of the argument.
expression: Any column or literal expression.
Returns the hyperbolic cosine of the argument.
expression: Any column or literal expression.
Returns expression, converted from radians to degrees. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal 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.
Rounds the argument down to the nearest whole number and returns the rounded value.
expression: Any column or literal expression.
Returns the natural logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the natural logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the Base-2 logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the Base-10 logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns PI. Note: this function is only available when UseLegacySQL=True.
Returns the result of raising expression1 to the power of expression2.
expression1: Any column or literal expression.
expression2: Any column or literal expression.
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.
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.
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.
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.
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.
Returns the sine of the argument.
expression: Any column or literal expression.
Returns the hyperbolic sine of the argument.
expression: Any column or literal expression.
Returns the square root of the expression. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the tangent of the argument.
expression: Any column or literal expression.
Returns the hyperbolic tangent of the argument.
expression: Any column or literal expression.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
str2: The pad characters.
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.
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.
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.
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.
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.
str2: The pad characters.
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.
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 (,).
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.
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.
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.
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.
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.
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.
Returns the original string with all characters in upper case.
str: The string to upper.
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.
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.
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.
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.
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.
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.
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.
readable_ip: The IPv4 address to convert to an integer.
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).
readable_ip: The IPv4 address to convert to an integer.
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.
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.
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.
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.
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.
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
Returns true if str matches the regular expression. For string matching without regular expressions, use CONTAINS instead of REGEXP_MATCH. 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.
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.
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.
Returns a human-readable string of the current date in the format %Y-%m-%d.
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.
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.
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.
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.
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.
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.
Returns the current time as a DATETIME object.
timezone: The timezone to use when retrieving the current datetime object.
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.
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.
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.
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.
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.
Returns a human-readable string of the server's current time in the format %H:%M:%S.
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.
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.
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.
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.
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.
Returns a TIMESTAMP data type of the server's current time in the format %Y-%m-%d %H:%M:%S.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
Returns the absolute value of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the arc cosine of the argument.
expression: Any column or literal expression.
Returns the arc hyperbolic cosine of the argument.
expression: Any column or literal expression.
Returns arcsine in radians.
expression: Any column or literal expression.
Returns the arc hyperbolic sine of the argument.
expression: Any column or literal expression.
Returns arc tangent of the argument.
expression: Any column or literal expression.
Returns the arc hyperbolic tangent of the argument.
expression: Any column or literal expression.
Returns the arc tangent of the two arguments.
expression1: Any column or literal expression.
expression2: Any column or literal expression.
Rounds the argument up to the nearest whole number and returns the rounded value.
expression: Any column or literal expression.
Synonym for CEIL function.
expression: Any column or literal expression.
Returns the cosine of the argument.
expression: Any column or literal expression.
Returns the hyperbolic cosine of the argument.
expression: Any column or literal expression.
Returns expression, converted from radians to degrees. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal 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.
Rounds the argument down to the nearest whole number and returns the rounded value.
expression: Any column or literal expression.
Returns the natural logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the natural logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the Base-2 logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the Base-10 logarithm of the argument. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns PI. Note: this function is only available when UseLegacySQL=True.
Returns the result of raising expression1 to the power of expression2.
expression1: Any column or literal expression.
expression2: Any column or literal expression.
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.
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.
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.
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.
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.
Returns the sine of the argument.
expression: Any column or literal expression.
Returns the hyperbolic sine of the argument.
expression: Any column or literal expression.
Returns the square root of the expression. Note: this function is only available when UseLegacySQL=True.
expression: Any column or literal expression.
Returns the tangent of the argument.
expression: Any column or literal expression.
Returns the hyperbolic tangent of the argument.
expression: Any column or literal expression.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
str2: The pad characters.
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.
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.
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.
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.
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.
str2: The pad characters.
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.
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 (,).
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.
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.
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.
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.
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.
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.
Returns the original string with all characters in upper case.
str: The string to upper.
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.
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.
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.
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.
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.
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.
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.
readable_ip: The IPv4 address to convert to an integer.
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).
readable_ip: The IPv4 address to convert to an integer.
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.
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.
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.
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.
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.
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