SQL CRC32 function
Computes the 32-bit CRC checksum of a string, returned as an unsigned integer.
- Categoría
- Strings
- Returns
unsigned integer- In this category
- 127 of 172
Sintaxis
CRC32(string)
Soporte del motor
| Motor | Support | Notas |
|---|---|---|
| SQL Server | Not built in | No CRC32; CHECKSUM and BINARY_CHECKSUM use other algorithms. |
| PostgreSQL | Sí | crc32(bytea) and crc32c(bytea) from PostgreSQL 18; convert text with convert_to. |
| MySQL | Sí | Supported under this name. |
| SQLite | Not built in | No CRC32 built in. |
| Oracle | Not built in | No CRC32; ORA_HASH or STANDARD_HASH. |
Ejemplos
MySQL
SELECT CRC32('hello') AS checksum; -- 907060870
MySQL
SELECT * FROM documents WHERE CRC32(body) <> stored_crc;
PostgreSQL
SELECT crc32(convert_to(body, 'UTF8')) AS checksum FROM documents;
Conviene saberlo
- CRC32 detects accidental corruption, not deliberate tampering; it has no cryptographic strength.
- With 2^32 possible values, collisions become likely after about 77,000 distinct inputs (the birthday bound). Treat equal CRCs as a hint and compare the actual values.
- The result is an integer, so it indexes and compares cheaply; a classic use is a stored checksum column that flags changed text.
Questions about CRC32
Can CRC32 be used as a unique identifier?
No. Collisions are certain at scale; use it to spot likely changes and confirm with the full value.
What is the difference between CRC32 and CHECKSUM in SQL Server?
Different algorithms: CRC32 is the standard cyclic code over one string; SQL Server's CHECKSUM hashes an expression list. Their values never agree.
Does PostgreSQL have CRC32?
From PostgreSQL 18: crc32(bytea) gives the same value as MySQL's CRC32 for the same bytes (907060870 for 'hello'), and crc32c uses the Castagnoli polynomial.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, MySQL.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.