Re: Table design question - Mailing list pgsql-sql

From Rod Taylor
Subject Re: Table design question
Date
Msg-id 1149169316.851.782.camel@home
Whole thread Raw
In response to Table design question  ("David Clarke" <pigwin32@gmail.com>)
List pgsql-sql
> So I'm designing a table and I'm looking for an appropriate key. The
> natural key is a string from a few characters up to a maximum of
> perhaps 100. Joe gets quite fierce about avoiding the use of a serial
> id column as a key. The string is unique in the table and fits the
> criteria for a key. So should I follow Joe's advice and use my natural
> key as the primary key? It sounds reasonable but it will mean at least
> one other table will have the string as a foreign key. My postgres

Unfortunately as a result of the implementation of most commercial
databases (and PostgreSQL), using a string as the primary key will cause
a performance hit.

Yes, normally it is better and for things like status flags and other
constant values that rarely change it is a good approach.


I would tend to add a SERIAL and make it the primary key (using it in
foreign tables) but also making the string column unique and not
null'able.

Essentially it gives the table two primary keys in the hope that some
day PostgreSQL will add a layer of abstraction between primary/foreign
key lookups and presentation that allows for usage of strings directly
without a performance hit.
-- 



pgsql-sql by date:

Previous
From: Miroslav Šulc
Date:
Subject: SELECT DISTINCT too slow
Next
From: Alvaro Herrera
Date:
Subject: Re: SELECT DISTINCT too slow