Search Postgresql Archives

Re: Primary Key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 16, 2007 at 12:06:46PM -0800, Joshua D. Drake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Fri, 16 Nov 2007 20:00:29 +0000
> Sam Mason <sam@xxxxxxxxxxxxx> 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));

By itself, this insufficiently restricts what's going on in the table.
I'd recommend a TRIGGER that disallows updating the synthetic key.

Cheers,
David.
-- 
David Fetter <david@xxxxxxxxxx> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@xxxxxxxxx

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux