# BigQuery Functions List: Syntax and Examples for Every Function | Masthead

All 143 BigQuery SQL functions we cover, by category: date, timestamp, string, array, JSON, aggregate, window and more. Each with syntax, runnable examples, common mistakes and cost notes.

> For the index of this section of the site, see [llms.txt](https://mastheadata.com/llms.txt)

BigQuery reference

# BigQuery SQL functions

The GoogleSQL functions data engineers use every day, with examples you can paste into the BigQuery console and run for free, the mistakes people make with them, and what they mean for cost. 143 functions in 12 categories.

No function matches. Try the [statements and clauses](https://mastheadata.com/bigquery/sql.md) or the [error messages](https://mastheadata.com/bigquery/errors.md).

## [Date functions](https://mastheadata.com/bigquery/date-functions.md)

*   [CURRENT\DATECURRENT\DATE() returns today's date as a DATE, in UTC unless you pass a time zone: CURRENT\DATE('America/New\York').](https://mastheadata.com/bigquery/functions/current-date.md)
*   [DATEDATE builds a DATE from year, month and day numbers, or converts a TIMESTAMP or DATETIME to its calendar date.](https://mastheadata.com/bigquery/functions/date.md)
*   [DATE\ADDDATE\ADD(date, INTERVAL n part) adds days, weeks, months, quarters or years to a DATE and returns a DATE.](https://mastheadata.com/bigquery/functions/date-add.md)
*   [DATE\BUCKETDATE\BUCKET(date, INTERVAL n DAY) returns the first day of the fixed-width bucket that contains a date, counted from an origin (1950-01-01 by default).](https://mastheadata.com/bigquery/functions/date-bucket.md)
*   [DATE\DIFFDATE\DIFF(end\date, start\date, DAY) returns the number of days between two dates as INT64.](https://mastheadata.com/bigquery/functions/date-diff.md)
*   [DATE\FROM\UNIX\DATEDATE\FROM\UNIX\DATE(n) converts a count of days since 1970-01-01 into a DATE: DATE\FROM\UNIX\DATE(20780) is 2026-11-23.](https://mastheadata.com/bigquery/functions/date-from-unix-date.md)
*   [DATE\SUBDATE\SUB(date, INTERVAL n part) subtracts days, weeks, months, quarters or years from a DATE.](https://mastheadata.com/bigquery/functions/date-sub.md)
*   [DATE\TRUNCDATE\TRUNC rounds a date down to the start of a period: DATE\TRUNC(order\date, MONTH) returns the first day of that month.](https://mastheadata.com/bigquery/functions/date-trunc.md)
*   [EXTRACTEXTRACT(part FROM value) returns one part of a DATE, DATETIME, TIMESTAMP or TIME, such as YEAR, MONTH, DAYOFWEEK, ISOWEEK or HOUR, usually as INT64.](https://mastheadata.com/bigquery/functions/extract.md)
*   [FORMAT\DATEFORMAT\DATE(format\string, date) turns a DATE into a STRING using % elements: FORMAT\DATE('%d/%m/%Y', d) gives 23/11/2026 and FORMAT\DATE('%B %Y', d) gives November 2026.](https://mastheadata.com/bigquery/functions/format-date.md)
*   [GENERATE\DATE\ARRAYGENERATE\DATE\ARRAY(start, end\[, INTERVAL n part\]) returns an ARRAY of dates from start to end, both included.](https://mastheadata.com/bigquery/functions/generate-date-array.md)
*   [LAST\DAYLAST\DAY(date) returns the last day of the month that contains a date, such as 2026-11-30 for 2026-11-23.](https://mastheadata.com/bigquery/functions/last-day.md)
*   [PARSE\DATEPARSE\DATE(format\string, string) converts a STRING to a DATE using % elements, such as PARSE\DATE('%d/%m/%Y', '23/11/2026').](https://mastheadata.com/bigquery/functions/parse-date.md)
*   [UNIX\DATEUNIX\DATE(date) returns the number of days since 1970-01-01 as INT64: UNIX\DATE(DATE '2026-11-23') is 20780.](https://mastheadata.com/bigquery/functions/unix-date.md)

## [Datetime functions](https://mastheadata.com/bigquery/datetime-functions.md)

*   [CURRENT\DATETIMECURRENT\DATETIME() returns the current date and time as a DATETIME, the wall-clock time in UTC or in the time zone you pass: CURRENT\DATETIME('Europe/Berlin').](https://mastheadata.com/bigquery/functions/current-datetime.md)
*   [DATETIMEDATETIME builds a DATETIME from numbers, from a DATE and TIME, or converts a TIMESTAMP to local wall-clock time: DATETIME(ts, 'Europe/Berlin').](https://mastheadata.com/bigquery/functions/datetime.md)
*   [DATETIME\ADDDATETIME\ADD(datetime, INTERVAL n part) adds microseconds up to years to a DATETIME and returns a DATETIME.](https://mastheadata.com/bigquery/functions/datetime-add.md)
*   [DATETIME\DIFFDATETIME\DIFF(end, start, part) returns the number of part boundaries between two DATETIME values as INT64.](https://mastheadata.com/bigquery/functions/datetime-diff.md)
*   [DATETIME\SUBDATETIME\SUB(datetime, INTERVAL n part) subtracts microseconds up to years from a DATETIME and returns a DATETIME.](https://mastheadata.com/bigquery/functions/datetime-sub.md)
*   [DATETIME\TRUNCDATETIME\TRUNC(datetime, part) rounds a DATETIME down to the start of a period, such as the hour, day, week or month.](https://mastheadata.com/bigquery/functions/datetime-trunc.md)
*   [FORMAT\DATETIMEFORMAT\DATETIME(format\string, datetime) turns a DATETIME into a STRING using % elements, for example FORMAT\DATETIME('%d/%m/%Y %H:%M', dt) gives 23/11/2026 18:45.](https://mastheadata.com/bigquery/functions/format-datetime.md)
*   [PARSE\DATETIMEPARSE\DATETIME(format\string, string) converts a STRING to a DATETIME using % elements, such as PARSE\DATETIME('%d/%m/%Y %H:%M', '23/11/2026 18:45').](https://mastheadata.com/bigquery/functions/parse-datetime.md)

## [Timestamp functions](https://mastheadata.com/bigquery/timestamp-functions.md)

*   [CURRENT\TIMESTAMPCURRENT\TIMESTAMP() returns the current instant as a TIMESTAMP with microsecond precision, shown in UTC.](https://mastheadata.com/bigquery/functions/current-timestamp.md)
*   [FORMAT\TIMESTAMPFORMAT\TIMESTAMP(format\string, ts\[, time\zone\]) converts a TIMESTAMP to a STRING with % elements, in UTC or in the zone you pass: FORMAT\TIMESTAMP('%F %H:%M', ts, 'Europe/Berlin').](https://mastheadata.com/bigquery/functions/format-timestamp.md)
*   [PARSE\TIMESTAMPPARSE\TIMESTAMP(format\string, string\[, time\zone\]) converts a STRING to a TIMESTAMP using % elements.](https://mastheadata.com/bigquery/functions/parse-timestamp.md)
*   [TIMESTAMPTIMESTAMP converts a STRING, DATE or DATETIME to a TIMESTAMP, reading it in UTC or in the time zone you pass: TIMESTAMP('2026-11-23 09:00:00', 'Europe/Berlin') is 08:00 UTC.](https://mastheadata.com/bigquery/functions/timestamp.md)
*   [TIMESTAMP\ADDTIMESTAMP\ADD(ts, INTERVAL n part) adds an exact duration to a TIMESTAMP, in MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR or DAY (24 hours).](https://mastheadata.com/bigquery/functions/timestamp-add.md)
*   [TIMESTAMP\DIFFTIMESTAMP\DIFF(end\ts, start\ts, part) returns the number of whole MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR or DAY units between two TIMESTAMPs as INT64, truncated toward zero.](https://mastheadata.com/bigquery/functions/timestamp-diff.md)
*   [TIMESTAMP\MILLISTIMESTAMP\MILLIS(n) converts milliseconds since 1970-01-01 00:00:00 UTC to a TIMESTAMP.](https://mastheadata.com/bigquery/functions/timestamp-millis.md)
*   [TIMESTAMP\SECONDSTIMESTAMP\SECONDS(n) converts Unix epoch seconds (seconds since 1970-01-01 00:00:00 UTC) to a TIMESTAMP: TIMESTAMP\SECONDS(1795392000) is 2026-11-23 00:00:00 UTC.](https://mastheadata.com/bigquery/functions/timestamp-seconds.md)
*   [TIMESTAMP\SUBTIMESTAMP\SUB(ts, INTERVAL n part) subtracts an exact duration (MICROSECOND up to DAY) from a TIMESTAMP.](https://mastheadata.com/bigquery/functions/timestamp-sub.md)
*   [TIMESTAMP\TRUNCTIMESTAMP\TRUNC(ts, part\[, time\zone\]) rounds a TIMESTAMP down to the start of a minute, hour, day, week, month or year, in UTC or in the zone you pass.](https://mastheadata.com/bigquery/functions/timestamp-trunc.md)
*   [UNIX\MILLISUNIX\MILLIS(ts) returns the number of milliseconds since 1970-01-01 00:00:00 UTC as INT64, truncating microseconds.](https://mastheadata.com/bigquery/functions/unix-millis.md)
*   [UNIX\SECONDSUNIX\SECONDS(ts) returns the number of seconds since 1970-01-01 00:00:00 UTC as INT64, dropping fractions of a second.](https://mastheadata.com/bigquery/functions/unix-seconds.md)

## [String functions](https://mastheadata.com/bigquery/string-functions.md)

*   [CONCATCONCAT joins two or more values into one STRING (or BYTES): CONCAT(first\name, ' ', last\name).](https://mastheadata.com/bigquery/functions/concat.md)
*   [CONTAINS\SUBSTRCONTAINS\SUBSTR(expression, 'text') returns TRUE if the text appears anywhere in the value, ignoring case and Unicode differences.](https://mastheadata.com/bigquery/functions/contains-substr.md)
*   [ENDS\WITHENDS\WITH(value, suffix) returns TRUE if a string ends with suffix: ENDS\WITH(file\name, '.parquet') finds Parquet files.](https://mastheadata.com/bigquery/functions/ends-with.md)
*   [FORMATFORMAT(pattern, values...) builds a string with printf-style specifiers: FORMAT('%.2f', 3.14159) returns 3.14, FORMAT("%'d", 1234567) returns 1,234,567 and FORMAT('%s has %d orders', name, n) fills in text.](https://mastheadata.com/bigquery/functions/format.md)
*   [INITCAPINITCAP(value\[, delimiters\]) capitalizes the first letter of each word and lowercases the rest: INITCAP('mary-jane SMITH') returns Mary-Jane Smith.](https://mastheadata.com/bigquery/functions/initcap.md)
*   [INSTRINSTR(value, subvalue\[, position\[, occurrence\]\]) returns the 1-based position of a substring, optionally starting at a given position or finding the nth match.](https://mastheadata.com/bigquery/functions/instr.md)
*   [LEFTLEFT(value, length) returns the first length characters of a string (or bytes of a BYTES value): LEFT('4111111111111111', 4) returns 4111.](https://mastheadata.com/bigquery/functions/left.md)
*   [LENGTHLENGTH(value) returns the number of characters in a STRING, or the number of bytes in a BYTES value.](https://mastheadata.com/bigquery/functions/length.md)
*   [LOWERLOWER(value) converts a string to lowercase using Unicode case rules: LOWER('Ana@Example.COM') returns ana@example.com.](https://mastheadata.com/bigquery/functions/lower.md)
*   [LPADLPAD(value, length\[, pattern\]) pads a string on the left to a fixed length: LPAD('42', 6, '0') returns 000042.](https://mastheadata.com/bigquery/functions/lpad.md)
*   [LTRIMLTRIM(value\[, characters\]) removes leading whitespace, or every leading character found in the characters set: LTRIM('000123', '0') returns 123.](https://mastheadata.com/bigquery/functions/ltrim.md)
*   [REGEXP\CONTAINSREGEXP\CONTAINS(value, regex) returns TRUE if any part of the string matches an RE2 regular expression: REGEXP\CONTAINS(email, r'@example\\.(com|org)$').](https://mastheadata.com/bigquery/functions/regexp-contains.md)
*   [REGEXP\EXTRACTREGEXP\EXTRACT(value, regex) returns the first substring that matches an RE2 regular expression, or the capture group if the pattern has one: REGEXP\EXTRACT(note, r'\\d+') pulls the first number from text.](https://mastheadata.com/bigquery/functions/regexp-extract.md)
*   [REGEXP\EXTRACT\ALLREGEXP\EXTRACT\ALL(value, regex) returns an ARRAY of every non-overlapping match of an RE2 regular expression: REGEXP\EXTRACT\ALL(text, r'(\\w+)') returns all hashtags.](https://mastheadata.com/bigquery/functions/regexp-extract-all.md)
*   [REGEXP\REPLACEREGEXP\REPLACE(value, regex, replacement) replaces every match of an RE2 regular expression: REGEXP\REPLACE(phone, r'\[^0-9\]', '') keeps only digits.](https://mastheadata.com/bigquery/functions/regexp-replace.md)
*   [REPLACEREPLACE(value, from, to) replaces every occurrence of a substring: REPLACE(phone, ' ', '') removes all spaces.](https://mastheadata.com/bigquery/functions/replace.md)
*   [REVERSEREVERSE(value) returns a STRING with its characters in reverse order, or a BYTES value with its bytes reversed: REVERSE('stressed') returns desserts.](https://mastheadata.com/bigquery/functions/reverse.md)
*   [RIGHTRIGHT(value, length) returns the last length characters of a string (or bytes of a BYTES value): RIGHT('4111111111111111', 4) returns 1111.](https://mastheadata.com/bigquery/functions/right.md)
*   [RPADRPAD(value, length\[, pattern\]) pads a string on the right to a fixed length: RPAD('SKU', 8, '.') returns SKU.....](https://mastheadata.com/bigquery/functions/rpad.md)
*   [RTRIMRTRIM(value\[, characters\]) removes trailing whitespace, or every trailing character found in the characters set: RTRIM('12.500', '0') returns 12.5.](https://mastheadata.com/bigquery/functions/rtrim.md)
*   [SOUNDEXSOUNDEX(value) returns a four-character phonetic code (a letter and three digits) for how a word sounds in English: SOUNDEX('Smith') and SOUNDEX('Smyth') both return S530.](https://mastheadata.com/bigquery/functions/soundex.md)
*   [SPLITSPLIT breaks a string into an ARRAY<STRING> on a delimiter: SPLIT('a,b,c', ',') returns \[a, b, c\].](https://mastheadata.com/bigquery/functions/split.md)
*   [STARTS\WITHSTARTS\WITH(value, prefix) returns TRUE if a string begins with prefix: STARTS\WITH(table\name, 'tmp\') is TRUE for tmp\orders.](https://mastheadata.com/bigquery/functions/starts-with.md)
*   [STRPOSSTRPOS(value, subvalue) returns the 1-based position of the first occurrence of subvalue, or 0 if it isn't found: STRPOS('ana@example.com', '@') returns 4.](https://mastheadata.com/bigquery/functions/strpos.md)
*   [SUBSTRSUBSTR(value, position\[, length\]) returns part of a string: SUBSTR('INV-2026-00042', 5, 4) returns 2026.](https://mastheadata.com/bigquery/functions/substr.md)
*   [TRANSLATETRANSLATE(value, source\chars, target\chars) replaces each character in source\chars with the character at the same position in target\chars, and deletes source characters that have no counterpart: TRANSLATE(phone, '()- ', '') strips four characters in one call.](https://mastheadata.com/bigquery/functions/translate.md)
*   [TRIMTRIM(value\[, characters\]) removes leading and trailing whitespace from a string, or every leading and trailing character found in the characters set: TRIM('xxapplexx', 'x') returns apple.](https://mastheadata.com/bigquery/functions/trim.md)
*   [UPPERUPPER(value) converts a string to uppercase using Unicode case rules: UPPER('de-be') returns DE-BE.](https://mastheadata.com/bigquery/functions/upper.md)

## [Aggregate functions](https://mastheadata.com/bigquery/aggregate-functions.md)

*   [ANY\VALUEANY\VALUE returns the value of an expression from some row of the group, skipping NULLs.](https://mastheadata.com/bigquery/functions/any-value.md)
*   [APPROX\COUNT\DISTINCTAPPROX\COUNT\DISTINCT estimates the number of distinct non-NULL values with a HyperLogLog++ sketch.](https://mastheadata.com/bigquery/functions/approx-count-distinct.md)
*   [APPROX\QUANTILESAPPROX\QUANTILES(x, n) returns an array of n + 1 approximate quantile boundaries, from the minimum to the maximum.](https://mastheadata.com/bigquery/functions/approx-quantiles.md)
*   [APPROX\TOP\COUNTAPPROX\TOP\COUNT(x, n) returns the n most frequent values of x with their approximate counts, as an ARRAY of STRUCT<value, count>.](https://mastheadata.com/bigquery/functions/approx-top-count.md)
*   [ARRAY\AGGARRAY\AGG collects the values of a group into an ARRAY.](https://mastheadata.com/bigquery/functions/array-agg.md)
*   [AVGAVG returns the mean of the non-NULL values in a group.](https://mastheadata.com/bigquery/functions/avg.md)
*   [COUNTCOUNT counts rows: COUNT() counts every row, COUNT(column) skips NULLs, and COUNT(DISTINCT column) counts unique non-NULL values exactly.](https://mastheadata.com/bigquery/functions/count.md)
*   [COUNTIFCOUNTIF counts the rows where a BOOL condition is TRUE, for example COUNTIF(status = 'failed').](https://mastheadata.com/bigquery/functions/countif.md)
*   [LOGICAL\ANDLOGICAL\AND returns TRUE if a BOOL expression is TRUE for every non-NULL row of a group and FALSE if any row is FALSE.](https://mastheadata.com/bigquery/functions/logical-and.md)
*   [LOGICAL\ORLOGICAL\OR returns TRUE if a BOOL expression is TRUE for at least one row of a group and FALSE if every non-NULL row is FALSE.](https://mastheadata.com/bigquery/functions/logical-or.md)
*   [MAXMAX returns the largest non-NULL value in a group: the latest timestamp, the highest amount, the alphabetically last string.](https://mastheadata.com/bigquery/functions/max.md)
*   [MAX\BYMAX\BY(x, y) returns the value of x from the row where y is largest, such as the current status of each order: MAX\BY(status, updated\at).](https://mastheadata.com/bigquery/functions/max-by.md)
*   [MINMIN returns the smallest non-NULL value in a group: the earliest date, the lowest price, the alphabetically first string.](https://mastheadata.com/bigquery/functions/min.md)
*   [MIN\BYMIN\BY(x, y) returns the value of x from the row where y is smallest, such as each user's first marketing channel: MIN\BY(channel, visited\at).](https://mastheadata.com/bigquery/functions/min-by.md)
*   [STRING\AGGSTRING\AGG concatenates the non-NULL strings of a group into one value, separated by a delimiter (a comma by default).](https://mastheadata.com/bigquery/functions/string-agg.md)
*   [SUMSUM adds up the non-NULL values in a group and returns NULL, not 0, when there is nothing to add.](https://mastheadata.com/bigquery/functions/sum.md)

## [Window functions](https://mastheadata.com/bigquery/window-functions.md)

*   [DENSE\RANKDENSE\RANK() ranks rows within a window partition without gaps: tied rows share a rank and the next distinct value gets the next integer (1, 1, 2).](https://mastheadata.com/bigquery/functions/dense-rank.md)
*   [FIRST\VALUEFIRST\VALUE(x) returns x from the first row of the current window frame, such as each session's landing page or a series' starting value.](https://mastheadata.com/bigquery/functions/first-value.md)
*   [LAGLAG(value, offset, default) returns a value from an earlier row of the window partition, the previous row by default.](https://mastheadata.com/bigquery/functions/lag.md)
*   [LAST\VALUELAST\VALUE(x) returns x from the last row of the current window frame.](https://mastheadata.com/bigquery/functions/last-value.md)
*   [LEADLEAD(value, offset, default) returns a value from a later row of the window partition, the next row by default.](https://mastheadata.com/bigquery/functions/lead.md)
*   [NTILENTILE(n) splits the ordered rows of each window partition into n buckets of nearly equal size and returns the bucket number, from 1 to n.](https://mastheadata.com/bigquery/functions/ntile.md)
*   [PERCENT\RANKPERCENT\RANK() returns each row's relative rank in its window partition as a FLOAT64 from 0 to 1, computed as (rank - 1) / (rows - 1).](https://mastheadata.com/bigquery/functions/percent-rank.md)
*   [PERCENTILE\CONTPERCENTILE\CONT(x, p) OVER (...) returns the exact p-th percentile of x with linear interpolation, such as the median with p = 0.5.](https://mastheadata.com/bigquery/functions/percentile-cont.md)
*   [PERCENTILE\DISCPERCENTILE\DISC(x, p) OVER (...) returns the first value of x whose cumulative distribution reaches p, so the answer is always a value from the data.](https://mastheadata.com/bigquery/functions/percentile-disc.md)
*   [RANKRANK() assigns 1-based ranks within a window partition; tied rows share a rank and the next rank skips ahead (1, 1, 3).](https://mastheadata.com/bigquery/functions/rank.md)
*   [ROW\NUMBERROW\NUMBER() numbers the rows of each window partition 1, 2, 3 in ORDER BY order, with no ties and no gaps.](https://mastheadata.com/bigquery/functions/row-number.md)

## [Array functions](https://mastheadata.com/bigquery/array-functions.md)

*   [ARRAYARRAY(subquery) collects the rows a subquery returns into an array, one element per row, and returns an empty array (never NULL) when there are no rows.](https://mastheadata.com/bigquery/functions/array.md)
*   [ARRAY\CONCATARRAY\CONCAT(arr1, arr2, ...) joins two or more arrays of the same element type into one, keeping order and duplicates.](https://mastheadata.com/bigquery/functions/array-concat.md)
*   [ARRAY\FIRSTARRAY\FIRST(arr) returns the first element of an array, typed as the array's elements.](https://mastheadata.com/bigquery/functions/array-first.md)
*   [ARRAY\LASTARRAY\LAST(arr) returns the last element of an array without the ARRAY\LENGTH(arr) - 1 arithmetic.](https://mastheadata.com/bigquery/functions/array-last.md)
*   [ARRAY\LENGTHARRAY\LENGTH(arr) returns the number of elements in an array as INT64: 0 for an empty array and NULL for a NULL array.](https://mastheadata.com/bigquery/functions/array-length.md)
*   [ARRAY\REVERSEARRAY\REVERSE(arr) returns the same array with its elements in the opposite order.](https://mastheadata.com/bigquery/functions/array-reverse.md)
*   [ARRAY\SLICEARRAY\SLICE(arr, start\offset, end\offset) returns the elements between two zero-based offsets, both ends included.](https://mastheadata.com/bigquery/functions/array-slice.md)
*   [ARRAY\TO\STRINGARRAY\TO\STRING(arr, delimiter\[, null\text\]) joins the elements of a STRING or BYTES array into one string.](https://mastheadata.com/bigquery/functions/array-to-string.md)
*   [GENERATE\ARRAYGENERATE\ARRAY(start, end\[, step\]) returns an array of numbers from start to end, both inclusive, stepping by 1 or by step.](https://mastheadata.com/bigquery/functions/generate-array.md)
*   [OFFSET and SAFE\OFFSETarr\[OFFSET(n)\] returns the array element at zero-based position n and fails if n is out of range; arr\[SAFE\OFFSET(n)\] returns NULL instead.](https://mastheadata.com/bigquery/functions/offset.md)
*   [UNNESTUNNEST turns an array into a table with one row per element.](https://mastheadata.com/bigquery/functions/unnest.md)

## [JSON functions](https://mastheadata.com/bigquery/json-functions.md)

*   [JSON\EXTRACTJSON\EXTRACT(json, json\path) returns the JSON at a path (an object, an array or a quoted string) as JSON-formatted text, or as JSON for JSON input.](https://mastheadata.com/bigquery/functions/json-extract.md)
*   [JSON\EXTRACT\ARRAYJSON\EXTRACT\ARRAY(json\[, json\path\]) converts a JSON array into a SQL ARRAY with one element per item, as JSON-formatted strings (or JSON values for JSON input), ready for UNNEST.](https://mastheadata.com/bigquery/functions/json-extract-array.md)
*   [JSON\EXTRACT\SCALARJSON\EXTRACT\SCALAR(json, json\path) returns a scalar JSON value (string, number or boolean) as a SQL STRING without quotes, and NULL for objects, arrays and JSON null.](https://mastheadata.com/bigquery/functions/json-extract-scalar.md)
*   [JSON\KEYSJSON\KEYS(json\[, max\depth\]\[, mode => ...\]) returns the unique keys of a JSON value as a sorted ARRAY<STRING>, with nested keys as dotted paths such as user.id.](https://mastheadata.com/bigquery/functions/json-keys.md)
*   [JSON\QUERYJSON\QUERY(json, json\path) returns the JSON value at a path (object, array or scalar) as JSON text for STRING input or as JSON for JSON input, keeping quotes on strings.](https://mastheadata.com/bigquery/functions/json-query.md)
*   [JSON\QUERY\ARRAYJSON\QUERY\ARRAY(json\[, json\path\]) turns a JSON array into a SQL ARRAY with one element per item: ARRAY<JSON> for JSON input, JSON-formatted strings for STRING input.](https://mastheadata.com/bigquery/functions/json-query-array.md)
*   [JSON\REMOVEJSON\REMOVE(json, path\[, path ...\]) returns a copy of a JSON value with the data at each JSONPath removed, whether an object key or an array element.](https://mastheadata.com/bigquery/functions/json-remove.md)
*   [JSON\SETJSON\SET(json, path, value\[, path, value ...\]) returns a copy of a JSON value with values inserted or replaced at the given JSONPaths, creating missing parents along the way.](https://mastheadata.com/bigquery/functions/json-set.md)
*   [JSON\TYPEJSON\TYPE(json) returns the type of a JSON value as a string: object, array, string, number, boolean or null.](https://mastheadata.com/bigquery/functions/json-type.md)
*   [JSON\VALUEJSON\VALUE(json\[, json\path\]) extracts a scalar (string, number or boolean) from JSON and returns it as a SQL STRING without quotes; objects, arrays and JSON null return NULL.](https://mastheadata.com/bigquery/functions/json-value.md)
*   [JSON\VALUE\ARRAYJSON\VALUE\ARRAY(json\[, json\path\]) extracts a JSON array of scalars as an ARRAY<STRING> with the quotes removed.](https://mastheadata.com/bigquery/functions/json-value-array.md)
*   [PARSE\JSONPARSE\JSON(json\string) converts JSON-formatted text into a value of the JSON type, validating it on the way.](https://mastheadata.com/bigquery/functions/parse-json.md)
*   [TO\JSONTO\JSON(value) converts a SQL value (scalar, struct, array or whole row) into a value of the JSON type.](https://mastheadata.com/bigquery/functions/to-json.md)
*   [TO\JSON\STRINGTO\JSON\STRING(value\[, pretty\print\]) serializes any SQL value, from a scalar to a struct, an array or a whole row, into JSON text.](https://mastheadata.com/bigquery/functions/to-json-string.md)

## [Conversion functions](https://mastheadata.com/bigquery/conversion-functions.md)

*   [CASTCAST(expression AS type) converts a value to another data type, such as STRING to INT64 or TIMESTAMP to DATE, and fails the whole query if any value can't be converted.](https://mastheadata.com/bigquery/functions/cast.md)
*   [PARSE\NUMERICPARSE\NUMERIC(string) converts a STRING to NUMERIC and, unlike CAST, accepts thousands separators, spaces and a trailing minus sign, as in '1,234.50' or '75.10-'.](https://mastheadata.com/bigquery/functions/parse-numeric.md)
*   [SAFE\CASTSAFE\CAST(expression AS type) works like CAST but returns NULL instead of failing when a value can't be converted.](https://mastheadata.com/bigquery/functions/safe-cast.md)

## [Conditional expressions](https://mastheadata.com/bigquery/conditional-expressions.md)

*   [CASECASE returns the result of the first WHEN branch that matches.](https://mastheadata.com/bigquery/functions/case.md)
*   [COALESCECOALESCE(expr1, expr2, ...) returns the first argument that is not NULL, or NULL if every argument is NULL.](https://mastheadata.com/bigquery/functions/coalesce.md)
*   [IFIF(condition, true\result, else\result) returns true\result when the condition is TRUE and else\result when it is FALSE or NULL.](https://mastheadata.com/bigquery/functions/if.md)
*   [IFNULLIFNULL(expr, null\result) returns expr, or null\result when expr is NULL.](https://mastheadata.com/bigquery/functions/ifnull.md)
*   [NULLIFNULLIF(expr, expr\to\match) returns NULL when the two values are equal and expr otherwise.](https://mastheadata.com/bigquery/functions/nullif.md)

## [Mathematical functions](https://mastheadata.com/bigquery/math-functions.md)

*   [ABSABS(x) returns the absolute value of x with the same type as the input: ABS(-42) is 42.](https://mastheadata.com/bigquery/functions/abs.md)
*   [CEIL / CEILINGCEIL(x) returns the smallest whole number that is not less than x: CEIL(2.1) is 3.0 and CEIL(-2.9) is -2.0.](https://mastheadata.com/bigquery/functions/ceil.md)
*   [DIVDIV(x, y) divides two integers and drops the remainder: DIV(7, 2) is 3, while 7 / 2 is 3.5.](https://mastheadata.com/bigquery/functions/div.md)
*   [FLOORFLOOR(x) returns the largest whole number that is not greater than x: FLOOR(2.9) is 2.0 and FLOOR(-2.1) is -3.0.](https://mastheadata.com/bigquery/functions/floor.md)
*   [GREATESTGREATEST(x1, x2, ...) returns the largest of its arguments within a single row, for example the latest of several date columns.](https://mastheadata.com/bigquery/functions/greatest.md)
*   [LEASTLEAST(x1, x2, ...) returns the smallest of its arguments within a single row, such as the earliest of several dates or a value capped at a limit.](https://mastheadata.com/bigquery/functions/least.md)
*   [LOG, LN, LOG10LOG(x) returns the natural logarithm of x (the same as LN), LOG(x, base) uses any base, and LOG10(x) uses base 10.](https://mastheadata.com/bigquery/functions/log.md)
*   [MODMOD(x, y) returns the remainder of x divided by y, with the sign of x: MOD(25, 7) is 4 and MOD(-25, 7) is -4.](https://mastheadata.com/bigquery/functions/mod.md)
*   [POW / POWERPOW(x, y) raises x to the power y, and POWER is a synonym: POW(2, 10) returns 1024.0.](https://mastheadata.com/bigquery/functions/pow.md)
*   [RANDRAND() returns a pseudo-random FLOAT64 from 0 (inclusive) to 1 (exclusive), different for every row and every run.](https://mastheadata.com/bigquery/functions/rand.md)
*   [RANGE\BUCKETRANGE\BUCKET(point, boundaries) returns the 0-based index of the bucket a value falls into, given a sorted array of boundaries: RANGE\BUCKET(25, \[10, 20, 30\]) is 2.](https://mastheadata.com/bigquery/functions/range-bucket.md)
*   [ROUNDROUND(x, n) rounds x to n decimal places, with halfway cases going away from zero: ROUND(19.987, 2) returns 19.99.](https://mastheadata.com/bigquery/functions/round.md)
*   [SAFE\DIVIDESAFE\DIVIDE(x, y) divides x by y like the / operator but returns NULL instead of failing when y is 0 or the division overflows.](https://mastheadata.com/bigquery/functions/safe-divide.md)
*   [SQRTSQRT(x) returns the square root of x: SQRT(16) is 4.0.](https://mastheadata.com/bigquery/functions/sqrt.md)
*   [TRUNCTRUNC(x, n) cuts x to n decimal places by rounding toward zero: TRUNC(2.789, 2) is 2.78 and TRUNC(-2.789, 2) is -2.78.](https://mastheadata.com/bigquery/functions/trunc.md)

## [Hash and utility functions](https://mastheadata.com/bigquery/utility-functions.md)

*   [ERRORERROR(message) stops the query with your own error message.](https://mastheadata.com/bigquery/functions/error.md)
*   [FARM\FINGERPRINTFARM\FINGERPRINT(value) hashes a STRING or BYTES value to a signed INT64 that never changes between runs.](https://mastheadata.com/bigquery/functions/farm-fingerprint.md)
*   [GENERATE\UUIDGENERATE\UUID() returns a random version 4 UUID as a lowercase 36-character STRING, such as 3f2b8c1e-9d4a-4e7b-8c21-5a6f0d9e7b13.](https://mastheadata.com/bigquery/functions/generate-uuid.md)
*   [MD5MD5(input) returns the 16-byte MD5 hash of a STRING or BYTES value as BYTES, which the console shows in base64.](https://mastheadata.com/bigquery/functions/md5.md)
*   [SESSION\USERSESSION\USER() returns the email address of the user or service account running the query, or a principal identifier for third-party identities.](https://mastheadata.com/bigquery/functions/session-user.md)
*   [SHA256SHA256(input) returns the 32-byte SHA-256 hash of a STRING or BYTES value as BYTES.](https://mastheadata.com/bigquery/functions/sha256.md)
---

## Other pages in BigQuery Reference

> For the full index of this section, see [BigQuery Reference](https://mastheadata.com/llms/llms-bigquery-reference.txt).

- [BigQuery Aggregate Functions: COUNT, SUM, STRING_AGG and More | Masthead](https://mastheadata.com/bigquery/aggregate-functions.md): Aggregate functions collapse many rows into one value per group. 16 aggregate functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Array Functions: UNNEST, ARRAY_AGG and More | Masthead](https://mastheadata.com/bigquery/array-functions.md): ARRAY is a first-class type in BigQuery: nested and repeated fields are how BigQuery avoids joins. 11 array functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conditional Expressions: CASE, IF, COALESCE, IFNULL | Masthead](https://mastheadata.com/bigquery/conditional-expressions.md): Conditional expressions choose a value based on a condition or on NULLs. 5 conditional expressions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conversion Functions: CAST and SAFE_CAST | Masthead](https://mastheadata.com/bigquery/conversion-functions.md): Conversion functions change a value from one type to another. 3 conversion functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Cost Queries: SQL to Find and Cut BigQuery Spend | Masthead](https://mastheadata.com/bigquery/cost-queries.md): 20 ready-to-run SQL queries for BigQuery cost: the most expensive queries, cost by user, project, label, dbt model and dashboard, slot usage, storage cost, unused and dead-end tables.
- [BigQuery Date Functions: Syntax, Examples and Gotchas | Masthead](https://mastheadata.com/bigquery/date-functions.md): DATE functions in BigQuery (GoogleSQL) build, shift, truncate, compare and format calendar dates. 14 date functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Datetime Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/datetime-functions.md): DATETIME is a civil date and time with no time zone: what a wall clock shows. 8 datetime functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DDL: CREATE TABLE, Partitioning, Clustering and Views | Masthead](https://mastheadata.com/bigquery/ddl.md): Data definition language creates and changes tables, views, materialized views and functions. 8 DDL statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DML: INSERT, UPDATE, DELETE and MERGE | Masthead](https://mastheadata.com/bigquery/dml.md): Data manipulation language changes table rows. 5 DML statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Error Messages: Causes and Fixes | Masthead](https://mastheadata.com/bigquery/errors.md): 51 BigQuery error messages explained: what each one means, why it happens and how to fix it, from "Resources exceeded" and quota errors to permissions, DML conflicts and failed loads.
- [GA4 BigQuery Export: SQL Queries for Sessions, Users, Events and Revenue | Masthead](https://mastheadata.com/bigquery/ga4.md): 28 SQL recipes for the GA4 BigQuery export: unnest event_params, sessions, users, traffic sources, engagement, ecommerce, retention, and how to keep the queries cheap. Every one runs on Google's public GA4 sample.
- [BigQuery INFORMATION_SCHEMA: Jobs, Tables, Storage and Costs | Masthead](https://mastheadata.com/bigquery/information-schema-views.md): INFORMATION_SCHEMA views expose BigQuery metadata as tables you can query: jobs, slots, bytes billed, tables, columns and storage. 2 INFORMATION_SCHEMA with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery JSON Functions: JSON_VALUE, JSON_QUERY and More | Masthead](https://mastheadata.com/bigquery/json-functions.md): BigQuery reads JSON stored as STRING or as the native JSON type. 14 JSON functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Math Functions: ROUND, SAFE_DIVIDE, MOD and More | Masthead](https://mastheadata.com/bigquery/math-functions.md): Mathematical functions round, divide, bucket and transform numbers. 15 mathematical functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Pricing Calculator: On-Demand vs Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing-calculator.md): Free BigQuery pricing calculator: compare on-demand ($6.25 per TiB) with Standard, Enterprise and Enterprise Plus editions per slot-hour, and logical vs physical storage billing, using your own numbers from INFORMATION_SCHEMA.
- [BigQuery Pricing Explained (2026): On-Demand, Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing.md): BigQuery bills compute and storage separately. Compute is on-demand at $6.25 per TiB scanned (the first 1 TiB a month is free) or capacity-based with editions from $0.04 per slot-hour. Storage costs $0.02 per GiB a month for active data and $0.01 for data unchanged for 90 days (US, logical).
- [BigQuery Public Datasets: Sizes, Tables and What They Cost to Query | Masthead](https://mastheadata.com/bigquery/public-datasets.md): 40 BigQuery public datasets with their real table sizes and what querying them costs: GitHub, Stack Overflow, Wikipedia, Google Trends, GA4 sample, NOAA weather, taxi trips, crypto and more, with cheap example queries.
- [BigQuery Query Syntax: QUALIFY, PIVOT, CTEs, JOINs and More | Masthead](https://mastheadata.com/bigquery/query-syntax.md): The clauses that shape a GoogleSQL query in BigQuery: CTEs, joins, set operations, PIVOT, QUALIFY and SELECT * EXCEPT. 11 query syntax with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Scripting: Variables, Loops, Dynamic SQL, LOAD and EXPORT | Masthead](https://mastheadata.com/bigquery/scripting.md): Multi-statement queries let you declare variables, loop, branch and build SQL at run time, and LOAD DATA and EXPORT DATA move data in and out of BigQuery from SQL.. 5 scripting and data movement with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery SQL Syntax: Statements, Clauses, DDL and DML | Masthead](https://mastheadata.com/bigquery/sql.md): BigQuery SQL syntax reference: QUALIFY, PIVOT, MERGE, CTEs, partitioned and clustered tables, scripting and INFORMATION_SCHEMA. 31 statements and clauses with examples and cost notes.
- [BigQuery String Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/string-functions.md): String functions in BigQuery split, search, replace, pad and format STRING values, and most also accept BYTES. 28 string functions with syntax, runnable examples, common mistakes and cost notes.
- [The Bill Is Right: Guess Your BigQuery Bill | Masthead](https://mastheadata.com/bigquery/the-bill-is-right.md): A free game show for data teams. Guess the monthly BigQuery bill from real Google Cloud list prices: three tries, land within 15% to win.
- [BigQuery Timestamp Functions: Syntax, Time Zones and Examples | Masthead](https://mastheadata.com/bigquery/timestamp-functions.md): TIMESTAMP is an absolute point in time with microsecond precision, stored in UTC. 12 timestamp functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Hash and Utility Functions: FARM_FINGERPRINT, UUID, SHA256 | Masthead](https://mastheadata.com/bigquery/utility-functions.md): Hashing, unique IDs and a few utility functions that show up in pipelines: deterministic sampling, surrogate keys, deduplication and raising your own errors.. 6 hash and utility functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Window Functions: ROW_NUMBER, LAG, RANK and More | Masthead](https://mastheadata.com/bigquery/window-functions.md): Window (analytic) functions compute a value for every row from a window of related rows, defined with OVER (PARTITION BY ... 11 window functions with syntax, runnable examples, common mistakes and cost notes.
