Data Types

On this page Carat arrow pointing down
Warning:
CockroachDB v1.0 is no longer supported as of November 10, 2018. For more details, refer to the Release Support Policy.

Supported Types

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

Type Description Example
INT A 64-bit signed integer. 12345
SERIAL A unique 64-bit signed integer. 148591304110702593
DECIMAL An exact, fixed-point number. 1.2345
FLOAT A 64-bit, inexact, floating-point number. 1.2345
BOOL A Boolean value. true
DATE A date. DATE '2016-01-25'
TIMESTAMP
TIMESTAMPTZ
A date and time pairing in UTC. TIMESTAMP '2016-01-25 10:10:10'
TIMESTAMPTZ '2016-01-25 10:10:10-05:00'
INTERVAL A span of time. INTERVAL '2h30m30s'
STRING A string of Unicode characters. 'a1b2c3'
COLLATE The COLLATE feature lets you sort STRING values according to language- and country-specific rules, known as collations. 'a1b2c3' COLLATE en
BYTES A string of binary characters. b'\141\061\142\062\143\063'

Data Type Conversions & 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 a type annotation instead 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 converstion and casting on its respective page in its section Supported Casting & Conversion.


Yes No
On this page

Yes No