Compute the CRC-32 checksum of a string as a non-negative 32-bit integer.
CRC32(expr)
## Overview Computes the CRC-32 (Cyclic Redundancy Check, 32-bit) of the input string and returns the result as a non-negative BIGINT (to fit the 32-bit unsigned range). CRC-32 is a fast, deterministic checksum widely used for link-layer and storage-layer integrity checks. CRC-32 is not cryptographically secure. Collisions are trivial to construct, so do not use it for authentication or tamper detection. Use it for distribution, bucketing, and quick change detection where accidental collisions are acceptable. ## Behavior - Returns NULL for NULL input. - Output is a 32-bit unsigned value represented as BIGINT (0 to 4,294,967,295). - Empty input returns 0. - Deterministic across calls with the same input. - String inputs are hashed as their UTF-8 byte sequence. ## Algorithm - CRC-32 with the polynomial 0xEDB88320 (reversed representation of 0x04C11DB7), as used in IEEE 802.3 and in widely deployed archive formats. - Output width: 32 bits. ## Compatibility - Matches the CRC-32 variant used by ZIP, Ethernet, and PNG (IEEE polynomial). Other CRC-32 variants (for example CRC-32C used in iSCSI) produce different values; do not interchange.
| Name | Type | Description |
|---|---|---|
expr | Specifies the string value to checksum. The string is hashed as its UTF-8 byte sequence. Returns NULL for NULL input. |
-- CRC-32 of a simple string
SELECT CRC32('hello') AS c;
-- Empty input yields 0
SELECT CRC32('') AS c; -- 0
-- Different strings produce different checksums
SELECT CRC32('abc') AS c1, CRC32('abd') AS c2;
-- Realistic: quick fingerprint for change detection
SELECT row_id, CRC32(CONCAT(col_a, '|', col_b)) AS fingerprint
FROM ingestion.staging.daily_rows;
-- Bucketed distribution
SELECT CRC32(user_id) % 16 AS bucket, COUNT(*)
FROM iam.directory.users
GROUP BY bucket;