CMP()

Overview

Returns -1, 0, or 1 indicating the order of two values.

USAGE

CMP(value, value)

Argument Name

Description

value

The two values to compare

DETAILS

CMP() is a function that returns -1, 0, or 1 to indicate the ordinality of two values.

If at least one argument is a number, a numeric comparison is performed. Thus, a string argument is converted into a number when paired with a numeric argument.

When both arguments are (non-NULL) strings, the result is the same as calling STRCMP(), including how the current sort order affects equality and ordinality.

The return value is 0 if the two arguments are equal.

The return value is -1 if the first argument sorts prior to the second.

The return value is 1 if the first argument sorts after the second.

A NULL argument sorts prior to any other non-NULL value. Two NULL arguments return 0 (equality).

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT    CMP(99, 123),
       STRCMP(99, 123);
+--------------+-----------------+
| CMP(99, 123) | STRCMP(99, 123) |
+--------------+-----------------+
|           -1 |               1 |
+--------------+-----------------+
-- Disable strict mode or the select might throw an error
SET sql_mode = '';
SELECT CMP('abc', 0);
+---------------+
| CMP('abc', 0) |
+---------------+
|             0 |
+---------------+
SELECT CMP(5, NULL), CMP(NULL, NULL);
+--------------+-----------------+
| CMP(5, NULL) | CMP(NULL, NULL) |
+--------------+-----------------+
|            1 |               0 |
+--------------+-----------------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES