Chapter 5. Data Definition

Table of Contents
5.1. Table Basics
5.2. Default Values
5.3. Constraints
5.3.1. Check Constraints
5.3.2. Not-Null Constraints
5.3.3. Unique Constraints
5.3.4. Primary Keys
5.3.5. Foreign Keys
5.4. System Columns
5.5. Modifying Tables
5.5.1. Adding a Column
5.5.2. Removing a Column
5.5.3. Adding a Constraint
5.5.4. Removing a Constraint
5.5.5. Changing a Column's Default Value
5.5.6. Changing a Column's Data Type
5.5.7. Renaming a Column
5.5.8. Renaming a Table
5.6. Privileges
5.7. Schemas
5.7.1. Creating a Schema
5.7.2. The Public Schema
5.7.3. The Schema Search Path
5.7.4. Schemas and Privileges
5.7.5. The System Catalog Schema
5.7.6. Usage Patterns
5.7.7. Portability
5.8. Inheritance
5.9. Other Database Objects
5.10. Dependency Tracking

Note: The following description applies both to Postgres-XC and PostgreSQL if not described explicitly.

This chapter covers how one creates the database structures that will hold one's data. In a relational database, the raw data is stored in tables, so the majority of this chapter is devoted to explaining how tables are created and modified and what features are available to control what data is stored in the tables. Subsequently, we discuss how tables can be organized into schemas, and how privileges can be assigned to tables. Finally, we will briefly look at other features that affect the data storage, such as inheritance, views, functions, and triggers.