The columns of a table may be extended by passing the ADD COLUMN clause to the ALTER TABLE command. The following syntax describes adding a column where table_name is the name of the table to modify, column_name is the name of the column to add, and column_type is the data type of the new column:
ALTER TABLE table_name ADD [ COLUMN ] column_name column_type
Technically, the COLUMN keyword may be omitted, as it is considered a noise term, and it is only useful for your own readability.
As an example of this function, imagine that an industrious employee at Book Town decides that the books table requires another column; specifically, a date column to represent the publication date. Such a procedure is demonstrated in Example 4-7 .
Example 4-7. Adding a Column
booktown=# ALTER TABLE books booktown-# ADD publication date; ALTER booktown=# \d books Table "books" Attribute | Type | Modifier -------------+---------+---------- id | integer | not null title | text | not null author_id | integer | subject_id | integer | publication | date | Index: books_pkey
Example 4-7 successfully adds a new column to Book Town's books table with the name of publication , and a data type of date . It also demonstrates a pitfall of uncoordinated table design among developers: in our examples, the Book Town editions table already stores the publication date. See the section called Re-structuring Existing Tables for information on how to re-structure a table after such a mistake has been made.