Re: primary keys

From: Grant Maxwell <grant(dot)maxwell(at)maxan(dot)com(dot)au>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: primary keys
Date: 2009-09-12 16:53:18
Message-ID: E997FF33-A54A-4382-9538-6301D55BE361@maxan.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 13/09/2009, at 2:46 AM, Tom Lane wrote:

> Grant Maxwell <grant(dot)maxwell(at)maxan(dot)com(dot)au> writes:
>> I don't know why it was done this way but it seems to me that the
>> email addresses are unique, non null and could be used as the primary
>> key. This would make the replication much faster and simpler.
>
>> Does anyone out there think the change (number to email address as
>> primary key) would be a bad idea ?
>
> One thing that's often considered a useful attribute of a primary
> key is
> that it be immutable. In your application, do users ever change their
> email addresses? If so, what should happen --- is it okay to treat
> that
> as effectively a new entry?
>
This would be ok. The table keeps a list of email addresses and some
stats on them
users may have multiple addresses but would never alter a specific
record.

> Also, if you have any other tables referencing this one via foreign
> keys, you'd have to have them storing the email address instead of
> the serial number; it'll be bulkier and address updates will be that
> much more expensive.
so text PKs will be less efficient than numeric ?
>
> You can find lots and lots and lots of discussion of this topic if
> you search the archives for talk about natural versus surrogate keys.
>
Good pointer = thanks Tom
> regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Denis BUCHER 2009-09-12 17:10:16 Re: How to GRANT rights to modify a table ???
Previous Message Tom Lane 2009-09-12 16:46:03 Re: primary keys