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]
|
||||
----
|
||||
|
||||
|
||||
[[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
|
||||
IFNULL |CONDITIONAL
|
||||
ISNULL |CONDITIONAL
|
||||
NVL |CONDITIONAL
|
||||
DAY |SCALAR
|
||||
DAYNAME |SCALAR
|
||||
DAYNAME |SCALAR
|
||||
DAYOFMONTH |SCALAR
|
||||
DAYOFWEEK |SCALAR
|
||||
DAYOFYEAR |SCALAR
|
||||
|
|
|
@ -199,8 +199,9 @@ VAR_POP |AGGREGATE
|
|||
COALESCE |CONDITIONAL
|
||||
IFNULL |CONDITIONAL
|
||||
ISNULL |CONDITIONAL
|
||||
NVL |CONDITIONAL
|
||||
DAY |SCALAR
|
||||
DAYNAME |SCALAR
|
||||
DAYNAME |SCALAR
|
||||
DAYOFMONTH |SCALAR
|
||||
DAYOFWEEK |SCALAR
|
||||
DAYOFYEAR |SCALAR
|
||||
|
@ -1555,7 +1556,6 @@ search
|
|||
// end::ifNullReturnSecond
|
||||
;
|
||||
|
||||
|
||||
isNullReturnFirst
|
||||
// tag::isNullReturnFirst
|
||||
SELECT ISNULL('elastic', null) AS "isnull";
|
||||
|
@ -1576,3 +1576,24 @@ SELECT ISNULL(null, 'search') AS "isnull";
|
|||
search
|
||||
// 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
|
||||
// conditional
|
||||
addToMap(def(Coalesce.class, Coalesce::new));
|
||||
addToMap(def(IFNull.class, IFNull::new, "ISNULL"));
|
||||
addToMap(def(IFNull.class, IFNull::new, "ISNULL", "NVL"));
|
||||
// Date
|
||||
addToMap(def(DayName.class, DayName::new, "DAYNAME"),
|
||||
def(DayOfMonth.class, DayOfMonth::new, "DAYOFMONTH", "DAY", "DOM"),
|
||||
|
|
Loading…
Reference in New Issue