Re: Are Indices automatically generated for primary keys?

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Clemens Eisserer" <linuxhippy(at)gmail(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Are Indices automatically generated for primary keys?
Date: 2010-08-18 13:59:34
Message-ID: 4C6BA0F6020000250003481C@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-performance

Clemens Eisserer <linuxhippy(at)gmail(dot)com> wrote:

> Are indices for columns marked with "PRIMARY KEY" automatically
> generated by postgresql, or do I have to do it manually?

If you look at the documentation page for CREATE TABLE, you'll see
the following:

| PostgreSQL automatically creates an index for each unique
| constraint and primary key constraint to enforce uniqueness. Thus,
| it is not necessary to create an index explicitly for primary key
| columns. (See CREATE INDEX for more information.)

http://www.postgresql.org/docs/current/interactive/sql-createtable.html

There's a lot of information on the page, but if you use your
browser to search for PRIMARY KEY within the page, it's not too hard
to find.

Also, if you create a primary key or a unique constraint on a table,
you should see a notice informing you of the creation of the index,
and its name.

-Kevin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Clemens Eisserer 2010-08-18 14:15:26 Re: Are Indices automatically generated for primary keys?
Previous Message hubert depesz lubaczewski 2010-08-18 13:54:56 Re: Are Indices automatically generated for primary keys?

Browse pgsql-performance by date

  From Date Subject
Next Message Clemens Eisserer 2010-08-18 14:15:26 Re: Are Indices automatically generated for primary keys?
Previous Message hubert depesz lubaczewski 2010-08-18 13:54:56 Re: Are Indices automatically generated for primary keys?