Re: When to use name verses id - Mailing list pgsql-novice

From Tom Lane
Subject Re: When to use name verses id
Date
Msg-id 2491.1012838416@sss.pgh.pa.us
Whole thread Raw
In response to When to use name verses id  (Lewis Bergman <lbergman@abi.tconline.net>)
Responses Re: When to use name verses id  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-novice
Lewis Bergman <lbergman@abi.tconline.net> writes:
> Do I even need an id column if I make the name column unique?

You could dispense with an ID column (and IMHO should do so) if you can
*guarantee* that the name column will always be unique.  In a lot of
practical situations that falls down --- eg, you'd be foolish to assume
that a company will never have two employees named Tom Lane.

The main reason people tend to use arbitrarily-assigned ID values is so
they can be certain of having a unique primary key for the table, even
when the other identifying info turns out to be less unique than it
might at first seem.

Integer IDs are probably also more compact and faster to compare than
strings, but this effect is not so strong that it should govern your
decisions.  If you don't really need an ID column, I think you're
better off without one.

            regards, tom lane

pgsql-novice by date:

Previous
From: Lewis Bergman
Date:
Subject: When to use name verses id
Next
From: "Josh Berkus"
Date:
Subject: Re: limit of 16 on arguments to functons