Re: Drawbacks of using BYTEA for PK?

D. Dante Lorenso <dante@lorenso.com>

From: "D. Dante Lorenso" <dante@lorenso.com>
To: David Garamond <lists@zara.6.isreserved.com>
Cc: pgsql-general@postgresql.org
Date: 2004-01-11T22:05:15Z
Lists: pgsql-general
David Garamond wrote:

> Are there any drawbacks of using BYTEA for PK compared to using a 
> primitive/atomic data types like INT/SERIAL? (like significant 
> performance hit, peculiar FK behaviour, etc).
>
> I plan to use BYTEA for GUID (of course, temporarily I hope, until 
> PostgreSQL officially supports GUID data type), since it seems to be 
> the most convenient+compact compared to other data types currently 
> available. I use GUIDs for most PK columns.

GUID?  Isn't that really nothing more than an MD5 on a sequence?

    SELECT (MD5(NEXTVAL('my_table_seq'))) AS my_guid;

Since 7.4 has the md5 function built-in, there's your support ;-)
Now just add that to your table's trigger and your good to go.
I think in MS products, they format the guid with dashes in the
style 8-4-4-4-12 but it still looks to me like a 32 character hex
string or a 16 byte (128 bit) value.  You can choose to store the
value however you like, I'm not sure what would be optimal, but
bits are bits, right?

Dante