X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id C50B39FA0EC for ; Thu, 6 Jul 2006 07:16:52 -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 32669-01 for ; Thu, 6 Jul 2006 07:16:44 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by postgresql.org (Postfix) with ESMTP id 2FDAD9F94F3 for ; Thu, 6 Jul 2006 07:16:43 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so2608537ugf for ; Thu, 06 Jul 2006 03:16:42 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=YfCPyzi3bmtepNg7+bKT2AnekuQpC3vVnSD+I1DvIjEi2Urbre05A3lqZuCoSgI1YTmkR0DWPyBsH/FI4lW8KfYOjXye+kbGEWa/IlEAN2f8VW3BBzoZDzNofOAMUU+ZByP9UcorVht72ABNAm8Uk7gEdHqET23fzR6NNGLEzow= Received: by 10.67.101.8 with SMTP id d8mr522176ugm; Thu, 06 Jul 2006 03:16:42 -0700 (PDT) Received: by 10.67.23.14 with HTTP; Thu, 6 Jul 2006 03:16:42 -0700 (PDT) Message-ID: <12b7ac1e0607060316ub7b5e21i5e8e3bef2504e02c@mail.gmail.com> Date: Thu, 6 Jul 2006 22:16:42 +1200 From: "David Clarke" To: pgsql-sql@postgresql.org Subject: Alternative to serial primary key MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/53 X-Sequence-Number: 25627 I posted a couple of weeks back a question regarding the use of a 100 char column as a primary key and the responses uniformily advised the use of a serial column. My concern is that the key is effectively abstract and I want to use the column as a foreign key in other tables. It occurred to me that if I used a hash function on insert to generate another column and used that column as the primary key then I have a value that meets a lot of the requirements for a good key, including that I can regenerate the exact value from my data, something that is impossible with a serial id. I also don't have to index the 100 char column in order to search on the table, I just need to calculate the hash value and check that against the calculated column. It does violate the rule that a table shouldn't contain a column that is calculated from another column in the table but I think it would still be more effective than a serial id. Is this a reasonable/normal thing to do? I know postgres contains an md5() hash function, is this likely to be fast enough to make this an effective choice? Are there other options? Am I just a noob barking up the wrong tree? It is getting kind of late and my brain is starting to hurt.