Re: Storing a file hash as primary key - Mailing list pgsql-general

From Greg Stark
Subject Re: Storing a file hash as primary key
Date
Msg-id 87isf8rr12.fsf@stark.xeocode.com
Whole thread Raw
In response to Storing a file hash as primary key  (Eduardo Pérez Ureta <eperez@it.uc3m.es>)
Responses Re: Storing a file hash as primary key  (Joe Conway <mail@joeconway.com>)
List pgsql-general
Eduardo Pérez Ureta <eperez@it.uc3m.es> writes:

> I was wondering what the best way is to store a file hash (MD5 or SHA1)
> and make it primary key indexed.
> I have seen some people storing the hexadecimal encoded MD5 in a
> CHAR(32) but it may be a better idea to use a CHAR(16) without encoding
> the string, but that may cause some problems.

I would say either char(32) or bytea(16). Not char(16) since you don't want to
treat the raw binary data using any specific character encoding or sort it
according to any locale specific rules etc.

Personally I would have preferred bytea(16) but for some reason the php
drivers seem to jut drop NULL there when I try to store raw binary md5 hashes.
So for now I just declared it bytea with no length specification and store the
hex encoded hash.

If anyone knows how to get Pear::DB to store binary data in a bytea column, by
all means.

--
greg

pgsql-general by date:

Previous
From: Rick Gigger
Date:
Subject: Re: pgFoundry Open For Business
Next
From: Tom Lane
Date:
Subject: Re: Interpreting vacuum verbosity