Data Types
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:
NUMERIC
&BIGNUMERIC
INT64
Integers are always whole numbers; they have no decimals or fractional components.
SELECT cast('12' as INT64) int
About
-9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
Properties
INT64
sBOOL
, INT64
, NUMERIC
, BIGNUMERIC
, FLOAT64
, STRING
NUMERIC
, BIGNUMERIC
, FLOAT64
FLOAT64
Floating point numbers are approximate numeric values with decimal/fractional components.
SELECT cast('12.44' as FLOAT64) float
About
NaN
and +/-inf
NULL
NaN
-inf
- Negative numbers
- 0
- Positive numbers
+inf
Properties
FLOAT64
sINT64
, NUMERIC
, BIGNUMERIC
, FLOAT64
, STRING
NUMERIC
and BIGNUMERIC
Decimals 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.
SELECT cast('12.4E17' as NUMERIC) numeric, cast('12.4E37' as BIGNUMERIC) bignumeric
About
- Precision:
38
- Scale:
0
- Min :
-9.9999999999999999999999999999999999999E+29
- Max:
9.9999999999999999999999999999999999999E+29
- Precision:
76.76
(the 77th digit is partial)
- Scale:
38
- Min:
-5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38
- Max:
5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38
Properties
NUMERICS
s and BIGNUMERIC
sINT64
, NUMERIC
, BIGNUMERIC
, FLOAT64
, STRING
BIGNUMERIC
, FLOAT64
BOOL
Booleans are True or False
SELECT CAST('True' AS BOOL) AS boolean
About
- NULL
- FALSE
- TRUE
Properties
BOOL
sINT64
, BOOL
, STRING
STRING
Variable-length text (unicode) data
SELECT CAST(123 AS STRING) AS string
About
Properties
STRING
sBOOL
, INT64
, NUMERIC
, BIGNUMERIC
, FLOAT64
,STRING
, BYTES
, DATE
, DATETIME
, TIME
, TIMESTAMP
BYTES
Variable-length binary data
SELECT cast('hi' as BYTES) bytes
About
Properties
BYTE
sSTRING
, BYTES
DATE
Represents a logical calendar date (e.g. 2020-01-03)
SELECT CAST('2020-08-24' AS DATE) AS date
About
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 day
Properties
DATE
sSTRING
, DATE
, DATETIME
, TIMESTAMP
DATETIME
Represents a logical calendar datetime (e.g. 2020-01-03 12:04:22)
SELECT CAST('2020-08-24 13:11:05' AS DATETIME) AS datetime
About
0001-01-01 00:00:00
to 9999-12-31 23:59:59.999999
YYYY-[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)
Properties
DATETIME
sSTRING
, DATE
, DATETIME
, TIMESTAMP
, TIME
TIMESTAMP
Represents an absolute point in time (e.g. 2020-01-03 12:04:22 UTC)
SELECT CAST('2020-08-24 13:11:05+5:00' AS TIMESTAMP) AS timestamp
About
0001-01-01 00:00:00
to 9999-12-31 23:59:59.999999 UTC
YYYY-[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.
Properties
TIMESTAMP
sSTRING
, DATE
, DATETIME
, TIMESTAMP
, TIME
TIME
Represents a time as might be displayed on a watch (e.g. 10:14:00)
SELECT CAST('13:11:05' AS TIME) AS time
About
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)
Properties
TIME
'sSTRING
, TIME
ARRAY
Ordered list of 0+ elements of non-ARRAY type
SELECT CAST([1,2,3] as ARRAY) array_
About
- BigQuery raises an error if a query result contains ARRAYs which contain
NULL
elements, although such ARRAYs can be used inside the query.
- BigQuery translates
NULL
into an empty ARRAY in the query result, although inside the queryNULL
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.
Properties
ARRAY
sARRAY
STRUCT
Container of ordered fields, each with a type (required) and field name (optional).
SELECT CAST((1,'a') as STRUCT) struct_
About
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 namedx
inside it. The STRUCTx
has two fields,y
andz
, both of which are 64-bit integers.
(expr1, expr2 [, ... ])
- There must be at least 2 expressions specified, otherwise it's indistinguishable from the element that is defined
- If column names are used(e.g.
(x, x+y)
), the data types are derived from the column types
- You can use any of the following operators:
- Equal (
=
)
- Not Equal (
!=
or<>
)
- [
NOT
]IN
- These compare pairwise in ordinal order so you cannot be sure that you're comparing the same fields. To do that, compare the fields directly.
Properties
STRUCT
sSTRUCT
GEOGRAPHY
A collection of points, lines, and polygons, which is represented as a point set or a subset of the surface of the Earth.
SELECT CAST(ST_GEOGFROMTEXT('POINT(1 1)') as GEOGRAPHY) geography
About
GEOGRAPHY
is the result of, or an argument to, a Geography Function.ST_Equals
Properties
GEOGRAPHY
sCoercion
Coercion is an implicit type conversion, which BigQuery performs automatically between certain data types.