md5(text) — Compute the MD5 digest of a string

Last updated: 2026-11-04

md5(text) — Compute the MD5 digest of a string

md5() returns the MD5 digest of the input as a fixed 32-character hexadecimal string. It is handy for cache keys, fingerprinting non-sensitive content and detecting whether data changed. MD5 is no longer collision resistant, so for password storage use crypt() with gen_salt() from the pgcrypto extension instead.

Kindfunction
Example LanguageSQL

📝 Syntax

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

⚙️ Parameters

string textThe string to digest; NULL is treated as an empty string. Type text.
string byteaThe binary data to digest. Type bytea.

Returns:text — a 32-character lower-case hex digest. Both the text and bytea variants return text (as of PG 18 the bytea variant no longer returns bytea).

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

 id | body        | md5_hash                         | hash_len
----+-------------+----------------------------------+----------
  1 | postgresql  | e4728f444b24839e3f80adf3829bcba9 |       32
  2 | hello world | 5eb63bbbe01eeed093cb22bb8f5acdc3 |       32
(2 rows)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow does md5() differ from digest() in pgcrypto?
Amd5() is built in and limited to MD5; digest(data, 'sha256') in pgcrypto supports the stronger SHA-2 family, but it requires CREATE EXTENSION pgcrypto first.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏