md5

Returns the MD5 digest of a string.

Syntax

md5(<string>)

Arguments

ArgumentTypeDescription
<string>stringString to hash.

Returns

Returns string containing 32 lowercase hexadecimal characters. Returns NULL if the input is NULL.

Examples

Create a content fingerprint for exported records. Identical text receives the same fingerprint.

VALUES
    ('evt-17', 'order=o-17 status=paid'),
    ('evt-18', 'order=o-17 status=paid'),
    ('evt-19', 'order=o-42 status=paid')
SELECT $0 AS event_id, $1 AS record
SELECT event_id, md5(record) AS fingerprint
+----------+----------------------------------+
| event_id | fingerprint                      |
+----------+----------------------------------+
| evt-17   | 5b91e13c95e7ccf1863c51b384e54491 |
| evt-18   | 5b91e13c95e7ccf1863c51b384e54491 |
| evt-19   | 99b338711fc1f1c6f6fdf2dc846204a3 |
+----------+----------------------------------+

Different JSON formatting produces different hashes even when the values are equivalent. MD5 hashes can also collide; use them as a comparison aid, not a unique record ID.