Re: IS it a good practice to use SERIAL as Primary Key?

From: Scott Ribe <scott_ribe(at)killerbytes(dot)com>
To: Brandon Aiken <BAiken(at)winemantech(dot)com>, pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: IS it a good practice to use SERIAL as Primary Key?
Date: 2006-11-27 22:32:34
Message-ID: C190B592.5C2C5%scott_ribe@killerbytes.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Shenanigans!
>
> That problem occurs regardless of whether or not you use surrogate keys.
> You have exceeded the scope of the example.

Yes the "problem occurs" in that this is something that needs to be tracked,
but the suggested schema presents peculiar problems for what otherwise is a
pretty simple thing.

Reasonable solution: every address is kept, so each address is a row in an
address table, with its own id. Shipment rows simply record the id of the
address current at the time of shipment. The user row simply records the id
of the most-recent address as the now-current one. That's rational.

But if you use the address id as part of the user's primary key, well now
you have a primary key that keeps changing as users move. On the other hand,
if you don't change the address key but the contents of the address row
itself, in order to preserve this bizarre notion of primary key, you have to
keep a copy somewhere of the same address with a different id in order to
use that for shipments.

>> You would update the address, the address id wouldn't change. If you
>> want to keep track of old addresses you would keep an archive table
>> associated with the user.id.
>
> But what about historical data that referenced the address? If you move
> today, I still want to know where I shipped last week's orders.

--
Scott Ribe
scott_ribe(at)killerbytes(dot)com
http://www.killerbytes.com/
(303) 722-0567 voice

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2006-11-27 22:36:36 Re: IS it a good practice to use SERIAL as Primary Key?
Previous Message Alvaro Herrera 2006-11-27 22:22:33 Re: fatal error on 8.1 server