postgresqlHow can I generate an MD5 hash in PostgreSQL?
PostgreSQL provides a built-in function for generating MD5 hashes called md5()
. It takes a single argument, which can be either a text string or a bytea data type. To generate an MD5 hash of a text string, use the following syntax:
SELECT md5('MyTextString');
Output example
f2d6c7f6f1b556bb9aefef8c1e5cf149
The syntax for generating an MD5 hash from a bytea data type is as follows:
SELECT md5(BYTEA_COLUMN);
The md5()
function returns the generated MD5 hash as a 32-character hexadecimal string.
Code explanation
SELECT md5(
: This is the SQL command used to generate an MD5 hash.'MyTextString'
: This is the argument passed to themd5()
function, which in this case is a text string.BYTEA_COLUMN
: This is the argument passed to themd5()
function, which in this case is a bytea data type.
Helpful links
More of Postgresql
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL and ZFS together?
- How do I set the PostgreSQL work_mem parameter?
- How can I use PostgreSQL with YAML?
See more codes...