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.


  • Alter the table cycling.upcoming_calendar to add a collection map named description to store a name and description for each race.
    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 = {
      '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.
     {'Criterium du Dauphine': 'Easy race', 'Tour du Suisse': 'Hard uphill race'}
    (1 rows)