md5() 是一个系统函数,用于生成提供的字符串的 MD5 散列。该散列以 32 个十六进制字符的字符串形式返回。
md5() 在 PostgreSQL 7.4 中添加。
用法
md5 (text) →text
md5 (bytea) →text
请注意,在转换 bytea 字符串时,散列表示形式返回为 text,而 SHA-2 函数则以 bytea 的形式返回散列表示。
变更历史
- PostgreSQL 8.1
- PostgreSQL 7.4
- 添加(提交 e87e82d2)
示例
md5() 的基本用法示例
postgres=# SELECT md5('foo');
md5
----------------------------------
acbd18db4cc2f85cedef654fccc4a4d8
(1 row)
将 md5() 与 bytea 字符串一起使用
postgres=# SELECT md5(E'\\xDEADBEEF');
md5
----------------------------------
6c1ca46eb23735bba60f9bf05994b0a6
(1 row)
生成 bytea 形式的散列表示
postgres=# SELECT decode(md5(E'\\xDEADBEEF'), 'hex'); decode ------------------------------------ \x6c1ca46eb23735bba60f9bf05994b0a6 (1 row)
参考资料
- PostgreSQL 文档: 其他字符串函数
