Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between TEXT, CHAR, and VARCHAR in CockroachDB?

I see different schemas using TEXT, CHAR, VARCHAR, CHARACTER VARYING, CHAR VARYING to store string data. Which should I use in CockroachDB?

like image 956
benesch Avatar asked Sep 11 '25 14:09

benesch


1 Answers

All the types mentioned are equivalent; see the CockroachDB STRING documentation for an exhaustive list.

In CockroachDB, the following are aliases for STRING:

  • CHARACTER
  • CHAR
  • VARCHAR
  • TEXT

And the following are aliases for STRING(n):

  • CHARACTER(n)
  • CHARACTER VARYING(n)
  • CHAR(n)
  • CHAR VARYING(n)
  • VARCHAR(n)

CockroachDB will treat all of these types identically. The canonical name for the type in CockroachDB, however, is STRING, so if you're starting a new application from scratch, you'll reduce confusion by preferring STRING over the other aliases.

like image 140
benesch Avatar answered Sep 14 '25 05:09

benesch