Utility functions

GoogleSQL for BigQuery supports the following utility functions.

Function list

NameSummary
GENERATE_UUID Produces a random universally unique identifier (UUID) as aSTRING value.
TYPEOF Gets the name of the data type for an expression.

GENERATE_UUID

GENERATE_UUID()

Description

Returns a random universally unique identifier (UUID) as aSTRING.The returnedSTRING consists of 32 hexadecimaldigits in five groups separated by hyphens in the form 8-4-4-4-12. Thehexadecimal digits represent 122 random bits and 6 fixed bits, in compliancewithRFC 4122 section 4.4.The returnedSTRING is lowercase.

Return Data Type

STRING

Example

The following query generates a random UUID.

SELECTGENERATE_UUID()ASuuid;/*--------------------------------------+ | uuid                                 | +--------------------------------------+ | 4192bff0-e1e0-43ce-a4db-912808c32493 | +--------------------------------------*/

TYPEOF

TYPEOF(expression)

Description

Takes an expression and gets the name of the data type for thatexpression.

Return type

STRING

Examples

The following example produces the name of the data type for the expressionpassed into theTYPEOF function. WhenNULL is passed in, thesupertype,INT64, is produced.

SELECTTYPEOF(NULL)ASA,TYPEOF('hello')ASB,TYPEOF(12+1)ASC,TYPEOF(4.7)ASD/*-------+--------+-------+--------+ | A     | B      | C     | D      | +-------+--------+-------+--------+ | INT64 | STRING | INT64 | FLOAT64 | +-------+--------+-------+--------*/

The following example produces the name of the data type for fieldy in astruct.

SELECTTYPEOF(STRUCT<xINT64,ySTRING>(25,'apples'))ASstruct_type,TYPEOF(STRUCT<xINT64,ySTRING>(25,'apples').y)ASfield_type;/*---------------------------+------------+ | struct_type               | field_type | +---------------------------+------------+ | STRUCT<x INT64, y STRING> | STRING     | +---------------------------+------------*/

The following example produces the name of the data type for elements in anarray.

SELECTTYPEOF(ARRAY<INT64>[25,32])ASarray_type,TYPEOF(ARRAY<INT64>[25,32][0])ASelement_type;/*--------------+--------------+ | array_type   | element_type | +--------------+--------------+ | ARRAY<INT64> | INT64        | +--------------+--------------*/

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-24 UTC.