From 4b9d72210f0201efeafb9703e166aa3b38c04873 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Sun, 14 Jan 2018 22:00:16 +0100 Subject: Refs #28643 -- Added NullIf database function. Thanks Nick Pope, Mariusz Felisiak, and Tim Graham for reviews. --- docs/ref/databases.txt | 2 ++ docs/ref/models/database-functions.txt | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'docs/ref') diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt index 04214a6560..0c584f7110 100644 --- a/docs/ref/databases.txt +++ b/docs/ref/databases.txt @@ -899,6 +899,8 @@ occur when an Oracle datatype is used as a column name. In particular, take care to avoid using the names ``date``, ``timestamp``, ``number`` or ``float`` as a field name. +.. _oracle-null-empty-strings: + NULL and empty strings ---------------------- diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index f1affb2b6f..2661b65c78 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -149,6 +149,25 @@ will result in a database error. The PostgreSQL behavior can be emulated using ``Coalesce`` if you know a sensible maximum value to provide as a default. +``NullIf`` +---------- + +.. class:: NullIf(expression1, expression2) + +.. versionadded:: 2.2 + +Accepts two expressions and returns ``None`` if they are equal, otherwise +returns ``expression1``. + +.. admonition:: Caveats on Oracle + + Due to an :ref:`Oracle convention`, this + function returns the empty string instead of ``None`` when the expressions + are of type :class:`~django.db.models.CharField`. + + Passing ``Value(None)`` to ``expression1`` is prohibited on Oracle since + Oracle doesn't accept ``NULL`` as the first argument. + .. _date-functions: Date functions -- cgit v1.3