Re: Primary Key

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Primary Key
Date: 2007-11-16 20:06:46
Message-ID: 20071116120646.7e79bd21@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 16 Nov 2007 20:00:29 +0000
Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:

> > > Normally a primary key would just be a single column. When you
> > > start going to that many I'd probably have a serial column as the
> > > primary key, and a UNIQUE index on those six fields. Depends on
> > > what you're doing, though unless you've got a few years
> > > experience I'd be tempted to stay away from primary keys of more
> > > than a single column.
> >
> > Fie on you evil synthetic key lovers. Long live the Natural Key!
>
> Really? I started off with everything using sequences and everything
> was good. Then I found I wanted to do more complicated things so I
> started to transition to natural keys and things were better. Then
> I took things too far and wanted something artificial back in my

When that is needed I do this:

create table foo(id serial unique, a text, b text, primary (a,b));

Joshua D. Drake

> life. I'm back to almost never using natural keys now, mainly because
> interfacing with the outside world gets too complicated. When I'm
> just doing stuff inside the database then I can use natural keys and
> all is good, otherwise things just get too complicated.
>
> I'll probably look back in another few years and remember how young
> and naive I was back now.
>
>
> Sam
>
> ---------------------------(end of
> broadcast)--------------------------- TIP 6: explain analyze is your
> friend
>

- --

=== The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 24x7/Emergency: +1.800.492.2240
PostgreSQL solutions since 1997 http://www.commandprompt.com/
UNIQUE NOT NULL
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHPfhWATb/zqfZUUQRArjCAJ90cXYwuw/A/yojQanj1gv+RJqJnQCdFvPv
6nGph8K57KcKtk1rTgfFSFg=
=fQ5l
-----END PGP SIGNATURE-----

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Hart 2007-11-16 20:13:48 "field doesn't exist" even though I'm sure it does
Previous Message Sam Mason 2007-11-16 20:00:29 Re: Primary Key