Re: string primary key

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Mark Gibson <mark(at)gibsonsoftware(dot)com>
Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: string primary key
Date: 2006-05-11 16:40:57
Message-ID: 1147365657.9755.69.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2006-05-11 at 10:52, Mark Gibson wrote:
> Is there a disadvantage to having the primary key for a table be a text
> type vs. an integer type? Performance? Any difference between having a
> varchar or char as a primary key?
>
> My instinct tells me that an integer is preferred, but I'm looking for a
> more concrete answer.

If you need a unique constraint on the text field anyway, and it's a
natural key, you're generally better of using that field as the pk.

However, if it's not a natually unique key, then it shouldn't be the pk,
and int is a perhaps better choice.

There are two VERY oppositional schools of thought on natural versus
artificial keys out there, and neither side is likely to change their
minds.

My preference is generally for artificial keys (i.e. sequence generated
ones) because I've had requirements change underfoot too many times to
rely on natural keys all the time.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Blair Lowe 2006-05-11 16:41:51 Re: pg_dump and grants to PUBLIC
Previous Message Tom Lane 2006-05-11 16:29:21 Re: Debugging SQL queries