mirror of
https://github.com/django/django.git
synced 2025-11-28 06:30:00 +00:00
Refs #28643 -- Added NullIf database function.
Thanks Nick Pope, Mariusz Felisiak, and Tim Graham for reviews.
This commit is contained in:
parent
217f4456d8
commit
4b9d72210f
6 changed files with 78 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
|||
"""Database functions that do comparisons or type conversions."""
|
||||
from django.db.models.expressions import Func
|
||||
from django.db.models.expressions import Func, Value
|
||||
|
||||
|
||||
class Cast(Func):
|
||||
|
|
@ -103,3 +103,14 @@ class Least(Func):
|
|||
def as_sqlite(self, compiler, connection, **extra_context):
|
||||
"""Use the MIN function on SQLite."""
|
||||
return super().as_sqlite(compiler, connection, function='MIN', **extra_context)
|
||||
|
||||
|
||||
class NullIf(Func):
|
||||
function = 'NULLIF'
|
||||
arity = 2
|
||||
|
||||
def as_oracle(self, compiler, connection, **extra_context):
|
||||
expression1 = self.get_source_expressions()[0]
|
||||
if isinstance(expression1, Value) and expression1.value is None:
|
||||
raise ValueError('Oracle does not allow Value(None) for expression1.')
|
||||
return super().as_sql(compiler, connection, **extra_context)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue