Columns

In the object hierarchy under any table, you will find Columns. At some point more columns may need to be added to a user table. Rather than recreating the entire table with another column, PostgreSQL allows you to add columns to an existing user table.

Columns can be added by selecting ADD COLUMN from the Columns context menu. Once a column has been added, it cannot be dropped. This section describes how to add and modify a column with RHDB Administrator.

In this example, you will create a column called item_sale_price and add it to the table items.

  1. A column is an object under a table, so to create a column, first expand the database then the table you wish to create the column under (click the + beside the database and table names).

  2. Right-click on Columns and select ADD COLUMN.

  3. A dialog box asks for the name of the new column and the data type. In the Name For The New Column field, type: item_sale_price

    Because this column will represent the cost of an item when it is on sale, for data type enter numeric(7,2). Refer to the Red Hat Database SQL Guide and Reference for detailed information on each data type and how it can be used.

    Figure 4-12. The ADD COLUMN Dialog

  4. Click OK to add the column to the table.

Figure 4-13. The customers Column Tree View and Summary View

Note that the column item_sale_price has been added under the Columns node in the Tree View.

RHDB Administrator also enables you to perform the following operations on existing columns:

SET DEFAULT

A column can be given a default value that is used when no other value has been assigned to that column field during a table update. To set the default value for a column, right-click on that column and select ALTER COLUMN -> SET DEFAULT. The dialog that appears enables you to drop or change the default value for that column.

Figure 4-14. The ALTER COLUMN SET DEFAULT Dialog

Refer to the Red Hat Database SQL Guide and Reference for more information on inheritance.

SET STATISTICS

Statistics can be set for each column on a table. These values set the statistics-gathering target for subsequent ANALYZE operations. To set the default value for a column, right-click on that column and select ALTER COLUMN -> SET STATISTICS. A dialog box asks for the statistics value for that column. Standard values can be from 0 to 1000, but (in PostgreSQL versions 7.3 and above) you can set a value of -1 to cause default statistics values to be used.

Figure 4-15. The ALTER COLUMN SET STATISTICS Dialog

Rename

PostgreSQL allows renaming of columns. To rename a column, right-click on it and select RENAME COLUMN. A dialog asks for the new name. Type the new name in the edit box and click OK (or press [Enter]) to save the new name.

Commenting

PostgreSQL allows commenting on columns, which makes them easier to identify. To comment on a column, right-click on it and select COMMENT. A dialog asks for the comment. If there is already a comment on the column, this comment is displayed. Type the new comment in the edit box and click OK (or press [Enter]) to save the new comment.