From a7310f9eb9b2b3cbea4c71ea4c93ed9ed6f4f38d Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Wed, 3 Dec 2025 14:54:17 +0530 Subject: [PATCH 01/10] Use function template --- .../n1ql-language-reference/condfunnum.adoc | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index 8b3c9a4aa..dffc435ca 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -2,8 +2,29 @@ :description: Conditional functions evaluate expressions to determine if the values and formulas meet the specified condition. :page-topic-type: reference + +[abstract] {description} +== IFINF + +=== Description + +Returns the first non-missing, non-infinite number from a list of expressions. +If a non-number input is encountered first, it returns MISSING or NULL. + +=== Syntax + +[subs=normal] +.... +IFINF(expression1, expression2, ...) +.... + + + + + + IFINF(expression1, expression2, \...) Returns first non-MISSING, non-Inf number. From 66c77f9e07afb5c2c261a3ca425410f676385539 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 4 Dec 2025 10:04:40 +0530 Subject: [PATCH 02/10] Update content --- .../n1ql-language-reference/condfunnum.adoc | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index dffc435ca..ef4a6f735 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -10,8 +10,10 @@ === Description -Returns the first non-missing, non-infinite number from a list of expressions. -If a non-number input is encountered first, it returns MISSING or NULL. +Returns the first non-missing, non-infinite number (Inf or -Inf) from a list of expressions. +Inf is positive infinity, whereas -Inf is negative infinity. + +If the function encounters a non-number input first, it returns NULL. === Syntax @@ -20,6 +22,37 @@ If a non-number input is encountered first, it returns MISSING or NULL. IFINF(expression1, expression2, ...) .... +==== Arguments + +expression1, expression2, ...:: +A list of valid expressions to evaluate. + +=== Return Value + +The function returns: + +* The first non-MISSING, non-Inf number. +* MISSING or NULL if a non-number input is encountered first. + +=== Examples + +.Find a non-infinite number from a list of numbers +==== + +.Query +[source,sqlpp] +---- +SELECT IFINF(MISSING, Inf, -Inf, 42, 100) AS result +---- +.Result +[source,json] +---- +{ + "result": 42 +} +---- +==== + From 5e9fcc41613385e52e04cb120b20dbc3cd54df1a Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Fri, 5 Dec 2025 10:00:49 +0530 Subject: [PATCH 03/10] Update content --- .../n1ql-language-reference/condfunnum.adoc | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index ef4a6f735..cf5d7e3a8 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -42,7 +42,7 @@ The function returns: .Query [source,sqlpp] ---- -SELECT IFINF(MISSING, Inf, -Inf, 42, 100) AS result +SELECT IFINF(42, NULL, 100) AS result ---- .Result [source,json] @@ -53,6 +53,42 @@ SELECT IFINF(MISSING, Inf, -Inf, 42, 100) AS result ---- ==== +.Find distance covered, ignoring infinite values +==== +.Query +[source,sqlpp] +---- +SELECT airline, IFINF(distance, -1, 100) AS distance_covered +FROM `travel-sample`.`inventory`.route +WHERE type = "route" +LIMIT 5; +---- +.Result +[source,json] +---- +[{ + "airline": "AF", + "distance_covered": 2881.617376098415 + }, + { + "airline": "AF", + "distance_covered": 2735.2013399811754 + }, + { + "airline": "AF", + "distance_covered": 8748.296323466084 + }, + { + "airline": "AF", + "distance_covered": 654.9546621929924 + }, + { + "airline": "AF", + "distance_covered": 9442.50092891188 + } +] +---- +==== From 4d5c791dfe27206e6efe4454308b942bb4f3e6ed Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 11 Dec 2025 14:10:05 +0530 Subject: [PATCH 04/10] Update content --- .../n1ql-language-reference/condfunnum.adoc | 146 ++++++++---------- 1 file changed, 67 insertions(+), 79 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index cf5d7e3a8..6f830f731 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -6,35 +6,29 @@ [abstract] {description} -== IFINF +== IFINF (`expr1`, `expr2`, ...) -=== Description - -Returns the first non-missing, non-infinite number (Inf or -Inf) from a list of expressions. -Inf is positive infinity, whereas -Inf is negative infinity. +This function has a synonym `IF_INF()`. -If the function encounters a non-number input first, it returns NULL. +=== Description -=== Syntax +Evaluates a list of expressions and returns the first non-infinite number. -[subs=normal] -.... -IFINF(expression1, expression2, ...) -.... +The function skips `MISSING` and infinite values such as `Inf` and `-Inf`. +If it encounters `NULL` or any other non-number before finding a finite number, the function returns `NULL`. -==== Arguments +=== Arguments -expression1, expression2, ...:: +expr1, expr2, ...:: A list of valid expressions to evaluate. +You must specify at least 2 expressions. === Return Value -The function returns: +* A finite number. +* `NULL` if the function encounters a non-number input before finding a finite number. -* The first non-MISSING, non-Inf number. -* MISSING or NULL if a non-number input is encountered first. - -=== Examples +=== Example .Find a non-infinite number from a list of numbers ==== @@ -42,84 +36,78 @@ The function returns: .Query [source,sqlpp] ---- -SELECT IFINF(42, NULL, 100) AS result +SELECT IFINF(5, 10, 20), + IFINF(10, NULL, 20), + IFINF(NULL, 10, 20), + IFINF(MISSING, 20, NULL), + IFINF(MISSING, NULL, 10, 20), + IFINF(1e400, -1e400, 10, 20); ---- + .Result [source,json] ---- -{ - "result": 42 -} +[ + { + "$1": 5, + "$2": 10, + "$3": null, + "$4": 20, + "$5": null, + "$6": 10 + } +] ---- +In SQL++, `1e400` is equivalent to `Inf` (positive infinity) and `-1e400` is equivalent to `-Inf` (negative infinity). ==== -.Find distance covered, ignoring infinite values +== IFNAN(`expr1`, `expr2`, ...) + +This function has a synonym `IF_NAN()`. + +=== Description + +Evaluates a list of expressions and returns the first non-NaN (Not a Number). + +The function skips `MISSING` values. +If it encounters `NULL` or any other non-number before finding a valid number, the function returns `NULL`. + +=== Arguments + +expr1, expr2, ...:: +A list of valid expressions to evaluate. +You must specify at least 2 expressions. + +=== Return Value +* A valid number that is not `NaN`. +* `NULL` if the function encounters a non-number input before finding a valid number. + +=== Example +.Find a non-NaN number from a list of numbers ==== .Query [source,sqlpp] ---- -SELECT airline, IFINF(distance, -1, 100) AS distance_covered -FROM `travel-sample`.`inventory`.route -WHERE type = "route" -LIMIT 5; +SELECT IFNAN(3.14, 2.71, NaN), + IFNAN(NaN, NULL, 2.71), + IFNAN(NULL, 3.14, NaN), + IFNAN(MISSING, NaN, NULL), + IFNAN(MISSING, NULL, 3.14, NaN), + IFNAN(NaN, NaN, 2.71, 3.14); ---- .Result [source,json] ---- -[{ - "airline": "AF", - "distance_covered": 2881.617376098415 - }, - { - "airline": "AF", - "distance_covered": 2735.2013399811754 - }, - { - "airline": "AF", - "distance_covered": 8748.296323466084 - }, +[ { - "airline": "AF", - "distance_covered": 654.9546621929924 - }, - { - "airline": "AF", - "distance_covered": 9442.50092891188 + "$1": 3.14, + "$2": 2.71, + "$3": null, + "$4": null, + "$5": null, + "$6": 2.71 } ] ---- +In SQL++, `NaN` represents a value that is "Not a Number". ==== - - - - - -IFINF(expression1, expression2, \...) - -Returns first non-MISSING, non-Inf number. -Returns MISSING or NULL if a non-number input is encountered first. - -IFNAN(expression1, expression2, \...) - -Returns first non-MISSING, non-NaN number. -Returns MISSING or NULL if a non-number input is encountered first. - -IFNANORINF(expression1, expression2, \...) - -Returns first non-MISSING, non-Inf, or non-NaN number. -Returns MISSING or NULL if a non-number input is encountered first. - -NANIF(expression1, expression2) - -Returns NaN if expression1 = expression2, otherwise returns expression1. -Returns MISSING or NULL if either input is MISSING or NULL. - -NEGINFIF(expression1, expression2) - -Returns NegInf if expression1 = expression2, otherwise returns expression1. -Returns MISSING or NULL if either input is MISSING or NULL. - -POSINFIF(expression1, expression2) - -Returns PosInf if expression1 = expression2, otherwise returns expression1. -Returns MISSING or NULL if either input is MISSING or NULL. From eb3d8fdb1c2cfd7d8d35e566574bb1d1c753b847 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 18 Dec 2025 13:24:40 +0530 Subject: [PATCH 05/10] Update conditional functions --- .../n1ql-language-reference/condfunnum.adoc | 282 +++++++++++++++--- 1 file changed, 246 insertions(+), 36 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index 6f830f731..783717144 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -12,36 +12,39 @@ This function has a synonym `IF_INF()`. === Description -Evaluates a list of expressions and returns the first non-infinite number. +Evaluates a list of expressions and returns the first finite number. -The function skips `MISSING` and infinite values such as `Inf` and `-Inf`. -If it encounters `NULL` or any other non-number before finding a finite number, the function returns `NULL`. +The function ignores `MISSING` and infinite values. +If it encounters `NULL` or any non-numeric value before finding a finite number, the function returns `NULL`. === Arguments expr1, expr2, ...:: -A list of valid expressions to evaluate. +A list of expressions to evaluate. You must specify at least 2 expressions. === Return Value -* A finite number. -* `NULL` if the function encounters a non-number input before finding a finite number. +The function returns one of the following: + +* The first finite number. +* `NULL` if it encounters `NULL` or a non-number before finding a finite number. === Example -.Find a non-infinite number from a list of numbers +.Find the 1st non-infinite number from a list of numbers ==== .Query [source,sqlpp] ---- SELECT IFINF(5, 10, 20), - IFINF(10, NULL, 20), - IFINF(NULL, 10, 20), - IFINF(MISSING, 20, NULL), - IFINF(MISSING, NULL, 10, 20), - IFINF(1e400, -1e400, 10, 20); + IFINF(5, NULL, 10), + IFINF(inf(), -inf(), 5, 10), + IFINF(POWER(10, 400), 5, 10), + IFINF(NULL, 5, 10), + IFINF(MISSING, 5, NULL), + IFINF(MISSING, NULL, 5, 10); ---- .Result @@ -50,15 +53,17 @@ SELECT IFINF(5, 10, 20), [ { "$1": 5, - "$2": 10, - "$3": null, - "$4": 20, + "$2": 5, + "$3": 5, + "$4": 5, "$5": null, - "$6": 10 + "$6": 5, + "$7": null } ] ---- -In SQL++, `1e400` is equivalent to `Inf` (positive infinity) and `-1e400` is equivalent to `-Inf` (negative infinity). +The functions `inf()` and `-inf()` return positive and negative infinity, respectively. +Also, the expression `POWER(10, 400)` results in positive infinity because it exceeds the maximum representable finite number. ==== == IFNAN(`expr1`, `expr2`, ...) @@ -67,9 +72,9 @@ This function has a synonym `IF_NAN()`. === Description -Evaluates a list of expressions and returns the first non-NaN (Not a Number). +Evaluates a list of expressions and returns the first non-NaN (Not a Number), that is, a valid number. -The function skips `MISSING` values. +The function ignores `MISSING` and NaN values. If it encounters `NULL` or any other non-number before finding a valid number, the function returns `NULL`. === Arguments @@ -79,8 +84,11 @@ A list of valid expressions to evaluate. You must specify at least 2 expressions. === Return Value -* A valid number that is not `NaN`. -* `NULL` if the function encounters a non-number input before finding a valid number. + +The function returns one of the following: + +* The first valid number. +* `NULL` if it encounters `NULL` or a non-number before finding a number. === Example .Find a non-NaN number from a list of numbers @@ -88,26 +96,228 @@ You must specify at least 2 expressions. .Query [source,sqlpp] ---- -SELECT IFNAN(3.14, 2.71, NaN), - IFNAN(NaN, NULL, 2.71), - IFNAN(NULL, 3.14, NaN), - IFNAN(MISSING, NaN, NULL), - IFNAN(MISSING, NULL, 3.14, NaN), - IFNAN(NaN, NaN, 2.71, 3.14); +SELECT IFNAN(5, 10, 20, nan()), + IFNAN("abc", 5, NULL, 10), + IFNAN(NULL, 5, 10), + IFNAN(MISSING, 5, NULL), + IFNAN(MISSING, NULL, 5, 10), + IFNAN(nan(), 5, 10); +---- +.Result +[source,json] +---- +[ + { + "$1": 5, + "$2": null, + "$3": null, + "$4": 5, + "$5": null, + "$6": 5 + } +] +---- +The function `nan()` returns a NaN value. +==== + + +== IFNANORINF(`expr1`, `expr2`, ...) + +This function has a synonym `IF_NAN_OR_INF()`. + +=== Description + +Evaluates a list of expressions and returns the first number that is neither NaN (Not a Number) nor infinite. + +The function skips `MISSING`, NaN, and infinite values. +If it encounters `NULL` or any other non-number before finding a valid number, the function returns `NULL`. + +=== Arguments + +expr1, expr2, ...:: +A list of valid expressions to evaluate. +You must specify at least 2 expressions. + +=== Return Value + +The function returns one of the following: + +* The first number that is neither NaN nor infinite. +* `NULL` if it encounters `NULL` or a non-number before finding such a number. + +=== Example + +.Find a number that is neither NaN nor infinite from a list of numbers +==== +.Query +[source,sqlpp] +---- +SELECT IFNANORINF(5, 10, nan(), inf()), + IFNANORINF("abc", 5, NULL, 10), + IFNANORINF(NULL, 5, 10), + IFNANORINF(MISSING, 5, NULL), + IFNANORINF(MISSING, NULL, 5, 10), + IFNANORINF(nan(), -inf(), 5, 10); +---- +.Result +[source,json] +---- +[ + { + "$1": 5, + "$2": null, + "$3": null, + "$4": 5, + "$5": null, + "$6": 5 + } +] +---- +The function `nan()` returns a NaN value, and the functions `inf()` and `-inf()` return positive and negative infinity, respectively. +==== + +== NANIF(`expr1`, `expr2`) + +This function has a synonym `NAN_IF()`. + +=== Description + +Compares two expressions and returns `NaN` (Not a Number) if they are equal; otherwise, it returns the value of the first expression. + +=== Arguments + +expr1:: +A valid expression. + +expr2:: +A valid expression to compare with `expr1`. + +=== Return Value + +The function returns one of the following: + +* `NaN` if `expr1` is equal to `expr2`. +* `expr1` if the expressions are not equal. +* `NULL` if either expression is `MISSING` or `NULL`. + +=== Example +.Compare two numbers and return NaN if they are equal +==== +.Query +[source,sqlpp] +---- +SELECT NANIF(10, 10) AS nan_equal, + NANIF(10, 5) AS nan_not_equal, + NANIF(NULL, 5) AS nan_null; +---- +.Result +[source,json] +---- +[ + { + "nan_equal": "NaN", + "nan_not_equal": 10, + "nan_null": null + } +] ---- +==== + +== NEGINFIF(`expr1`, `expr2`) + +This function has a synonym `NEGINF_IF()`. + +=== Description + +Compares two expressions and returns negative infinity if they are equal; otherwise, it returns the value of the first expression. + +=== Arguments + +expr1:: +A valid expression. + +expr2:: +A valid expression to compare with `expr1`. + +=== Return Value + +The function returns one of the following: + +* `-Infinity` if `expr1` is equal to `expr2`. +* `expr1` if the expressions are not equal. +* `NULL` if either expression is `MISSING` or `NULL`. + +=== Example + +.Compare two numbers and return negative infinity if they are equal +==== +.Query +[source,sqlpp] +---- +SELECT NEGINFIF(10, 10) AS neg_inf_equal, + NEGINFIF(10, 5) AS neg_inf_not_equal, + NEGINFIF(NULL, 5) AS neg_inf_null; +---- + .Result [source,json] ---- [ - { - "$1": 3.14, - "$2": 2.71, - "$3": null, - "$4": null, - "$5": null, - "$6": 2.71 - } + { + "neg_inf_equal": "-Infinity", + "neg_inf_not_equal": 10, + "neg_inf_null": null + } +] +---- +==== + +== POSINFIF(`expr1`, `expr2`) + +This function has a synonym `POSINF_IF()`. + +=== Description + +Compares two expressions and returns positive infinity if they are equal; otherwise, it returns the value of the first expression. + +=== Arguments + +expr1:: +A valid expression. + +expr2:: +A valid expression to compare with `expr1`. + +=== Return Value + +The function returns one of the following: + +* `+Infinity` if `expr1` is equal to `expr2`. +* `expr1` if the expressions are not equal. +* `NULL` if either expression is `MISSING` or `NULL`. + +=== Example + +.Compare two numbers and return positive infinity if they are equal +==== + +.Query +[source,sqlpp] +---- +SELECT POSINFIF(10, 10) AS pos_inf_equal, + POSINFIF(10, 5) AS pos_inf_not_equal, + POSINFIF(NULL, 5) AS pos_inf_null; +---- + +.Result +[source,json] +---- +[ + { + "pos_inf_equal": "+Infinity", + "pos_inf_not_equal": 10, + "pos_inf_null": null + } ] ---- -In SQL++, `NaN` represents a value that is "Not a Number". ==== From ee9579783006ccebf28d30a3ba52c23defd173f9 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 18 Dec 2025 13:30:15 +0530 Subject: [PATCH 06/10] Minor edits --- modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index 783717144..cd3c7ead8 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -20,7 +20,7 @@ If it encounters `NULL` or any non-numeric value before finding a finite number, === Arguments expr1, expr2, ...:: -A list of expressions to evaluate. +A list of valid expressions to evaluate. You must specify at least 2 expressions. === Return Value @@ -72,7 +72,7 @@ This function has a synonym `IF_NAN()`. === Description -Evaluates a list of expressions and returns the first non-NaN (Not a Number), that is, a valid number. +Evaluates a list of expressions and returns the first valid number that is not NaN (Not a Number). The function ignores `MISSING` and NaN values. If it encounters `NULL` or any other non-number before finding a valid number, the function returns `NULL`. From 9979aeb085185b72e9b9f50a86616e2bc00ed94d Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 18 Dec 2025 14:05:07 +0530 Subject: [PATCH 07/10] Vale checks --- .../n1ql-language-reference/condfunnum.adoc | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index cd3c7ead8..e0994f845 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -6,7 +6,7 @@ [abstract] {description} -== IFINF (`expr1`, `expr2`, ...) +== IFINF(`expr1`, `expr2`, ...) This function has a synonym `IF_INF()`. @@ -20,19 +20,19 @@ If it encounters `NULL` or any non-numeric value before finding a finite number, === Arguments expr1, expr2, ...:: -A list of valid expressions to evaluate. +[Required] A list of valid expressions to evaluate. You must specify at least 2 expressions. === Return Value -The function returns one of the following: +The function returns 1 of the following: * The first finite number. * `NULL` if it encounters `NULL` or a non-number before finding a finite number. === Example -.Find the 1st non-infinite number from a list of numbers +.Find the first non-infinite number from a list of values ==== .Query @@ -72,7 +72,7 @@ This function has a synonym `IF_NAN()`. === Description -Evaluates a list of expressions and returns the first valid number that is not NaN (Not a Number). +Evaluates a list of expressions and returns the first valid number that's not NaN (Not a Number). The function ignores `MISSING` and NaN values. If it encounters `NULL` or any other non-number before finding a valid number, the function returns `NULL`. @@ -80,18 +80,18 @@ If it encounters `NULL` or any other non-number before finding a valid number, t === Arguments expr1, expr2, ...:: -A list of valid expressions to evaluate. +[Required] A list of valid expressions to evaluate. You must specify at least 2 expressions. === Return Value -The function returns one of the following: +The function returns 1 of the following: * The first valid number. * `NULL` if it encounters `NULL` or a non-number before finding a number. === Example -.Find a non-NaN number from a list of numbers +.Find a non-NaN number from a list of values ==== .Query [source,sqlpp] @@ -127,7 +127,7 @@ This function has a synonym `IF_NAN_OR_INF()`. === Description -Evaluates a list of expressions and returns the first number that is neither NaN (Not a Number) nor infinite. +Evaluates a list of expressions and returns the first number that's neither NaN (Not a Number) nor infinite. The function skips `MISSING`, NaN, and infinite values. If it encounters `NULL` or any other non-number before finding a valid number, the function returns `NULL`. @@ -135,19 +135,19 @@ If it encounters `NULL` or any other non-number before finding a valid number, t === Arguments expr1, expr2, ...:: -A list of valid expressions to evaluate. +[Required] A list of valid expressions to evaluate. You must specify at least 2 expressions. === Return Value -The function returns one of the following: +The function returns 1 of the following: -* The first number that is neither NaN nor infinite. +* The first number that's neither NaN nor infinite. * `NULL` if it encounters `NULL` or a non-number before finding such a number. === Example -.Find a number that is neither NaN nor infinite from a list of numbers +.Find a number that's neither NaN nor infinite from a list of values ==== .Query [source,sqlpp] @@ -182,26 +182,26 @@ This function has a synonym `NAN_IF()`. === Description -Compares two expressions and returns `NaN` (Not a Number) if they are equal; otherwise, it returns the value of the first expression. +Compares 2 expressions and returns `NaN` (Not a Number) if they're equal; otherwise, it returns the value of the first expression. === Arguments expr1:: -A valid expression. +[Required] A valid expression. expr2:: -A valid expression to compare with `expr1`. +[Required] A valid expression to compare with `expr1`. === Return Value -The function returns one of the following: +The function returns 1 of the following: * `NaN` if `expr1` is equal to `expr2`. * `expr1` if the expressions are not equal. * `NULL` if either expression is `MISSING` or `NULL`. === Example -.Compare two numbers and return NaN if they are equal +.Compare 2 values and return NaN if they're equal ==== .Query [source,sqlpp] @@ -229,19 +229,19 @@ This function has a synonym `NEGINF_IF()`. === Description -Compares two expressions and returns negative infinity if they are equal; otherwise, it returns the value of the first expression. +Compares 2 expressions and returns negative infinity if they're equal; otherwise, it returns the value of the first expression. === Arguments expr1:: -A valid expression. +[Required] A valid expression. expr2:: -A valid expression to compare with `expr1`. +[Required] A valid expression to compare with `expr1`. === Return Value -The function returns one of the following: +The function returns 1 of the following: * `-Infinity` if `expr1` is equal to `expr2`. * `expr1` if the expressions are not equal. @@ -249,7 +249,7 @@ The function returns one of the following: === Example -.Compare two numbers and return negative infinity if they are equal +.Compare 2 values and return negative infinity if they're equal ==== .Query [source,sqlpp] @@ -278,19 +278,19 @@ This function has a synonym `POSINF_IF()`. === Description -Compares two expressions and returns positive infinity if they are equal; otherwise, it returns the value of the first expression. +Compares 2 expressions and returns positive infinity if they're equal; otherwise, it returns the value of the first expression. === Arguments expr1:: -A valid expression. +[Required] A valid expression. expr2:: -A valid expression to compare with `expr1`. +[Required] A valid expression to compare with `expr1`. === Return Value -The function returns one of the following: +The function returns 1 of the following: * `+Infinity` if `expr1` is equal to `expr2`. * `expr1` if the expressions are not equal. @@ -298,7 +298,7 @@ The function returns one of the following: === Example -.Compare two numbers and return positive infinity if they are equal +.Compare 2 values and return positive infinity if they're equal ==== .Query From 086d23c01926e491d126b6b1a2d8867fc9318a4a Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 18 Dec 2025 15:34:55 +0530 Subject: [PATCH 08/10] Update examples --- .../n1ql-language-reference/condfunnum.adoc | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index e0994f845..fa373fb7f 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -39,9 +39,9 @@ The function returns 1 of the following: [source,sqlpp] ---- SELECT IFINF(5, 10, 20), - IFINF(5, NULL, 10), IFINF(inf(), -inf(), 5, 10), IFINF(POWER(10, 400), 5, 10), + IFINF(2.001e340, 5), IFINF(NULL, 5, 10), IFINF(MISSING, 5, NULL), IFINF(MISSING, NULL, 5, 10); @@ -62,8 +62,10 @@ SELECT IFINF(5, 10, 20), } ] ---- -The functions `inf()` and `-inf()` return positive and negative infinity, respectively. -Also, the expression `POWER(10, 400)` results in positive infinity because it exceeds the maximum representable finite number. +In this example: + +* The functions `inf()` and `-inf()` return positive and negative infinity, respectively. +* The expressions `POWER(10, 400)` and `2.001e340` return positive infinity because they exceed the maximum representable finite number. ==== == IFNAN(`expr1`, `expr2`, ...) @@ -97,6 +99,7 @@ The function returns 1 of the following: [source,sqlpp] ---- SELECT IFNAN(5, 10, 20, nan()), + IFNAN(sqrt(-1), 5, 10), IFNAN("abc", 5, NULL, 10), IFNAN(NULL, 5, 10), IFNAN(MISSING, 5, NULL), @@ -109,15 +112,19 @@ SELECT IFNAN(5, 10, 20, nan()), [ { "$1": 5, - "$2": null, + "$2": 5, "$3": null, - "$4": 5, - "$5": null, - "$6": 5 + "$4": null, + "$5": 5, + "$6": null, + "$7": 5 } ] ---- -The function `nan()` returns a NaN value. +In this example: + +* The function `nan()` returns a NaN value. +* The expression `sqrt(-1)` also returns NaN because the square root of a negative number is not a real number. ==== @@ -153,11 +160,11 @@ The function returns 1 of the following: [source,sqlpp] ---- SELECT IFNANORINF(5, 10, nan(), inf()), + IFNANORINF(sqrt(-1), -inf(), 5, 10), + IFNANORINF(2.001e340, 5, 10), IFNANORINF("abc", 5, NULL, 10), IFNANORINF(NULL, 5, 10), - IFNANORINF(MISSING, 5, NULL), - IFNANORINF(MISSING, NULL, 5, 10), - IFNANORINF(nan(), -inf(), 5, 10); + IFNANORINF(MISSING, 5, NULL); ---- .Result [source,json] @@ -165,15 +172,20 @@ SELECT IFNANORINF(5, 10, nan(), inf()), [ { "$1": 5, - "$2": null, - "$3": null, - "$4": 5, + "$2": 5, + "$3": 5, + "$4": null, "$5": null, "$6": 5 } ] ---- -The function `nan()` returns a NaN value, and the functions `inf()` and `-inf()` return positive and negative infinity, respectively. +In this example: + +* The function `nan()` returns a NaN value. +* The functions `inf()` and `-inf()` return positive and negative infinity, respectively. +* The expression `sqrt(-1)` returns NaN because the square root of a negative number is not a real number. +* The expression `2.001e340` returns positive infinity because it exceeds the maximum representable finite number. ==== == NANIF(`expr1`, `expr2`) From 0f6f3b23e754d597a53d283df769b2993a9bf1b4 Mon Sep 17 00:00:00 2001 From: rakhi-prathap Date: Thu, 8 Jan 2026 10:01:48 +0530 Subject: [PATCH 09/10] Apply suggestions from code review Co-authored-by: Simon Dew <39966290+simon-dew@users.noreply.github.com> --- .../n1ql-language-reference/condfunnum.adoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index fa373fb7f..dfcb7a999 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -39,7 +39,7 @@ The function returns 1 of the following: [source,sqlpp] ---- SELECT IFINF(5, 10, 20), - IFINF(inf(), -inf(), 5, 10), + IFINF(INF(), -INF(), 5, 10), IFINF(POWER(10, 400), 5, 10), IFINF(2.001e340, 5), IFINF(NULL, 5, 10), @@ -64,7 +64,7 @@ SELECT IFINF(5, 10, 20), ---- In this example: -* The functions `inf()` and `-inf()` return positive and negative infinity, respectively. +* The functions `INF()` and `-INF()` return positive and negative infinity, respectively. * The expressions `POWER(10, 400)` and `2.001e340` return positive infinity because they exceed the maximum representable finite number. ==== @@ -99,12 +99,12 @@ The function returns 1 of the following: [source,sqlpp] ---- SELECT IFNAN(5, 10, 20, nan()), - IFNAN(sqrt(-1), 5, 10), + IFNAN(SQRT(-1), 5, 10), IFNAN("abc", 5, NULL, 10), IFNAN(NULL, 5, 10), IFNAN(MISSING, 5, NULL), IFNAN(MISSING, NULL, 5, 10), - IFNAN(nan(), 5, 10); + IFNAN(NAN(), 5, 10); ---- .Result [source,json] @@ -123,8 +123,8 @@ SELECT IFNAN(5, 10, 20, nan()), ---- In this example: -* The function `nan()` returns a NaN value. -* The expression `sqrt(-1)` also returns NaN because the square root of a negative number is not a real number. +* The function `NAN()` returns a NaN value. +* The expression `SQRT(-1)` also returns NaN because the square root of a negative number is not a real number. ==== @@ -208,7 +208,7 @@ expr2:: The function returns 1 of the following: -* `NaN` if `expr1` is equal to `expr2`. +* `"NaN"` if `expr1` is equal to `expr2`. * `expr1` if the expressions are not equal. * `NULL` if either expression is `MISSING` or `NULL`. @@ -255,7 +255,7 @@ expr2:: The function returns 1 of the following: -* `-Infinity` if `expr1` is equal to `expr2`. +* `"-Infinity"` if `expr1` is equal to `expr2`. * `expr1` if the expressions are not equal. * `NULL` if either expression is `MISSING` or `NULL`. From ce566f5484863ca1ecc18d8172bf447b3e516253 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Thu, 8 Jan 2026 10:26:35 +0530 Subject: [PATCH 10/10] Function names in uppercase --- .../n1ql-language-reference/condfunnum.adoc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc index dfcb7a999..46435c61c 100644 --- a/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/condfunnum.adoc @@ -65,7 +65,7 @@ SELECT IFINF(5, 10, 20), In this example: * The functions `INF()` and `-INF()` return positive and negative infinity, respectively. -* The expressions `POWER(10, 400)` and `2.001e340` return positive infinity because they exceed the maximum representable finite number. +* The function `POWER(10, 400)` and the expression `2.001e340` return positive infinity because they exceed the maximum representable finite number. ==== == IFNAN(`expr1`, `expr2`, ...) @@ -98,7 +98,7 @@ The function returns 1 of the following: .Query [source,sqlpp] ---- -SELECT IFNAN(5, 10, 20, nan()), +SELECT IFNAN(5, 10, 20, NAN()), IFNAN(SQRT(-1), 5, 10), IFNAN("abc", 5, NULL, 10), IFNAN(NULL, 5, 10), @@ -124,7 +124,7 @@ SELECT IFNAN(5, 10, 20, nan()), In this example: * The function `NAN()` returns a NaN value. -* The expression `SQRT(-1)` also returns NaN because the square root of a negative number is not a real number. +* The function `SQRT(-1)` also returns NaN because the square root of a negative number is not a real number. ==== @@ -159,8 +159,8 @@ The function returns 1 of the following: .Query [source,sqlpp] ---- -SELECT IFNANORINF(5, 10, nan(), inf()), - IFNANORINF(sqrt(-1), -inf(), 5, 10), +SELECT IFNANORINF(5, 10, NAN(), INF()), + IFNANORINF(SQRT(-1), -INF(), 5, 10), IFNANORINF(2.001e340, 5, 10), IFNANORINF("abc", 5, NULL, 10), IFNANORINF(NULL, 5, 10), @@ -182,9 +182,9 @@ SELECT IFNANORINF(5, 10, nan(), inf()), ---- In this example: -* The function `nan()` returns a NaN value. -* The functions `inf()` and `-inf()` return positive and negative infinity, respectively. -* The expression `sqrt(-1)` returns NaN because the square root of a negative number is not a real number. +* The function `NAN()` returns a NaN value. +* The functions `INF()` and `-INF()` return positive and negative infinity, respectively. +* The function `SQRT(-1)` returns NaN because the square root of a negative number is not a real number. * The expression `2.001e340` returns positive infinity because it exceeds the maximum representable finite number. ==== @@ -304,7 +304,7 @@ expr2:: The function returns 1 of the following: -* `+Infinity` if `expr1` is equal to `expr2`. +* `"+Infinity"` if `expr1` is equal to `expr2`. * `expr1` if the expressions are not equal. * `NULL` if either expression is `MISSING` or `NULL`.