CREATE INDEX

An SQL command for creating an index

CREATE INDEX is a DDL command for creating an index.

CREATE INDEX has always been present in PostgreSQL.

Change history

Examples

Basic usage example for CREATE INDEX:

postgres=# CREATE INDEX ON foo (bar_id);
CREATE INDEX

postgres=# \d foo
                Table "public.foo"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 id     | integer |           | not null |
 bar_id | integer |           | not null |
Indexes:
    "foo_pkey" PRIMARY KEY, btree (id)
    "foo_bar_id_idx" btree (bar_id)
Foreign-key constraints:
    "foo_bar_id_fkey" FOREIGN KEY (bar_id) REFERENCES bar(id)

Categories

DDL, Indexing, SQL command

See also

ALTER INDEX, DROP INDEX, REINDEX