Tuple column
Write values into a tuple column. Tuplese are frozen by default, so you can’t update individual fields in a tuple. Tuples group small amounts of data together and stores the data in a single column.
Prerequisites
-
Insert tuple data into the table
cycling.route
. Note that the tuple is enclosed in parentheses. This tuple has a tuple nested inside; nested parentheses are required for the inner tuple, then the outer 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)
);
INSERT INTO cycling.route (
race_id, race_name, point_id, lat_long
) VALUES (
500, '47th Tour du Pays de Vaud', 1, ('Onnens', (46.8444, 6.6667))
);
INSERT INTO cycling.route (
race_id, race_name, point_id, lat_long
) VALUES (
500, '47th Tour du Pays de Vaud', 2, ('Champagne', (46.833, 6.65))
);
INSERT INTO cycling.route (
race_id, race_name, point_id, lat_long
) VALUES (
500, '47th Tour du Pays de Vaud', 3, ('Novalle', (46.833, 6.6))
);
INSERT INTO cycling.route (
race_id, race_name, point_id, lat_long
) VALUES (
500, '47th Tour du Pays de Vaud', 4, ('Vuiteboeuf', (46.8, 6.55))
);
INSERT INTO cycling.route (
race_id, race_name, point_id, lat_long
) VALUES (
500, '47th Tour du Pays de Vaud', 5, ('Baulmes', (46.7833, 6.5333))
);
INSERT INTO cycling.route (
race_id, race_name, point_id, lat_long
) VALUES (
500, '47th Tour du Pays de Vaud', 6, ('Les Clées', (46.7222, 6.5222))
);
-
Insert tuple data into the column
info
in the tablecycling.nation_rank
. Theinfo
column stores the rank, name, and point total of each cyclist. The tuple is enclosed in parentheses.
CREATE TABLE IF NOT EXISTS cycling.nation_rank (
nation text PRIMARY KEY,
info tuple<int, text, int>
);
INSERT INTO cycling.nation_rank (
nation, info
) VALUES (
'Spain', (1, 'Alejandro VALVERDE', 9054)
);
INSERT INTO cycling.nation_rank (
nation, info
) VALUES (
'France', (2, 'Sylvain CHAVANEL', 6339)
);
INSERT INTO cycling.nation_rank (
nation, info
) VALUES (
'Belgium', (3, 'Phillippe GILBERT', 6222)
);
INSERT INTO cycling.nation_rank (
nation, info
) VALUES (
'Italy', (4, 'Davide REBELLINI', 6090)
);
-
Insert tuple data into the column
cinfo
in the tablecycling.popular
. Thecinfo
column stores the country name, cyclist name, and points total.
CREATE TABLE IF NOT EXISTS cycling.popular (
rank int PRIMARY KEY,
cinfo tuple<text, text, int>
);
INSERT INTO cycling.popular ( rank, cinfo )
VALUES ( 1, ('Spain', 'Mikel LANDA', 1137) );
INSERT INTO cycling.popular ( rank, cinfo )
VALUES ( 2, ('Netherlands', 'Steven KRUIJSWIJK', 621) );
INSERT INTO cycling.popular ( rank, cinfo )
VALUES ( 3, ('USA', 'Matthew BUSCHE', 230) );
INSERT INTO cycling.popular ( rank, cinfo )
VALUES ( 4, ('Italy', 'Fabio ARU', 163) );
INSERT INTO cycling.popular ( rank, cinfo )
VALUES ( 5, ('Canada', 'Ryder HESJEDAL', 148) );