Compute the SHA-512 hash of a string and return it as a 128-character lowercase hexadecimal string.
SHA512(str)
## Overview Computes the SHA-512 cryptographic hash of the UTF-8-encoded input string and returns the digest as a lowercase hexadecimal string. SHA-512 is the widest member of the SHA-2 family in common use, producing a 512-bit (64-byte) digest. Use SHA-512 when your compliance or security model requires the longest SHA-2 output, or when your platform performs SHA-512 faster than SHA-256 (which is the case on most 64-bit CPUs). ## Algorithm and output - Returns a 128-character lowercase hexadecimal string (`[0-9a-f]`). - The digest is 512 bits (64 bytes) long. - Provides the highest collision and preimage resistance in the SHA-2 family. - Compare digests hex-for-hex; direct equality with `=` is collation-safe because the output is ASCII. ## Behavior - Returns NULL if the input is NULL. - Deterministic: equal inputs produce equal outputs. - Side effect free. - Hashes the UTF-8 encoding of the input string. ## Compatibility - PG-compat alias for the standard SHA-512 primitive.
| Name | Type | Description |
|---|---|---|
str | Specifies the input string to hash. The input is hashed as its UTF-8 byte representation. |
-- Hash a literal
SELECT SHA512('hello');
-- High-security fingerprinting (regulatory audit)
SELECT record_id, SHA512(CONCAT_WS('|', ssn, dob)) AS audit_hash
FROM reg.catalog.sensitive_records;
-- Equal inputs produce equal digests
SELECT SHA512('test') = SHA512('test') AS same; -- true
-- NULL propagation
SELECT SHA512(NULL); -- NULL