X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id EA7CA9FA5DC for ; Thu, 1 Jun 2006 10:42:49 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 03595-06 for ; Thu, 1 Jun 2006 10:42:40 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from gozer.look.ca (epsilon1.look.ca [207.136.80.10]) by postgresql.org (Postfix) with ESMTP id E833F9FA040 for ; Thu, 1 Jun 2006 10:42:40 -0300 (ADT) Received: from 216-154-16-41.dsl.look.ca ([216.154.16.41]) by gozer.look.ca with esmtp (Exim 4.20) id 1FlnRe-00085o-6y; Thu, 01 Jun 2006 13:42:38 +0000 From: Rod Taylor To: David Clarke Cc: pgsql-sql@postgresql.org In-Reply-To: <12b7ac1e0606010405u6e062f71mf4adbaeb6c46df5f@mail.gmail.com> References: <12b7ac1e0606010405u6e062f71mf4adbaeb6c46df5f@mail.gmail.com> Date: Thu, 01 Jun 2006 09:41:56 -0400 Message-Id: <1149169316.851.782.camel@home> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 FreeBSD GNOME Team Port X-SA-Exim-Mail-From: pg@rbt.ca Subject: Re: Table design question Content-Type: text/plain Content-Transfer-Encoding: 7bit X-SA-Exim-Version: 3.1 (built Tue Feb 24 05:09:27 GMT 2004) X-SA-Exim-Scanned: Yes X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/3 X-Sequence-Number: 25239 > 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. --