mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
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:
parent
3548d6a4bb
commit
d95d885bae
@ -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]
|
||||
----
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
;
|
||||
|
@ -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"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user