Supported Types
The following table lists all data types available in CockroachDB:A 1-dimensional, 1-indexed, homogeneous array of any non-array data type.
A string of binary digits (bits).
A Boolean value:
true or false.A string of binary characters.
A date without time zone information.
An exact, fixed-point number. Use for monetary values and when precision is critical.
A user-defined data type comprised of a set of static values.
A 64-bit, inexact, floating-point number.
An IPv4 or IPv6 address.
A signed integer, up to 64 bits. Aliases:
INTEGER, INT8, INT64, BIGINT.A 16-bit signed integer. Alias:
SMALLINT. Range: -32768 to +32767.A 32-bit signed integer. Range: -2147483648 to +2147483647.
A span of time.
JSON (JavaScript Object Notation) data stored in a binary format.
A string of Unicode characters. Aliases:
TEXT, VARCHAR, CHAR.A time of day in UTC without date information.
A time of day with a specified time zone offset from UTC.
A date and time pairing in UTC.
A timestamp with a specified time zone offset from UTC.
A 128-bit hexadecimal universally unique identifier.
A fixed-length array of floating-point numbers for vector embeddings.
Type Conversions and Casts
You can convert values between different data types using explicit casts:- Type Literal
- :: Operator
- CAST Function
Convert from a string literal to a specific type:
For constant values, use type literals (e.g.,
DATE '2016-01-01') instead of casts for more predictable results.Integer Size Considerations
By default,INT is an alias for INT8, which creates 64-bit signed integers. This differs from PostgreSQL’s default 32-bit INT.
JavaScript Compatibility
JavaScript represents numbers as 64-bit floats with only 53 bits of numeric accuracy. The maximum safe integer in JavaScript (2^53) is much smaller than CockroachDB’sINT maximum:
INT4 (32-bit) or STRING for large integer values.
Changing Default Integer Size
You can change the default integer size using:Session Variable
Cluster Setting
Implicit Casting to Arrays
CockroachDB supports implicit casting from string literals to arrays of all data types except:BYTESENUMJSONBSERIAL- Spatial types (
BOX2D,GEOGRAPHY,GEOMETRY)
String Length Limits
To limit the length of a string column, useSTRING(n) where n is the maximum number of characters:
Collations
STRING values support collations for language-specific sorting: