PostgreSQL 18 reference · String Functions
PostgreSQL MD5() Function
Return the MD5 hash of a string as 32 hex characters. Fine for checksums, never for passwords.
PostgreSQL 18
Syntax
md5(string)
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
Return value
Text (32 hex digits).
Examples
SELECT md5('hello') AS hash;
Output
hash ---------------------------------- 5d41402abc4b2a76b9719d911017c592 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT name, left(md5(email), 8) AS email_key
FROM customers
WHERE email IS NOT NULL
LIMIT 2;
Output
name | email_key --------------+----------- Ada Lovelace | 3e3417d7 Alan Turing | f8982b84 (2 rows)
Run this on your computer — see “Get Started” for setup.
For security use sha256(convert_to(text, 'UTF8')) (PostgreSQL 11+), and store passwords with a slow hash
such as crypt() from the pgcrypto extension.
Related
- SQL String Functions · tutorial