MariaDB CRC32C() Function

In MariaDB, CRC32C() is a built-in numeric function that computes a cyclic redundancy check value and returns a 32-bit unsigned value.

Unlike CRC32(), CRC32C() uses Castagnoli polynomials.

MariaDB CRC32C() Syntax

Here is the syntax of the MariaDB CRC32C() function:

CRC32C([par,]str)

Parameters

str

Required. A string used for calculation. Non-string arguments will be treated as strings.

par

Optional. One computes the cyclic redundancy check value. Optional parameter to calculate checksums for segments.

If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CRC32C'

Return value

The MariaDB CRC32C() function is used to calculate the cyclic redundancy check value and returns a 32-bit unsigned value.

If any parameter is NULL, the CRC32C() function will return NULL.

MariaDB CRC32C() Examples

Basic example

To calculate the cyclic redundancy check value for Hello, use the following statement:

SELECT CRC32C('Hello');

Output:

+-----------------+
| CRC32C('Hello') |
+-----------------+
|      2178485787 |
+-----------------+

case sensitive

The cyclic redundancy check value is different for strings of different case:

SELECT
  CRC32C('Hello'),
  CRC32C('HELLO');

Output:

+-----------------+-----------------+
| CRC32C('Hello') | CRC32C('HELLO') |
+-----------------+-----------------+
|      2178485787 |      3901656152 |
+-----------------+-----------------+

non-string parameter

MariaDB CRC32C() will treat non-string arguments as strings:

SELECT
  CRC32C('1234'),
  CRC32C(1234);

Output:

+----------------+--------------+
| CRC32C('1234') | CRC32C(1234) |
+----------------+--------------+
|     4131058926 |   4131058926 |
+----------------+--------------+

Segmented computing

SELECT
  CRC32C('HelloWorld'),
  CRC32C(CRC32C('Hello'), 'World');

Output:

+----------------------+----------------------------------+
| CRC32C('HelloWorld') | CRC32C(CRC32C('Hello'), 'World') |
+----------------------+----------------------------------+
|           1407507230 |                       1407507230 |
+----------------------+----------------------------------+

In this example, we split HelloWorld into Hello and World, and calculate them piecewise. You can split it according to your needs, the result is the same, as follows:

SELECT CRC32C(CRC32C('He'), 'lloWorld');

Output:

+----------------------------------+
| CRC32C(CRC32C('He'), 'lloWorld') |
+----------------------------------+
|                       1407507230 |
+----------------------------------+

Conclusion

In MariaDB, CRC32C() is a built-in numeric function that computes a cyclic redundancy check value and returns a 32-bit unsigned value.