Re: IS it a good practice to use SERIAL as Primary Key? - Mailing list pgsql-general

From Sander Steffann
Subject Re: IS it a good practice to use SERIAL as Primary Key?
Date
Msg-id 000d01c70f2e$98803600$64c8a8c0@balefirehome
Whole thread Raw
In response to IS it a good practice to use SERIAL as Primary Key?  ("carter ck" <carterck32@hotmail.com>)
Responses Re: IS it a good practice to use SERIAL as Primary Key?  (Ron Johnson <ron.l.johnson@cox.net>)
List pgsql-general
Hi,

>> Sure, but the check digit does not need to be stored, as it can be
>> regenerated on demand. The user interface just verifies the check
>> digit, then throws it away.
>
> $ SET GEEZER
> $ WRITE SYS$OUTPUT "THAT'S JUST EXTRA CYCLES WASTED BY THE"
> $ WRITE SYS$OUTPUT "CLIENT.  BETTER TO USE THEM FOR SOME OTHER"
> $ WRITE SYS$OUTPUT "MORE PRODUCTIVE PURPOSE."
> $ SET NOGEEZER
>
> That's the VAX/VMS in me oozing out.  But seriously, regenerate it
> on demand???  That's not how it works.  This isn't a CRC or hash
> function.

Well, a check digit _is_ a kind of CRC. It is redundant information. For
every number there is only one correct check digit, which means that the
check digit does not add extra information to the number. So why store it?

You will need to add the check digit on most (all?) output that is
interpreted by humans. The software itself can just use the number itself
(assuming you don't need to check the integrity of the software).

If you store the number in the database, I would suggest making the db check
the number on all input too. Otherwise you might end up with invalid data in
the database.

- Sander



pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: IS it a good practice to use SERIAL as Primary Key?
Next
From: Alvaro Herrera
Date:
Subject: Re: COPY FROM : out of memory