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
| Type | Description |
|---|---|
text | Text of any length. Use this for most text. |
ascii | Text with only English letters, digits and symbols. You rarely need it. |
Numbers
| Type | Description |
|---|---|
int | A whole number, up to about 2 billion |
bigint | A whole number for very large values |
varint | A whole number of any size |
float / double | A number with decimals, stored approximately |
decimal | A number with decimals, stored exactly. Use this for money. |
Date and time
| Type | Description |
|---|---|
date | A calendar date, like '2024-03-01' |
time | A time of day, like '09:30:00' |
timestamp | A date and a time, like '2024-03-01 09:30:00' |
Other types
| Type | Description |
|---|---|
boolean | true or false |
uuid | A long, random id that is unique everywhere |
timeuuid | A unique id that also holds the time it was made |
blob | Raw 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
decimalfor money.floatanddoublestore numbers approximately, so small rounding errors can appear in calculations.decimalkeeps the exact value. uuidis 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. Auuidis 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 andtrue/falsehave no quotes.
Now choose the right types for a table of game players.