Re: Is the primary key constraint also an index?

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Tim Uckun <timuckun(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is the primary key constraint also an index?
Date: 2008-08-13 09:41:31
Message-ID: 48A2AC4B.2050508@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 13/08/2008 03:18, Tim Uckun wrote:
> If I have a primary key constraint defined in the database do I also
> need to create an index on that field for fast lookup?

As I understand it, creating a primary key on a table also creates an
index automatically:

testdb=# create table test(f1 integer, f2 text);
CREATE TABLE
testdb=# alter table test add constraint test_pk primary key(f1);
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index
test_pk" for table "test"
ALTER TABLE

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dmitry Koterov 2008-08-13 10:34:17 Re: How to get many data at once?
Previous Message Dmitry Koterov 2008-08-13 09:20:35 Re: How to modify ENUM datatypes? (The solution)