# Data types This page provides an overview of all GoogleSQL data types, including information about their value domains. For information on data type literals and constructors, see [Lexical Structure and Syntax][lexical-literals]. ## Data type list
| Name | Summary |
|---|---|
| Array type |
An ordered list of zero or more elements of non-array values. SQL type name: ARRAY
|
| Boolean type |
A value that can be either TRUE or FALSE.SQL type name: BOOLSQL aliases: BOOLEAN
|
| Bytes type |
Variable-length binary data. SQL type name: BYTES
|
| Date type |
A Gregorian calendar date, independent of time zone. SQL type name: DATE
|
| Datetime type |
A Gregorian date and a time, as they might be displayed on a watch,
independent of time zone. SQL type name: DATETIME
|
| Enum type |
Named type that enumerates a list of possible values. SQL type name: ENUM
|
| Geography type |
A collection of points, linestrings, and polygons, which is represented as a
point set, or a subset of the surface of the Earth. SQL type name: GEOGRAPHY
|
| Graph element type |
An element in a property graph. Can be a GRAPH_NODE or
GRAPH_EDGE.SQL type name: GRAPH_ELEMENT
|
| Interval type |
A duration of time, without referring to any specific point in time. SQL type name: INTERVAL
|
| JSON type |
Represents JSON, a lightweight data-interchange format. SQL type name: JSON
|
| Measure type |
An aggregate calculation that doesn’t overcount. SQL type name: MEASURE
|
| Numeric types |
A numeric value. Several types are supported.
A 32-bit integer.
An unsigned 32-bit integer.
A 64-bit integer.
An unsigned 64-bit integer.
A decimal value with precision of 38 digits.
A decimal value with precision of approximately 76.8 digits (the 77th digit is partial).
An approximate single precision numeric value.
An approximate double precision numeric value. |
| Protocol buffer type |
A protocol buffer. SQL type name: PROTO
|
| Range type |
Contiguous range between two dates, datetimes, or timestamps. SQL type name: RANGE
|
| String type |
Variable-length character data. SQL type name: STRING
|
| Struct type |
Container of ordered fields. SQL type name: STRUCT
|
| Time type |
A time of day, as might be displayed on a clock, independent of a specific
date and time zone. SQL type name: TIME
|
| Timestamp type |
A timestamp value represents an absolute point in time,
independent of any time zone or convention such as
daylight saving time (DST). SQL type name: TIMESTAMP
|
| UUID type | A universally unique identifier (UUID) represented as a 128-bit number. |
| Name | Description |
|---|---|
ARRAY |
Ordered list of zero or more elements of any non-array type. |
| Type Declaration | Meaning |
|---|---|
ARRAY<INT64>
|
Simple array of 64-bit integers. |
ARRAY<STRUCT<INT64, INT64>>
|
An array of structs, each of which contains two 64-bit integers. |
ARRAY<ARRAY<INT64>>
(not supported) |
This is an invalid type declaration which is included here just in case you came looking for how to create a multi-level array. Arrays can't contain arrays directly. Instead see the next example. |
ARRAY<STRUCT<ARRAY<INT64>>>
|
An array of arrays of 64-bit integers. Notice that there is a struct between the two arrays because arrays can't hold other arrays directly. |
| Name | Description |
|---|---|
BOOLBOOLEAN
|
Boolean values are represented by the keywords TRUE and
FALSE (case-insensitive). |
| Name | Description |
|---|---|
BYTES |
Variable-length binary data. |
| Name | Range |
|---|---|
DATE |
0001-01-01 to 9999-12-31. |
| Name | Range |
|---|---|
DATETIME |
0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999999 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999 |
YYYY: Four-digit year.
+ [M]M: One or two digit month.
+ [D]D: One or two digit day.
+ { |T|t}: A space or a `T` or `t` separator. The `T` and `t`
separators are flags for time.
+ [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 60).
+ [.F]: Up to nine fractional
digits (nanosecond precision).
To learn more about the literal representation of a datetime type,
see [Datetime literals][datetime-literals].
[timestamp-type]: #timestamp_type
[datetime-literals]: https://github.com/google/googlesql/blob/master/docs/lexical.md#datetime_literals
## Enum type
| Name | Description |
|---|---|
ENUM |
Named type that maps string constants to INT32 constants. |
| Name | Description |
|---|---|
GEOGRAPHY |
A collection of points, linestrings, and polygons, which is represented as a point set, or a subset of the surface of the Earth. |
| Geography object | Description |
|---|---|
Point |
A single location in coordinate space known as a point. A point has an x-coordinate value and a y-coordinate value, where the x-coordinate is longitude and the y-coordinate is latitude of the point on the WGS84 reference ellipsoid. Syntax: POINT(x_coordinate y_coordinate)Examples: POINT(32 210) POINT EMPTY |
LineString |
Represents a linestring, which is a one-dimensional geometric object, with a sequence of points and geodesic edges between them. Syntax: LINESTRING(point[, ...])Examples: LINESTRING(1 1, 2 1, 3.1 2.88, 3 -3) LINESTRING EMPTY |
Polygon |
A polygon, which is represented as a planar surface defined by 1 exterior boundary and 0 or more interior boundaries. Each interior boundary defines a hole in the polygon. The boundary loops of polygons are oriented so that if you traverse the boundary vertices in order, the interior of the polygon is on the left. Syntax: POLYGON(interior_ring[, ...]) interior_ring: (point[, ...])Examples: POLYGON((0 0, 2 2, 2 0, 0 0), (2 2, 3 4, 2 4, 2 2)) POLYGON EMPTY |
MultiPoint |
A collection of points. Syntax: MULTIPOINT(point[, ...])Examples: MULTIPOINT(0 32, 123 9, 48 67) MULTIPOINT EMPTY |
MultiLineString |
Represents a multilinestring, which is a collection of linestrings. Syntax: MULTILINESTRING((linestring)[, ...])Examples: MULTILINESTRING((2 2, 3 4), (5 6, 7 7)) MULTILINESTRING EMPTY |
MultiPolygon |
Represents a multipolygon, which is a collection of polygons. Syntax: MULTIPOLYGON((polygon)[, ...])Examples: MULTIPOLYGON(((0 -1, 1 0, 1 1, 0 -1)), ((0 0, 2 2, 3 0, 0 0), (2 2, 3 4, 2 4, 1 9))) MULTIPOLYGON EMPTY |
GeometryCollection |
Represents a geometry collection with elements of different dimensions or an empty geography. Syntax: GEOMETRYCOLLECTION(geography_object[, ...])Examples: GEOMETRYCOLLECTION(MULTIPOINT(-1 2, 0 12), LINESTRING(-2 4, 0 6)) GEOMETRYCOLLECTION EMPTY |
| Name | Description |
|---|---|
GRAPH_ELEMENT |
An element in a property graph. |
| Name | Range |
|---|---|
INTERVAL |
-10000-0 -3660000 -87840000:0:0 to 10000-0 3660000 87840000:0:0 |
| Datetime part string | Datetime parts | Example |
|---|---|---|
Y-M |
YEAR TO MONTH |
INTERVAL '2-11' YEAR TO MONTH |
Y-M D |
YEAR TO DAY |
INTERVAL '2-11 28' YEAR TO DAY |
Y-M D H |
YEAR TO HOUR |
INTERVAL '2-11 28 16' YEAR TO HOUR |
Y-M D H:M |
YEAR TO MINUTE |
INTERVAL '2-11 28 16:15' YEAR TO MINUTE |
Y-M D H:M:S |
YEAR TO SECOND |
INTERVAL '2-11 28 16:15:14' YEAR TO SECOND |
M D |
MONTH TO DAY |
INTERVAL '11 28' MONTH TO DAY |
M D H |
MONTH TO HOUR |
INTERVAL '11 28 16' MONTH TO HOUR |
M D H:M |
MONTH TO MINUTE |
INTERVAL '11 28 16:15' MONTH TO MINUTE |
M D H:M:S |
MONTH TO SECOND |
INTERVAL '11 28 16:15:14' MONTH TO SECOND |
D H |
DAY TO HOUR |
INTERVAL '28 16' DAY TO HOUR |
D H:M |
DAY TO MINUTE |
INTERVAL '28 16:15' DAY TO MINUTE |
D H:M:S |
DAY TO SECOND |
INTERVAL '28 16:15:14' DAY TO SECOND |
H:M |
HOUR TO MINUTE |
INTERVAL '16:15' HOUR TO MINUTE |
H:M:S |
HOUR TO SECOND |
INTERVAL '16:15:14' HOUR TO SECOND |
M:S |
MINUTE TO SECOND |
INTERVAL '15:14' MINUTE TO SECOND |
| Name | Description |
|---|---|
JSON |
Represents JSON, a lightweight data-interchange format. |
| Name | Description |
|---|---|
MEASURE |
An aggregate calculation that doesn't overcount. |
| Name | Range |
|---|---|
INT32 |
-2,147,483,648 to 2,147,483,647 |
UINT32 |
0 to 4,294,967,295 |
INT64
|
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
UINT64 |
0 to 18,446,744,073,709,551,615 |
| Name | Precision, Scale, and Range |
|---|---|
NUMERIC
DECIMAL |
Precision: 38 Scale: 9 Minimum value greater than 0 that can be handled: 1e-9 Min: -9.9999999999999999999999999999999999999E+28 Max: 9.9999999999999999999999999999999999999E+28 |
BIGNUMERIC
BIGDECIMAL |
Precision: approximately 76.8 digits (the 77th digit is partial) Scale: 38 Minimum value greater than 0 that can be handled: 1e-38 Min: -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38 Max: 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38 |
| Name | Description |
|---|---|
FLOAT
FLOAT32 |
Single precision (approximate) numeric values. |
DOUBLE
FLOAT64 |
Double precision (approximate) numeric values. |
| Left Term | Operator | Right Term | Returns |
|---|---|---|---|
| Any value | + |
NaN |
NaN |
| 1.0 | + |
+inf |
+inf |
| 1.0 | + |
-inf |
-inf |
-inf |
+ |
+inf |
NaN |
Maximum DOUBLE value |
+ |
Maximum DOUBLE value |
Overflow error |
Minimum DOUBLE value |
/ |
2.0 | 0.0 |
| 1.0 | / |
0.0 |
"Divide by zero" error |
| Left Term | Operator | Right Term | Returns |
|---|---|---|---|
NaN |
= |
Any value | FALSE |
NaN |
< |
Any value | FALSE |
| Any value | < |
NaN |
FALSE |
| -0.0 | = |
0.0 | TRUE |
| -0.0 | < |
0.0 | FALSE |
| Name | Description |
|---|---|
PROTO |
An instance of protocol buffer. |
| Name | Range |
|---|---|
RANGE |
Contiguous range between two dates, datetimes, or timestamps. The lower and upper bound for the range are optional. The lower bound is inclusive and the upper bound is exclusive. |
| Type Declaration | Meaning |
|---|---|
RANGE<DATE> |
Contiguous range between two dates. |
RANGE<DATETIME> |
Contiguous range between two datetimes. |
RANGE<TIMESTAMP> |
Contiguous range between two timestamps. |
| Name | Description |
|---|---|
STRING |
Variable-length character (Unicode) data. |
| Name | Description |
|---|---|
STRUCT |
Container of ordered fields each with a type (required) and field name (optional). |
| Type Declaration | Meaning |
|---|---|
STRUCT<INT64>
|
Simple struct with a single unnamed 64-bit integer field. |
STRUCT<x STRUCT<y INT64, z INT64>>
|
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. |
STRUCT<inner_array ARRAY<INT64>>
|
A struct containing an array named inner_array that holds
64-bit integer elements. |
| Syntax | Output Type | Notes |
|---|---|---|
(x, x+y) |
STRUCT<?,?> |
If column names are used (unquoted strings), the struct field data type is
derived from the column data type. x and y are
columns, so the data types of the struct fields are derived from the column
types and the output type of the addition operator. |
| Syntax | Output Type |
|---|---|
STRUCT(1,2,3) |
STRUCT<int64,int64,int64> |
STRUCT() |
STRUCT<> |
STRUCT('abc') |
STRUCT<string> |
STRUCT(1, t.str_col) |
STRUCT<int64, str_col string> |
STRUCT(1 AS a, 'abc' AS b) |
STRUCT<a int64, b string> |
STRUCT(str_col AS abc) |
STRUCT<abc string> |
| Syntax | Output Type |
|---|---|
STRUCT<int64>(5) |
STRUCT<int64> |
STRUCT<date>("2011-05-05") |
STRUCT<date> |
STRUCT<x int64, y string>(1, t.str_col) |
STRUCT<x int64, y string> |
STRUCT<int64>(int_col) |
STRUCT<int64> |
STRUCT<x int64>(5 AS x) |
Error - Typed syntax doesn't allow AS |
| Name | Range |
|---|---|
TIME |
00:00:00 to 23:59:59.999999999 00:00:00 to 23:59:59.999999 |
[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 60).
+ [.F]: Up to nine fractional
digits (nanosecond precision).
To learn more about the literal representation of a time type,
see [Time literals][time-literals].
[timestamp-type]: #timestamp_type
[time-literals]: https://github.com/google/googlesql/blob/master/docs/lexical.md#time_literals
## Timestamp type
| Name | Range |
|---|---|
TIMESTAMP |
0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999999 UTC 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999 UTC |
YYYY: Four-digit year.
+ [M]M: One or two digit month.
+ [D]D: One or two digit day.
+ { |T|t}: A space or a `T` or `t` separator. The `T` and `t`
separators are flags for time.
+ [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 60).
+ [.F]: Up to 12 fractional
digits (picosecond precision).
+ [time_zone]: String representing the time zone. When a time
zone isn't explicitly specified, the default time zone,
which is implementation defined, is used. For details, see time
zones.
+ [time_zone_offset]: String representing the offset from the
Coordinated Universal Time (UTC) time zone. For details, see
time zones.
+ [utc_time_zone]: String representing the Coordinated Universal
Time (UTC), usually the letter `Z` or `z`. For details, see
time zones.
To learn more about the literal representation of a timestamp type,
see [Timestamp literals][timestamp-literals].
### Time zones
A time zone is used when converting from a civil date or time (as might appear
on a calendar or clock) to a timestamp (an absolute time), or vice versa. This
includes the operation of parsing a string containing a civil date and time like
"2020-01-01 00:00:00" and converting it to a timestamp. The resulting timestamp
value itself doesn't store a specific time zone, because it represents one
instant in time globally.
Time zones are represented by strings in one of these canonical formats:
+ Offset from Coordinated Universal Time (UTC), or the letter `Z` or `z` for
UTC.
+ Time zone name from the
[tz database][tz-database]{: class=external target=_blank }.
The following timestamps are identical because the time zone offset
for `America/Los_Angeles` is `-08` for the specified date and time.
```googlesql
SELECT UNIX_MILLIS(TIMESTAMP '2008-12-25 15:30:00 America/Los_Angeles') AS millis;
```
```googlesql
SELECT UNIX_MILLIS(TIMESTAMP '2008-12-25 15:30:00-08:00') AS millis;
```
#### Specify Coordinated Universal Time (UTC)
You can specify UTC using the following suffix:
```
{Z|z}
```
You can also specify UTC using the following time zone name:
```
{Etc/UTC}
```
The `Z` suffix is a placeholder that implies UTC when converting an [RFC
3339-format][rfc-3339-format] value to a `TIMESTAMP` value. The value `Z` isn't
a valid time zone for functions that accept a time zone. If you're specifying a
time zone, or you're unsure of the format to use to specify UTC, we recommend
using the `Etc/UTC` time zone name.
The `Z` suffix isn't case sensitive. When using the `Z` suffix, no space is
allowed between the `Z` and the rest of the timestamp. The following are
examples of using the `Z` suffix and the `Etc/UTC` time zone name:
```
SELECT TIMESTAMP '2014-09-27T12:30:00.45Z'
SELECT TIMESTAMP '2014-09-27 12:30:00.45z'
SELECT TIMESTAMP '2014-09-27T12:30:00.45 Etc/UTC'
```
#### Specify an offset from Coordinated Universal Time (UTC)
You can specify the offset from UTC using the following format:
```
{+|-}H[H][:M[M]]
```
Examples:
```
-08:00
-8:15
+3:00
+07:30
-7
```
When using this format, no space is allowed between the time zone and the rest
of the timestamp.
```
2014-09-27 12:30:00.45-8:00
```
#### Time zone name {: #time_zone_name}
Format:
```
tz_identifier
```
A time zone name is a tz identifier from the
[tz database][tz-database]{: class=external target=_blank }.
For a less comprehensive but simpler reference, see the
[List of tz database time zones][tz-database-list]{: class=external target=_blank }
on Wikipedia.
Examples:
```
America/Los_Angeles
America/Argentina/Buenos_Aires
Etc/UTC
Pacific/Auckland
```
When using a time zone name, a space is required between the name and the rest
of the timestamp:
```
2014-09-27 12:30:00.45 America/Los_Angeles
```
Note that not all time zone names are interchangeable even if they do happen to
report the same time during a given part of the year. For example,
`America/Los_Angeles` reports the same time as `UTC-7:00` during daylight
saving time (DST), but reports the same time as `UTC-8:00` outside of DST.
If a time zone isn't specified, the default time zone value is used.
#### Leap seconds
A timestamp is simply an offset from 1970-01-01 00:00:00 UTC, assuming there are
exactly 60 seconds per minute. Leap seconds aren't represented as part of a
stored timestamp.
If the input contains values that use ":60" in the seconds field to represent a
leap second, that leap second isn't preserved when converting to a timestamp
value. Instead that value is interpreted as a timestamp with ":00" in the
seconds field of the following minute.
Leap seconds don't affect timestamp computations. All timestamp computations
are done using Unix-style timestamps, which don't reflect leap seconds. Leap
seconds are only observable through functions that measure real-world time. In
these functions, it's possible for a timestamp second to be skipped or repeated
when there is a leap second.
#### Daylight saving time
A timestamp is unaffected by daylight saving time (DST) because it represents a
point in time. When you display a timestamp as a civil time,
with a timezone that observes DST, the following rules apply:
+ During the transition from standard time to DST, one hour is skipped. A
civil time from the skipped hour is treated the same as if it were written
an hour later. For example, in the `America/Los_Angeles` time zone, the hour
between 2 AM and 3 AM on March 10, 2024 is skipped on a clock. The times
2:30 AM and 3:30 AM on that date are treated as the same point in time:
```googlesql
SELECT
FORMAT_TIMESTAMP("%c %Z", "2024-03-10 02:30:00 America/Los_Angeles", "UTC") AS two_thirty,
FORMAT_TIMESTAMP("%c %Z", "2024-03-10 03:30:00 America/Los_Angeles", "UTC") AS three_thirty;
/*------------------------------+------------------------------+
| two_thirty | three_thirty |
+------------------------------+------------------------------+
| Sun Mar 10 10:30:00 2024 UTC | Sun Mar 10 10:30:00 2024 UTC |
+------------------------------+------------------------------*/
```
+ When there's ambiguity in how to represent a civil time in a particular
timezone because of DST, the later time is chosen:
```googlesql
SELECT
FORMAT_TIMESTAMP("%c %Z", "2024-03-10 10:30:00 UTC", "America/Los_Angeles") as ten_thirty;
/*--------------------------------+
| ten_thirty |
+--------------------------------+
| Sun Mar 10 03:30:00 2024 UTC-7 |
+--------------------------------*/
```
+ During the transition from DST to standard time, one hour is repeated. A
civil time that shows a time during that hour is treated as if it's the
earlier instance of that time. For example, in the `America/Los_Angeles` time
zone, the hour between 1 AM and 2 AM on November 3, 2024, is repeated on a
clock. The time 1:30 AM on that date is treated as the earlier (DST) instance
of that time.
```googlesql
SELECT
FORMAT_TIMESTAMP("%c %Z", "2024-11-03 01:30:00 America/Los_Angeles", "UTC") as one_thirty,
FORMAT_TIMESTAMP("%c %Z", "2024-11-03 02:30:00 America/Los_Angeles", "UTC") as two_thirty;
/*------------------------------+------------------------------+
| one_thirty | two_thirty |
+------------------------------+------------------------------+
| Sun Nov 3 08:30:00 2024 UTC | Sun Nov 3 10:30:00 2024 UTC |
+------------------------------+------------------------------*/
```
[rfc-3339-format]: https://datatracker.ietf.org/doc/html/rfc3339#page-10
[tz-database]: http://www.iana.org/time-zones
[tz-database-list]: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
[time-type]: #time_type
[date-type]: #date_type
[datetime-type]: #datetime_type
[timestamp-literals]: https://github.com/google/googlesql/blob/master/docs/lexical.md#timestamp_literals
## UUID type
| Name | Description |
|---|---|
UUID |
A universally unique identifier (UUID) represented as a 128-bit number. |
| Left term | Operator | Right term | Returns |
|---|---|---|---|
| Any value | = |
NULL |
NULL |
NULL |
< |
Any value | NULL |
| 00000000-0000-0000-0000-000000000000 | < |
ffffffff-ffff-ffff-ffff-ffffffffffff | TRUE |
| 00000000-0000-0000-0000-000000000000 | = |
00000000-0000-0000-0000-000000000000 | TRUE |
| 00000000-0000-0000-0000-000000000000 | > |
ffffffff-ffff-ffff-ffff-ffffffffffff | FALSE |