Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql: data type for md5 message digest?

I want to use the MD5 message digest of some string as the primary key of a table. What datatype should I use for such a field? What select and insert statements should I write for the field?

like image 467
象嘉道 Avatar asked Apr 13 '13 00:04

象嘉道


People also ask

What datatype is an MD5 hash?

MD5 is a one-way cryptographic hash function with a 128-bit hash value. MD5 returns a 32 character string of hexadecimal digits 0-9 & a-f and returns NULL if the input is a null value.

What is MD5 in Postgres?

MD5 is a cryptographic hash function used to generate a 32 character text string, a text hexadecimal value representation of a checksum of 128 bit. MD5 algorithm in PostgreSQL designed in 128 bit it is encryption algorithm in PostgreSQL designed to convert a string into 32 character text string.

What is _text data type in PostgreSQL?

PostgreSQL supports a character data type called TEXT. This data type is used to store character of unlimited length. It is represented as text in PostgreSQL. The performance of the varchar (without n) and text are the same. Syntax: variable_name TEXT.


1 Answers

bytea has a one byte overhead, but with padding to eight bytes this will result in significant wastage.

Instead, consider using the uuid type, which uses just 16 bytes. You'll have to use something like REPLACE(md5::text, '-', '') as md5 when selecting it, but that should be a quick operation.

like image 112
GreenReaper Avatar answered Sep 22 '22 08:09

GreenReaper