Re: varchar as primary key

From: William Garrison <postgres(at)mobydisk(dot)com>
To: Matthew Hixson <hixson(at)poindextrose(dot)org>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: varchar as primary key
Date: 2007-05-03 18:11:57
Message-ID: 463A25ED.3070006@mobydisk.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Matthew Hixson wrote:
> I'm investigating the usage of a UUID primary key generator using
> Hibernate and Postgres. The reason for using a UUID is that we will
> have an application hosted at different sites in different databases.
> We will need to aggregate the data back into a single database from time
> to time and we want to avoid PK collisions.
> Is there a significant performance difference between using int
> primary keys and string primary keys in Postgres?
> Thanks,
> -M@
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-05-03 18:25:02 Re: varchar as primary key
Previous Message Magnus Hagander 2007-05-03 17:16:17 Re: C functions under windows