NULLIF()

Overview

Returns NULL or the first argument based on an equality comparison of the two arguments.

USAGE

NULLIF(value1, value2)

Argument Name

Description

value

The two values to compare

DETAILS

NULLIF() is a control flow function that returns a result based on the equality of the two arguments:

  • The return value is NULL if the two arguments are equal

  • The return value is the first argument if the two arguments are not equal

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

With Literal Values

In the following examples, NULLIF() is called with literal values:

SELECT NULLIF(1.0, 1.00) AS result;
+--------+
| result |
+--------+
|   NULL |
+--------+
SELECT NULLIF(42, 8) AS result;
+--------+
| result |
+--------+
|     42 |
+--------+

Example Schema and Data

Some of the examples are based on the example table contacts:

CREATE TABLE contacts (
  first_name VARCHAR(25),
  last_name VARCHAR(25),
  email VARCHAR(25),
  new_contact boolean
);
INSERT INTO contacts VALUES
  ('John', 'Smith', 'John.Smith@example.com', true),
  ('Jane', 'Smith', '', true),
  ('Joe', 'Smith', 'Joe.Smith@example.com', NULL);

Per-row Values

SELECT first_name, NULLIF(email, '')
 FROM contacts;
+------------+------------------------+
| first_name | NULLIF(email, '')      |
+------------+------------------------+
| John       | John.Smith@example.com |
| Jane       | NULL                   |
| Joe        | Joe.Smith@example.com  |
+------------+------------------------+

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