Data Types

Supported types

CockroachDB supports the following data types. Click a type for more details.

TypeDescriptionExample
ARRAYA 1-dimensional, 1-indexed, homogeneous array of any non-array data type.{"sky","road","car"}
BITA string of binary digits (bits).B'10010101'
BOOLA Boolean value.true
BYTESA string of binary characters.b'\141\061\142\062\143\063'
COLLATEThe COLLATE feature lets you sort STRING values according to language- and country-specific rules, known as collations.'a1b2c3' COLLATE en
DATEA date.DATE '2016-01-25'
DECIMALAn exact, fixed-point number.1.2345
FLOATA 64-bit, inexact, floating-point number.1.2345
INETAn IPv4 or IPv6 address.192.168.0.1
INTA signed integer, up to 64 bits.12345
INTERVALA span of time.INTERVAL '2h30m30s'
JSONBJSON (JavaScript Object Notation) data.'{"first_name": "Lola", "last_name": "Dog", "location": "NYC", "online" : true, "friends" : 547}'
SERIALA pseudo-type that combines an integer type with a DEFAULT expression.148591304110702593
STRINGA string of Unicode characters.'a1b2c3'
TIMEA time of day in UTC.TIME '01:23:45.123456'
TIMESTAMPA date and time pairing in UTC.TIMESTAMP '2016-01-25 10:10:10'
TIMESTAMPTZA date and time pairing with a time zone offset from UTC.TIMESTAMPTZ '2016-01-25 10:10:10-05:00'
UUIDA 128-bit hexadecimal value.7f9c24e8-3b12-4fef-91e0-56a2d5a246ec

Data type conversions and casts

CockroachDB supports explicit type conversions using the following methods:

  • <type> 'string literal', to convert from the literal representation of a value to a value of that type. For example:DATE '2008-12-21', INT '123', or BOOL 'true'.

  • <value>::<data type>, or its equivalent longer form CAST(<value> AS <data type>), which converts an arbitrary expression of one built-in type to another (this is also known as type coercion or "casting"). For example:NOW()::DECIMAL, VARIANCE(a+2)::INT.

Tip:

To create constant values, consider using atype annotationinstead of a cast, as it provides more predictable results.

  • Other built-in conversion functions when the type is not a SQL type, for example from_ip(), to_ip() to convert IP addresses between STRING and BYTES values.

You can find each data type's supported conversion and casting on itsrespective page in its section Supported casting & conversion.

Was this page helpful?
YesNo