Re: Generic design: char vs varchar primary keys

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: raju(at)linux-delhi(dot)org
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Generic design: char vs varchar primary keys
Date: 2011-08-03 22:24:17
Message-ID: CAK3UJREnef=j-2RPZQ1pn_68EE_x7cRKVbTavPOCLZTN_jqN9A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

2011/8/3 Raj Mathur (राज माथुर) <raju(at)linux-delhi(dot)org>:
> Hi,
>
> Can you point me to any pages that explain the difference between using,
> say CHAR(8) vs VARCHAR(8) as the primary key for a table?  Is there any
> impact on the database in terms of:
>
> - Speed of indexed retrieval
> - Speed of join from a referencing table
> - Storage (I presume VARHAR(8) would have a slight edge, in general)
> - Any other issue

The docs have good info about the differences between these types:
http://www.postgresql.org/docs/current/static/datatype-character.html

I suspect the tiny size differences between char(8) and varchar(8) are
going to be negligible. In fact, this post talks precisely about this
concern, and more:
http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/

Personally I'd be most worried about the different semantics of the
types (i.e. treatment of trailing spaces), and perhaps the ease of
expanding the length constraint in the future.

Josh

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Raj Mathur ( राज =?utf-8?b?IOCkruCkvuCkpeClgeCksA==?=) 2011-08-04 01:58:25 Re: Generic design: char vs varchar primary keys
Previous Message Raj Mathur ( राज =?utf-8?b?IOCkruCkvuCkpeClgeCksA==?=) 2011-08-03 15:10:17 Generic design: char vs varchar primary keys