Create a tuple column
Tuples are a data type that allow two or more values to be stored together in a column.
A user-defined type can be used, but for simple groupings, a tuple
is a good choice.
Prerequisite
-
Keyspace must exist
Create a table cycling.nation_rank
using a tuple
to store the rank, cyclist name, and points total for a cyclist, and the nation name as the primary key.
CREATE TABLE IF NOT EXISTS cycling.nation_rank (
nation text PRIMARY KEY,
info tuple<int, text, int>
);
The previous table cycling.nation_rank
uses the nation as the primary key.
It is possible to store the same data using the rank as the primary key, as shown in the following example.
The example creates a table named cycling.popular
using a tuple
to store the country name, cyclist name, and points total for a cyclist, with rank set as the primary key.
CREATE TABLE IF NOT EXISTS cycling.popular (
rank int PRIMARY KEY,
cinfo tuple<text, text, int>
);
Create a table cycling.route
using a tuple
to store each way point location name, latitude, and longitude.
Two tuples are used in the following example, with one tuple nested inside the other tuple.
CREATE TABLE IF NOT EXISTS cycling.route (
race_id int,
race_name text,
point_id int,
lat_long tuple<text, tuple<float, float>>,
PRIMARY KEY (race_id, point_id)
);