Comprehensive reference for SQL data types supported by CockroachDB
CockroachDB supports a rich set of SQL data types for defining column schemas and expressing values. This page documents all supported data types, their storage characteristics, and usage examples.
Control string sorting and comparison using collations.
CREATE TABLE localized_content ( id INT PRIMARY KEY, title STRING COLLATE en, description VARCHAR(200) COLLATE de);-- Case-insensitive comparisonSELECT * FROM localized_content WHERE title COLLATE en = 'Hello';
CREATE TABLE features ( id INT PRIMARY KEY, enabled BOOL DEFAULT false, is_public BOOLEAN NOT NULL);INSERT INTO features VALUES (1, true, false), (2, 't', 'f'), -- Alternative syntax (3, 'yes', 'no'); -- Also supported
CREATE TABLE api_responses ( id INT PRIMARY KEY, data JSONB);INSERT INTO api_responses VALUES (1, '{"name": "Alice", "age": 30}');-- Query JSON fieldsSELECT data->>'name' AS name FROM api_responses;-- Index JSON fieldsCREATE INVERTED INDEX ON api_responses (data);
Binary JSON format (recommended). Supports inverted indexes.
CREATE TABLE legacy_data ( id INT PRIMARY KEY, payload JSON);INSERT INTO legacy_data VALUES (1, '[1, 2, 3]');
CREATE TABLE teams ( id INT PRIMARY KEY, member_ids INT[], scores INT8[]);INSERT INTO teams VALUES (1, ARRAY[1, 2, 3], ARRAY[100, 200, 300]);SELECT * FROM teams WHERE 2 = ANY(member_ids);
CREATE TYPE status AS ENUM ('pending', 'active', 'inactive');CREATE TABLE orders ( id INT PRIMARY KEY, order_status status DEFAULT 'pending');INSERT INTO orders VALUES (1, 'active'), (2, 'pending');SELECT * FROM orders WHERE order_status = 'active';
-- INT2VECTOR for system catalogsCREATE TABLE pg_indexes ( indkey INT2VECTOR);-- OIDVECTOR for system catalogs CREATE TABLE pg_class ( relchecks OIDVECTOR);