Hi Radomir,
On 12/17/2014 09:56 AM, Radomir Wojcik wrote:
> The official django doc uses this as an example (see below). Is there any
> point to storing 'FR' instead of 'Freshman" so the choice matches what is
> stored? Is it faster at all? Saves room? What about for querying the data?
> Then you have to lookup the symbol 'FR' in the tuple if someone wants to
> query by 'Freshman'.
>
> What is the best practice? Is it even more efficient if integers were used,
> like 1 value to represent Freshman and so on? To me it makes sense to store
> 'Freshman' as 'Freshman' but I'd like to get some insight.
I'm no expert on database performance (and what I do know is entirely
specific to Postgres), but I think that a shorter string will be
somewhat more efficient (both in terms of space and speed) than a longer
string, and an integer more efficient than either. However, I'd consider
worrying about that to be premature optimization, unless you have
evidence of it being a problem.
For me the two primary considerations here are:
1) It is useful to separate the database-stored value from the displayed
representation for humans, because the latter is prone to change (in a
sense this is a normalization, so the real name is only stored in one
place, not in various rows throughout your table).
2) I find some ease-of-development value in using a text slug rather
than an integer for the database-stored value, simply because it makes
database rows more readable when working with the database directly.
Carl