SQL: Implement ISNULL(expr1, expr2) (#35793)

Add ISNULL as an alias of IFNULL as they have the
same behaviour. Add basic test and docs.

Closes: #35781
This commit is contained in:
Marios Trivyzas 2018-11-21 23:15:10 +01:00 committed by GitHub
parent 3548d6a4bb
commit d95d885bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 3 deletions

View File

@ -81,3 +81,40 @@ include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnFirst]
----
include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnSecond]
----
[[sql-functions-conditional-isnull]]
==== `ISNULL`
.Synopsis
[source, sql]
----
ISNULL ( expression<1>, expression<2> )
----
*Input*:
<1> 1st expression
<2> 2nd expression
*Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
.Description
Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
Returns the first of its arguments that is not null.
If all arguments are null, then it returns `null`.
["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[isNullReturnFirst]
----
["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[isNullReturnSecond]
----

View File

@ -21,7 +21,8 @@ SUM_OF_SQUARES |AGGREGATE
VAR_POP |AGGREGATE
COALESCE |CONDITIONAL
IFNULL |CONDITIONAL
DAY |SCALAR
ISNULL |CONDITIONAL
DAY |SCALAR
DAYNAME |SCALAR
DAYOFMONTH |SCALAR
DAYOFWEEK |SCALAR

View File

@ -198,7 +198,8 @@ SUM_OF_SQUARES |AGGREGATE
VAR_POP |AGGREGATE
COALESCE |CONDITIONAL
IFNULL |CONDITIONAL
DAY |SCALAR
ISNULL |CONDITIONAL
DAY |SCALAR
DAYNAME |SCALAR
DAYOFMONTH |SCALAR
DAYOFWEEK |SCALAR
@ -1553,3 +1554,25 @@ SELECT IFNULL(null, 'search') AS "ifnull";
search
// end::ifNullReturnSecond
;
isNullReturnFirst
// tag::isNullReturnFirst
SELECT ISNULL('elastic', null) AS "isnull";
isnull
---------------
elastic
// end::isNullReturnFirst
;
isNullReturnSecond
// tag::isNullReturnSecond
SELECT ISNULL(null, 'search') AS "isnull";
isnull
---------------
search
// end::isNullReturnSecond
;

View File

@ -146,7 +146,7 @@ public class FunctionRegistry {
// Scalar functions
// conditional
addToMap(def(Coalesce.class, Coalesce::new));
addToMap(def(IFNull.class, IFNull::new));
addToMap(def(IFNull.class, IFNull::new, "ISNULL"));
// Date
addToMap(def(DayName.class, DayName::new, "DAYNAME"),
def(DayOfMonth.class, DayOfMonth::new, "DAYOFMONTH", "DAY", "DOM"),