Altering a table to add a collection
Add collection columns to a table or change existing collection columns with the ALTER TABLE command.
Use the ALTER TABLE
command to add a collection column to a table.
Procedure
-
Alter the table cycling.upcoming_calendar to add a
collection map description to store a description for each
race listed.
ALTER TABLE cycling.upcoming_calendar ADD description map<text,text>;
-
After updating cycling.upcoming_calendar table to insert
some data, description can be displayed.
UPDATE cycling.upcoming_calendar SET description = description + {'Criterium du Dauphine' : 'Easy race', 'Tour du Suisse' : 'Hard uphill race'} WHERE year = 2015 AND month = 6;
Verify the results.SELECT description FROM cycling.upcoming_calendar WHERE year = 2015 AND month = 6;
Map type columns display in a JSON format.description ------------------------------------------------------------------------------ {'Criterium du Dauphine': 'Easy race', 'Tour du Suisse': 'Hard uphill race'} (1 rows)