Re: varchar as primary key

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: William Garrison <postgres(at)mobydisk(dot)com>
Cc: Matthew Hixson <hixson(at)poindextrose(dot)org>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: varchar as primary key
Date: 2007-05-03 18:25:02
Message-ID: 20070503182502.GJ4218@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

William Garrison wrote:
> I don't recommend it. There are better ways to store UUIDs:
>
> char(32) <-- Easy to work with, fixed length, inefficient
> varchar(32) <-- 4 bytes larger due to variable size
> bytea() <-- 20 bytes, variable length
> bit(128) <-- 16 bytes, optimal
>
> I don't like char() or varchar() because of case-senstivity and
> inefficiency.
>
> We used bytea, and created a small function byte2guid() and guid2byte()
> to handle converting to/from strings when working at a SQL prompt. But
> the production code doesn't use those. In retrospect, I would like to
> have tried BIT(128) since I think fixed-length columns perform better
> than variable-length columns.

FWIW, in Postgres, all those types are stored with the word length in
front of each datum. We don't use the column maximum length as a cue
for the storage of each individual datum. So the two first items you
list above are stored identically.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2007-05-03 18:26:27 Re: varchar as primary key
Previous Message William Garrison 2007-05-03 18:11:57 Re: varchar as primary key