CQL Data Types

Every column in a Cassandra table has a data type. You choose it when you create the table, and it says what kind of value the column can hold. These are the types you will use most.

Text

TypeDescription
textText of any length. Use this for most text.
asciiText with only English letters, digits and symbols. You rarely need it.

Numbers

TypeDescription
intA whole number, up to about 2 billion
bigintA whole number for very large values
varintA whole number of any size
float / doubleA number with decimals, stored approximately
decimalA number with decimals, stored exactly. Use this for money.

Date and time

TypeDescription
dateA calendar date, like '2024-03-01'
timeA time of day, like '09:30:00'
timestampA date and a time, like '2024-03-01 09:30:00'

Other types

TypeDescription
booleantrue or false
uuidA long, random id that is unique everywhere
timeuuidA unique id that also holds the time it was made
blobRaw bytes, like the data of a small file

Example

Here is a table for events that uses several types:

CREATE TABLE events (
  id uuid PRIMARY KEY,
  title text,
  seats int,
  price decimal,
  online boolean,
  event_day date,
  starts_at timestamp
);

A few tips:

  • Use decimal for money. float and double store numbers approximately, so small rounding errors can appear in calculations. decimal keeps the exact value.
  • uuid is very common in Cassandra. Many databases number new rows for you: 1, 2, 3 and so on. Cassandra does not, because all the nodes would have to agree on the next number every time. A uuid is random and unique, so any node can make one without asking the others.
  • Text values use single quotes, like 'Alice'. Dates and times are written as text too: '2024-03-01'. Numbers and true / false have no quotes.

Now choose the right types for a table of game players.