Databases
CockroachDB
Column Types

CockroachDB Column Types

CockroachDB is PostgreSQL-compatible and supports most PostgreSQL column types. SchemaHero uses the same type handling as PostgreSQL.

Simple Types

TypeAliasesDescription
bigintint8, int648-byte signed integer
intint4, int64, integer8-byte signed integer (default)
smallintint22-byte signed integer
booleanboolTrue/false value
byteabytesBinary data
dateCalendar date
floatfloat8, double precision8-byte floating point
realfloat44-byte floating point
inetIPv4 or IPv6 address
intinteger8-byte integer (CockroachDB default)
intervalTime interval
jsonJSON data
jsonbBinary JSON data
serialAuto-incrementing integer
stringtext, varcharVariable-length string
timeTime of day
timestampDate and time
timestamptztimestamp with time zoneTimestamp with timezone
uuidUniversally unique identifier

Parameterized Types

TypeExampleDescription
bit(n)bit(8)Fixed-length bit string
varbit(n)varbit(64)Variable-length bit string
char(n)char(10)Fixed-length string
varchar(n)varchar(255)Variable-length string
decimal(p,s)decimal(10,2)Exact numeric
numeric(p,s)numeric(10,2)Exact numeric (alias)
string(n)string(100)Variable-length string with limit

Array Types

Arrays are supported:

columns:
  - name: tags
    type: text[]
  - name: scores
    type: int[]

CockroachDB-Specific Types

TypeDescription
serialAuto-incrementing unique ID
stringPreferred over varchar in CockroachDB

Type Differences from PostgreSQL

PostgreSQLCockroachDB
int = 4 bytesint = 8 bytes
serial = 4 bytesserial = 8 bytes
Many geometric typesLimited geometric support

Examples

columns:
  - name: id
    type: uuid
    default: gen_random_uuid()
  - name: email
    type: string
    constraints:
      notNull: true
  - name: name
    type: varchar(100)
  - name: balance
    type: decimal(10,2)
  - name: active
    type: boolean
  - name: metadata
    type: jsonb
  - name: tags
    type: text[]
  - name: created_at
    type: timestamptz
    default: now()
  - name: ip_address
    type: inet

Notes

  • CockroachDB defaults INT to 8 bytes (unlike PostgreSQL's 4 bytes)
  • Use INT4 explicitly if you need 4-byte integers
  • STRING is the preferred text type in CockroachDB
  • gen_random_uuid() is available by default