Contents
CREATE TABLE
An SQL command for defining a new table
CREATE TABLE
is a DDL command for defining a new table.
CREATE TABLE
has always been present in PostgreSQL.
Change history
Work-in-progress
- PostgreSQL 15
- PostgreSQL 9.2
GLOBAL
andLOCAL
options deprecated forCREATE TEMPORARY TABLE
(commit c3bc76bd)
- PostgreSQL 9.0
UNLOGGED
option added (commit 53dbc27c)
- PostgreSQL 8.3
CREATE TABLE ... (LIKE ... INCLUDING INDEXES)
added (commit 47477491)
- PostgreSQL 8.2
CREATE TABLE ... (LIKE ... INCLUDING CONSTRAINTS)
added (commit dc2c25fc)
- PostgreSQL 7.3
Examples
Basic usage example for CREATE TABLE
:
postgres=# CREATE TABLE foo (id INT NOT NULL PRIMARY KEY, val TEXT); CREATE TABLE postgres=# \d foo Table "public.foo" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- id | integer | | not null | val | text | | | Indexes: "foo_pkey" PRIMARY KEY, btree (id)
References
- PostgreSQL documentation: CREATE TABLE