SQL: Implement NVL(expr1, expr2) (#35794)
Add NVL as alias to IFNULL as they have the same behaviour. Add basic tests and docs. Closes: #35782
This commit is contained in:
parent
11052b75c7
commit
92acf47c16
|
@ -118,3 +118,40 @@ include-tagged::{sql-specs}/docs.csv-spec[isNullReturnFirst]
|
||||||
----
|
----
|
||||||
include-tagged::{sql-specs}/docs.csv-spec[isNullReturnSecond]
|
include-tagged::{sql-specs}/docs.csv-spec[isNullReturnSecond]
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[[sql-functions-conditional-nvl]]
|
||||||
|
==== `NVL`
|
||||||
|
|
||||||
|
.Synopsis
|
||||||
|
[source, sql]
|
||||||
|
----
|
||||||
|
NVL ( 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[nvlReturnFirst]
|
||||||
|
----
|
||||||
|
|
||||||
|
["source","sql",subs="attributes,callouts,macros"]
|
||||||
|
----
|
||||||
|
include-tagged::{sql-specs}/docs.csv-spec[nvlReturnSecond]
|
||||||
|
----
|
||||||
|
|
|
@ -22,8 +22,9 @@ VAR_POP |AGGREGATE
|
||||||
COALESCE |CONDITIONAL
|
COALESCE |CONDITIONAL
|
||||||
IFNULL |CONDITIONAL
|
IFNULL |CONDITIONAL
|
||||||
ISNULL |CONDITIONAL
|
ISNULL |CONDITIONAL
|
||||||
|
NVL |CONDITIONAL
|
||||||
DAY |SCALAR
|
DAY |SCALAR
|
||||||
DAYNAME |SCALAR
|
DAYNAME |SCALAR
|
||||||
DAYOFMONTH |SCALAR
|
DAYOFMONTH |SCALAR
|
||||||
DAYOFWEEK |SCALAR
|
DAYOFWEEK |SCALAR
|
||||||
DAYOFYEAR |SCALAR
|
DAYOFYEAR |SCALAR
|
||||||
|
|
|
@ -199,8 +199,9 @@ VAR_POP |AGGREGATE
|
||||||
COALESCE |CONDITIONAL
|
COALESCE |CONDITIONAL
|
||||||
IFNULL |CONDITIONAL
|
IFNULL |CONDITIONAL
|
||||||
ISNULL |CONDITIONAL
|
ISNULL |CONDITIONAL
|
||||||
|
NVL |CONDITIONAL
|
||||||
DAY |SCALAR
|
DAY |SCALAR
|
||||||
DAYNAME |SCALAR
|
DAYNAME |SCALAR
|
||||||
DAYOFMONTH |SCALAR
|
DAYOFMONTH |SCALAR
|
||||||
DAYOFWEEK |SCALAR
|
DAYOFWEEK |SCALAR
|
||||||
DAYOFYEAR |SCALAR
|
DAYOFYEAR |SCALAR
|
||||||
|
@ -1555,7 +1556,6 @@ search
|
||||||
// end::ifNullReturnSecond
|
// end::ifNullReturnSecond
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
isNullReturnFirst
|
isNullReturnFirst
|
||||||
// tag::isNullReturnFirst
|
// tag::isNullReturnFirst
|
||||||
SELECT ISNULL('elastic', null) AS "isnull";
|
SELECT ISNULL('elastic', null) AS "isnull";
|
||||||
|
@ -1576,3 +1576,24 @@ SELECT ISNULL(null, 'search') AS "isnull";
|
||||||
search
|
search
|
||||||
// end::isNullReturnSecond
|
// end::isNullReturnSecond
|
||||||
;
|
;
|
||||||
|
|
||||||
|
nvlReturnFirst
|
||||||
|
// tag::nvlReturnFirst
|
||||||
|
SELECT NVL('elastic', null) AS "nvl";
|
||||||
|
|
||||||
|
nvl
|
||||||
|
---------------
|
||||||
|
elastic
|
||||||
|
// end::nvlReturnFirst
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
nvlReturnSecond
|
||||||
|
// tag::nvlReturnSecond
|
||||||
|
SELECT NVL(null, 'search') AS "nvl";
|
||||||
|
|
||||||
|
nvl
|
||||||
|
---------------
|
||||||
|
search
|
||||||
|
// end::nvlReturnSecond
|
||||||
|
;
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class FunctionRegistry {
|
||||||
// Scalar functions
|
// Scalar functions
|
||||||
// conditional
|
// conditional
|
||||||
addToMap(def(Coalesce.class, Coalesce::new));
|
addToMap(def(Coalesce.class, Coalesce::new));
|
||||||
addToMap(def(IFNull.class, IFNull::new, "ISNULL"));
|
addToMap(def(IFNull.class, IFNull::new, "ISNULL", "NVL"));
|
||||||
// Date
|
// Date
|
||||||
addToMap(def(DayName.class, DayName::new, "DAYNAME"),
|
addToMap(def(DayName.class, DayName::new, "DAYNAME"),
|
||||||
def(DayOfMonth.class, DayOfMonth::new, "DAYOFMONTH", "DAY", "DOM"),
|
def(DayOfMonth.class, DayOfMonth::new, "DAYOFMONTH", "DAY", "DOM"),
|
||||||
|
|
Loading…
Reference in New Issue