md5()

A function for generating an MD5 hash

md5() is a system function for generating the MD5 hash of the provided string. The hash is returned as a 32-character hexadecimal string.

md5() was added in PostgreSQL 7.4.

Usage

md5 ( text ) → text
md5 ( bytea ) → text

Note that when converting a bytea string, the hash representation is returned as text, whereas SHA-2 functions return the hash representation as bytea.

Change history

Examples

Basic usage example for md5():

postgres=# SELECT md5('foo');
               md5                
----------------------------------
 acbd18db4cc2f85cedef654fccc4a4d8
(1 row)

Using md5() with a bytea string:

postgres=# SELECT md5(E'\\xDEADBEEF');
               md5                
----------------------------------
 6c1ca46eb23735bba60f9bf05994b0a6
(1 row)

Generate the hash representation as bytea:

postgres=# SELECT decode(md5(E'\\xDEADBEEF'), 'hex');
               decode               
------------------------------------
 \x6c1ca46eb23735bba60f9bf05994b0a6
(1 row)

Categories

String manipulation, System function