Everything you need to know about SQL Data Types in BigQuery. BigQuery supports several data types, some are quite standard, others are more complex.
BigQuery supports several data types, some of which are standard (e.g. STRING, INT64), and others that are more complex (e.g. ARRAY, STRUCT).
In general though they easily fall into the following categories or Supertypes:
SELECT cast('12' as INT64) intNUMERIC & BIGNUMERICIntegers are always whole numbers; they have no decimals or fractional components.
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807INT64sBOOL, INT64, NUMERIC, BIGNUMERIC, FLOAT64, STRINGNUMERIC, BIGNUMERIC, FLOAT64Floating point numbers are approximate numeric values with decimal/fractional components.
| float |
|---|
| 12.44 |
NaN and +/-infFLOAT64sINT64, NUMERIC, BIGNUMERIC, FLOAT64, STRINGNUMERIC and BIGNUMERICDecimals are numeric values with fixed precision and scale. Precision = the number of digits, and scale = the number of these digits appear after the decimal point.
| numeric | bignumeric |
|---|---|
| 1240000000000000000 | 124000000000000000000000000000000000000 |
38-9.9999999999999999999999999999999999999E+299.9999999999999999999999999999999999999E+2976.76 (the 77th digit is partial)-5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+385.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38NUMERICSs and BIGNUMERICsINT64, NUMERIC, BIGNUMERIC, FLOAT64, STRINGBIGNUMERIC, FLOAT64Booleans are True or False
| boolean |
|---|
| true |
BOOLsINT64, BOOL, STRINGVariable-length text (unicode) data
STRINGsBOOL, INT64, NUMERIC, BIGNUMERIC, FLOAT64,STRING, BYTES, DATE, DATETIME, TIME, TIMESTAMPVariable-length binary data
| bytes |
|---|
| 104,105 |
BYTEsSTRING, BYTESRepresents a logical calendar date (e.g. 2020-01-03)
| date |
|---|
| 2020-08-24 |
0001-01-01 to 9999-12-31.YYYY:[M]M:[D]D or 4-digit year : one or two digit month : one or two digit dayDATEsSTRING, DATE, DATETIME, TIMESTAMPRepresents a logical calendar datetime (e.g. 2020-01-03 12:04:22)
| datetime |
|---|
| 2020-08-24T13:11:05 |
0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999YYYY-[M]M-[D]D[( |T)[H]H:[M]M:[S]S[.DDDDDD]]YYYY: Four-digit year[M]M: One or two digit month[D]D: One or two digit day( |T): A space or a `T` separator[H]H: One or two digit hour (valid values from 00 to 23)[M]M: One or two digit minutes (valid values from 00 to 59)[S]S: One or two digit seconds (valid values from 00 to 59)[.DDDDDD]: Up to six fractional digits (microsecond precision)DATETIMEsSTRING, DATE, DATETIME, TIMESTAMP, TIMERepresents an absolute point in time (e.g. 2020-01-03 12:04:22 UTC)
| timestamp |
|---|
| 2020-08-24T08:11:05.000Z |
0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999 UTCYYYY-[M]M-[D]D[( |T)[H]H:[M]M:[S]S[.DDDDDD]][time zone]YYYY: Four-digit year[M]M: One or two digit month[D]D: One or two digit day( |T): A space or a `T` separator[H]H: One or two digit hour (valid values from 00 to 23)[M]M: One or two digit minutes (valid values from 00 to 59)[S]S: One or two digit seconds (valid values from 00 to 59)[.DDDDDD]: Up to six fractional digits (microsecond precision)[time zone]: String representing the time zone. When a time zone is not explicitly specified, the default time zone, UTC, is used. See the time zones section for details.TIMESTAMPsSTRING, DATE, DATETIME, TIMESTAMP, TIMERepresents a time as might be displayed on a watch (e.g. 10:14:00)
| time |
|---|
| 13:11:05 |
00:00:00 to 23:59:59.99999.[H]H:[M]M:[S]S[.DDDDDD][H]H: One or two digit hour (valid values from 00 to 23)[M]M: One or two digit minutes (valid values from 00 to 59)[S]S: One or two digit seconds (valid values from 00 to 59)[.DDDDDD]: Up to six fractional digits (microsecond precision)TIME'sSTRING, TIMEOrdered list of 0+ elements of non-ARRAY type
| array_ |
|---|
| 1,2,3 |
NULL elements, although such ARRAYs can be used inside the query.NULL into an empty ARRAY in the query result, although inside the query NULL and empty ARRAYs are two distinct values.ARRAY, where the type of elements in the ARRAY are contained inside the < and >. ARRAY = Simple ARRAY of integers.ARRAY> : ARRAY of STRUCTs that contain 2 integers.ARRAYsARRAYContainer of ordered fields, each with a type (required) and field name (optional).
| struct_ |
|---|
| [object Object] |
STRUCT, where the type of elements in the STRUCT are contained inside the < and >. STRUCT = Simple STRUCT of integers.STRUCT> : A STRUCT with a nested STRUCT named x inside it. The STRUCT x has two fields, y and z, both of which are 64-bit integers.(expr1, expr2 [, ... ])(x, x+y)), the data types are derived from the column types!= or <>)STRUCTsSTRUCTA collection of points, lines, and polygons, which is represented as a point set or a subset of the surface of the Earth.
| geography |
|---|
| POINT(1 1) |
GEOGRAPHY is the result of, or an argument to, a Geography Function.ST_EqualsGEOGRAPHYsCoercion is an implicit type conversion, which BigQuery performs automatically between certain data types.
SELECT cast('12.44' as FLOAT64) floatSELECT cast('12.4E17' as NUMERIC) numeric, cast('12.4E37' as BIGNUMERIC) bignumericSELECT CAST('True' AS BOOL) AS booleanSELECT CAST(123 AS STRING) AS stringSELECT cast('hi' as BYTES) bytesSELECT CAST('2020-08-24' AS DATE) AS dateSELECT CAST('2020-08-24 13:11:05' AS DATETIME) AS datetimeSELECT CAST('2020-08-24 13:11:05+5:00' AS TIMESTAMP) AS timestampSELECT CAST('13:11:05' AS TIME) AS timeSELECT CAST([1,2,3] as ARRAY) array_SELECT CAST((1,'a') as STRUCT) struct_SELECT CAST(ST_GEOGFROMTEXT('POINT(1 1)') as GEOGRAPHY) geography