jl6
jl6

Reputation: 6394

What is an efficient data type for storing a 32-byte hash value?

I understand that I can use a varchar(64) to hold the hex representation of the 32 bytes, but I imagine a bytea would be half the size, plus overhead. Are there any gotchas with bytea, or any more efficient way of storing the 32 bytes?

Upvotes: 4

Views: 2057

Answers (1)

Chris Travers
Chris Travers

Reputation: 26464

The largest issue with bytea is that decoding it on the client takes extra memory in most frameworks. This is probably not a big issue. It has a more efficient on-disk representation though.

As Craig noted in the comment the best type for this depends to a fair degree on what you are doing with it. I tend towards varchar because it is easiest to work with. bytea would work also however, and would save some disk space.

Upvotes: 2

Related Questions