From 86aacaef1e84dbfba1fc91337f602fa1c1ae0e60 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Thu, 1 Jun 2023 14:44:06 -0700 Subject: [PATCH 1/9] Updated documentation of arithmetic functions, correct some mistakes, added missing functions Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index 215300fba3..dd44430868 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -19,12 +19,12 @@ The SQL plugin supports the following functions. Function | Specification | Example :--- | :--- | :--- abs | `abs(number T) -> T` | `SELECT abs(0.5) FROM my-index LIMIT 1` -add | `add(number T, number) -> T` | `SELECT add(1, 5) FROM my-index LIMIT 1` +add | `add(number T, number T) -> T` | `SELECT add(1, 5) FROM my-index LIMIT 1` cbrt | `cbrt(number T) -> T` | `SELECT cbrt(0.5) FROM my-index LIMIT 1` ceil | `ceil(number T) -> T` | `SELECT ceil(0.5) FROM my-index LIMIT 1` conv | `conv(string T, int a, int b) -> T` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10) FROM my-index LIMIT 1` crc32 | `crc32(string T) -> T` | `SELECT crc32('MySQL') FROM my-index LIMIT 1` -divide | `divide(number T, number) -> T` | `SELECT divide(1, 0.5) FROM my-index LIMIT 1` +divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5) FROM my-index LIMIT 1` e | `e() -> double` | `SELECT e() FROM my-index LIMIT 1` exp | `exp(number T) -> T` | `SELECT exp(0.5) FROM my-index LIMIT 1` expm1 | `expm1(number T) -> T` | `SELECT expm1(0.5) FROM my-index LIMIT 1` @@ -33,11 +33,12 @@ ln | `ln(number T) -> double` | `SELECT ln(10) FROM my-index LIMIT 1` log | `log(number T) -> double` or `log(number T, number) -> double` | `SELECT log(10) FROM my-index LIMIT 1` log2 | `log2(number T) -> double` | `SELECT log2(10) FROM my-index LIMIT 1` log10 | `log10(number T) -> double` | `SELECT log10(10) FROM my-index LIMIT 1` -mod | `mod(number T, number) -> T` | `SELECT modulus(2, 3) FROM my-index LIMIT 1` -multiply | `multiply(number T, number) -> number` | `SELECT multiply(2, 3) FROM my-index LIMIT 1` +mod | `mod(number T, number) -> T` | `SELECT mod(2, 3) FROM my-index LIMIT 1` +modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3) FROM my-index LIMIT 1` +multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3) FROM my-index LIMIT 1` pi | `pi() -> double` | `SELECT pi() FROM my-index LIMIT 1` -pow | `pow(number T) -> T` or `pow(number T, number) -> T` | `SELECT pow(2, 3) FROM my-index LIMIT 1` -power | `power(number T) -> T` or `power(number T, number) -> T` | `SELECT power(2, 3) FROM my-index LIMIT 1` +pow | `pow(number T, number) -> T` | `SELECT pow(2, 3) FROM my-index LIMIT 1` +power | `power(number T, number) -> T` | `SELECT power(2, 3) FROM my-index LIMIT 1` rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5) FROM my-index LIMIT 1` rint | `rint(number T) -> T` | `SELECT rint(1.5) FROM my-index LIMIT 1` round | `round(number T) -> T` | `SELECT round(1.5) FROM my-index LIMIT 1` @@ -45,8 +46,11 @@ sign | `sign(number T) -> T` | `SELECT sign(1.5) FROM my-index LIMIT 1` signum | `signum(number T) -> T` | `SELECT signum(0.5) FROM my-index LIMIT 1` sqrt | `sqrt(number T) -> T` | `SELECT sqrt(0.5) FROM my-index LIMIT 1` strcmp | `strcmp(string T, string T) -> T` | `SELECT strcmp('hello', 'hello') FROM my-index LIMIT 1` -subtract | `subtract(number T, number) -> T` | `SELECT subtract(3, 2) FROM my-index LIMIT 1` +subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2) FROM my-index LIMIT 1` truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1) FROM my-index LIMIT 1` ++ | `number [op] number -> number` | `SELECT 1 + 100 FROM my-index LIMIT 1` +- | `number [op] number -> number` | `SELECT 1 - 100 FROM my-index LIMIT 1` +* | `number [op] number -> number` | `SELECT 1 * 100 FROM my-index LIMIT 1` / | `number [op] number -> number` | `SELECT 1 / 100 FROM my-index LIMIT 1` % | `number [op] number -> number` | `SELECT 1 % 100 FROM my-index LIMIT 1` From b0ab2b66a4899b61f9f82b4b551bc0aabe46a31c Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Thu, 1 Jun 2023 15:09:08 -0700 Subject: [PATCH 2/9] Added a few missing variable definitions Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index dd44430868..6307834ae2 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -33,11 +33,11 @@ ln | `ln(number T) -> double` | `SELECT ln(10) FROM my-index LIMIT 1` log | `log(number T) -> double` or `log(number T, number) -> double` | `SELECT log(10) FROM my-index LIMIT 1` log2 | `log2(number T) -> double` | `SELECT log2(10) FROM my-index LIMIT 1` log10 | `log10(number T) -> double` | `SELECT log10(10) FROM my-index LIMIT 1` -mod | `mod(number T, number) -> T` | `SELECT mod(2, 3) FROM my-index LIMIT 1` +mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3) FROM my-index LIMIT 1` modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3) FROM my-index LIMIT 1` multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3) FROM my-index LIMIT 1` pi | `pi() -> double` | `SELECT pi() FROM my-index LIMIT 1` -pow | `pow(number T, number) -> T` | `SELECT pow(2, 3) FROM my-index LIMIT 1` +pow | `pow(number T, number T) -> T` | `SELECT pow(2, 3) FROM my-index LIMIT 1` power | `power(number T, number) -> T` | `SELECT power(2, 3) FROM my-index LIMIT 1` rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5) FROM my-index LIMIT 1` rint | `rint(number T) -> T` | `SELECT rint(1.5) FROM my-index LIMIT 1` From 55085495c1c77f75c253cabbb1388d9d3d1d1e13 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Fri, 2 Jun 2023 09:11:00 -0700 Subject: [PATCH 3/9] Updated arithmetic operators documentation to include symbol Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index 6307834ae2..497cbe933f 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -48,11 +48,11 @@ sqrt | `sqrt(number T) -> T` | `SELECT sqrt(0.5) FROM my-index LIMIT 1` strcmp | `strcmp(string T, string T) -> T` | `SELECT strcmp('hello', 'hello') FROM my-index LIMIT 1` subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2) FROM my-index LIMIT 1` truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1) FROM my-index LIMIT 1` -+ | `number [op] number -> number` | `SELECT 1 + 100 FROM my-index LIMIT 1` -- | `number [op] number -> number` | `SELECT 1 - 100 FROM my-index LIMIT 1` -* | `number [op] number -> number` | `SELECT 1 * 100 FROM my-index LIMIT 1` -/ | `number [op] number -> number` | `SELECT 1 / 100 FROM my-index LIMIT 1` -% | `number [op] number -> number` | `SELECT 1 % 100 FROM my-index LIMIT 1` ++ | `number + number -> number` | `SELECT 1 + 5 FROM my-index LIMIT 1` +- | `number - number -> number` | `SELECT 3 - 2 FROM my-index LIMIT 1` +* | `number * number -> number` | `SELECT 2 * 3 FROM my-index LIMIT 1` +/ | `number / number -> number` | `SELECT 1 / 0.5 FROM my-index LIMIT 1` +% | `number % number -> number` | `SELECT 2 % 3 FROM my-index LIMIT 1` ## Trigonometric From 3aadc63125c8459a592823ab87e37c1b06ebd190 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Thu, 8 Jun 2023 09:37:04 -0700 Subject: [PATCH 4/9] removed unneeded SELECT and LIMIT Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 130 +++++++++++++++---------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index 497cbe933f..28cf73b5d2 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -18,58 +18,58 @@ The SQL plugin supports the following functions. Function | Specification | Example :--- | :--- | :--- -abs | `abs(number T) -> T` | `SELECT abs(0.5) FROM my-index LIMIT 1` -add | `add(number T, number T) -> T` | `SELECT add(1, 5) FROM my-index LIMIT 1` -cbrt | `cbrt(number T) -> T` | `SELECT cbrt(0.5) FROM my-index LIMIT 1` -ceil | `ceil(number T) -> T` | `SELECT ceil(0.5) FROM my-index LIMIT 1` -conv | `conv(string T, int a, int b) -> T` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10) FROM my-index LIMIT 1` -crc32 | `crc32(string T) -> T` | `SELECT crc32('MySQL') FROM my-index LIMIT 1` -divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5) FROM my-index LIMIT 1` -e | `e() -> double` | `SELECT e() FROM my-index LIMIT 1` -exp | `exp(number T) -> T` | `SELECT exp(0.5) FROM my-index LIMIT 1` -expm1 | `expm1(number T) -> T` | `SELECT expm1(0.5) FROM my-index LIMIT 1` -floor | `floor(number T) -> T` | `SELECT floor(0.5) AS Rounded_Down FROM my-index LIMIT 1` -ln | `ln(number T) -> double` | `SELECT ln(10) FROM my-index LIMIT 1` -log | `log(number T) -> double` or `log(number T, number) -> double` | `SELECT log(10) FROM my-index LIMIT 1` -log2 | `log2(number T) -> double` | `SELECT log2(10) FROM my-index LIMIT 1` -log10 | `log10(number T) -> double` | `SELECT log10(10) FROM my-index LIMIT 1` -mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3) FROM my-index LIMIT 1` -modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3) FROM my-index LIMIT 1` -multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3) FROM my-index LIMIT 1` -pi | `pi() -> double` | `SELECT pi() FROM my-index LIMIT 1` -pow | `pow(number T, number T) -> T` | `SELECT pow(2, 3) FROM my-index LIMIT 1` -power | `power(number T, number) -> T` | `SELECT power(2, 3) FROM my-index LIMIT 1` -rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5) FROM my-index LIMIT 1` -rint | `rint(number T) -> T` | `SELECT rint(1.5) FROM my-index LIMIT 1` -round | `round(number T) -> T` | `SELECT round(1.5) FROM my-index LIMIT 1` -sign | `sign(number T) -> T` | `SELECT sign(1.5) FROM my-index LIMIT 1` -signum | `signum(number T) -> T` | `SELECT signum(0.5) FROM my-index LIMIT 1` -sqrt | `sqrt(number T) -> T` | `SELECT sqrt(0.5) FROM my-index LIMIT 1` -strcmp | `strcmp(string T, string T) -> T` | `SELECT strcmp('hello', 'hello') FROM my-index LIMIT 1` -subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2) FROM my-index LIMIT 1` -truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1) FROM my-index LIMIT 1` -+ | `number + number -> number` | `SELECT 1 + 5 FROM my-index LIMIT 1` -- | `number - number -> number` | `SELECT 3 - 2 FROM my-index LIMIT 1` -* | `number * number -> number` | `SELECT 2 * 3 FROM my-index LIMIT 1` -/ | `number / number -> number` | `SELECT 1 / 0.5 FROM my-index LIMIT 1` -% | `number % number -> number` | `SELECT 2 % 3 FROM my-index LIMIT 1` +abs | `abs(number T) -> T` | `SELECT abs(0.5)` +add | `add(number T, number T) -> T` | `SELECT add(1, 5)` +cbrt | `cbrt(number T) -> T` | `SELECT cbrt(0.5)` +ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` +conv | `conv(string T, int a, int b) -> T` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10)` +crc32 | `crc32(string T) -> T` | `SELECT crc32('MySQL')` +divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` +e | `e() -> double` | `SELECT e()` +exp | `exp(number T) -> T` | `SELECT exp(0.5)` +expm1 | `expm1(number T) -> T` | `SELECT expm1(0.5)` +floor | `floor(number T) -> T` | `SELECT floor(0.5) AS Rounded_Down` +ln | `ln(number T) -> double` | `SELECT ln(10)` +log | `log(number T) -> double` or `log(number T, number) -> double` | `SELECT log(10)` +log2 | `log2(number T) -> double` | `SELECT log2(10)` +log10 | `log10(number T) -> double` | `SELECT log10(10)` +mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` +modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` +multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` +pi | `pi() -> double` | `SELECT pi()` +pow | `pow(number T, number T) -> T` | `SELECT pow(2, 3)` +power | `power(number T, number) -> T` | `SELECT power(2, 3)` +rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5)` +rint | `rint(number T) -> T` | `SELECT rint(1.5)` +round | `round(number T) -> T` | `SELECT round(1.5)` +sign | `sign(number T) -> T` | `SELECT sign(1.5)` +signum | `signum(number T) -> T` | `SELECT signum(0.5)` +sqrt | `sqrt(number T) -> T` | `SELECT sqrt(0.5)` +strcmp | `strcmp(string T, string T) -> T` | `SELECT strcmp('hello', 'hello')` +subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` +truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` ++ | `number + number -> number` | `SELECT 1 + 5` +- | `number - number -> number` | `SELECT 3 - 2` +* | `number * number -> number` | `SELECT 2 * 3` +/ | `number / number -> number` | `SELECT 1 / 0.5` +% | `number % number -> number` | `SELECT 2 % 3` ## Trigonometric Function | Specification | Example :--- | :--- | :--- -acos | `acos(number T) -> double` | `SELECT acos(0.5) FROM my-index LIMIT 1` -asin | `asin(number T) -> double` | `SELECT asin(0.5) FROM my-index LIMIT 1` -atan | `atan(number T) -> double` | `SELECT atan(0.5) FROM my-index LIMIT 1` -atan2 | `atan2(number T, number) -> double` | `SELECT atan2(1, 0.5) FROM my-index LIMIT 1` -cos | `cos(number T) -> double` | `SELECT cos(0.5) FROM my-index LIMIT 1` -cosh | `cosh(number T) -> double` | `SELECT cosh(0.5) FROM my-index LIMIT 1` -cot | `cot(number T) -> double` | `SELECT cot(0.5) FROM my-index LIMIT 1` -degrees | `degrees(number T) -> double` | `SELECT degrees(0.5) FROM my-index LIMIT 1` -radians | `radians(number T) -> double` | `SELECT radians(0.5) FROM my-index LIMIT 1` -sin | `sin(number T) -> double` | `SELECT sin(0.5) FROM my-index LIMIT 1` -sinh | `sinh(number T) -> double` | `SELECT sinh(0.5) FROM my-index LIMIT 1` -tan | `tan(number T) -> double` | `SELECT tan(0.5) FROM my-index LIMIT 1` +acos | `acos(number T) -> double` | `SELECT acos(0.5)` +asin | `asin(number T) -> double` | `SELECT asin(0.5)` +atan | `atan(number T) -> double` | `SELECT atan(0.5)` +atan2 | `atan2(number T, number) -> double` | `SELECT atan2(1, 0.5)` +cos | `cos(number T) -> double` | `SELECT cos(0.5)` +cosh | `cosh(number T) -> double` | `SELECT cosh(0.5)` +cot | `cot(number T) -> double` | `SELECT cot(0.5)` +degrees | `degrees(number T) -> double` | `SELECT degrees(0.5)` +radians | `radians(number T) -> double` | `SELECT radians(0.5)` +sin | `sin(number T) -> double` | `SELECT sin(0.5)` +sinh | `sinh(number T) -> double` | `SELECT sinh(0.5)` +tan | `tan(number T) -> double` | `SELECT tan(0.5)` ## Date and time @@ -106,32 +106,32 @@ year | `year(date) -> integer` | `SELECT year(date) FROM my-index LIMIT 1` Function | Specification | Example :--- | :--- | :--- -ascii | `ascii(string T) -> integer` | `SELECT ascii(name.keyword) FROM my-index LIMIT 1` -concat | `concat(str1, str2) -> string` | `SELECT concat('hello', 'world') FROM my-index LIMIT 1` -concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws("-", "Tutorial", "is", "fun!") FROM my-index LIMIT 1` -left | `left(string T, integer) -> T` | `SELECT left('hello', 2) FROM my-index LIMIT 1` -length | `length(string) -> integer` | `SELECT length('hello') FROM my-index LIMIT 1` -locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> INTEGER` | `SELECT locate('o', 'hello') FROM my-index LIMIT 1`, `SELECT locate('l', 'hello', 3) FROM my-index LIMIT 1` -replace | `replace(string T, string, string) -> T` | `SELECT replace('hello', 'l', 'x') FROM my-index LIMIT 1` -right | `right(string T, integer) -> T` | `SELECT right('hello', 1) FROM my-index LIMIT 1` -rtrim | `rtrim(string T) -> T` | `SELECT rtrim(name.keyword) FROM my-index LIMIT 1` -substring | `substring(string T, integer, integer) -> T` | `SELECT substring(name.keyword, 2,5) FROM my-index LIMIT 1` -trim | `trim(string T) -> T` | `SELECT trim(' hello') FROM my-index LIMIT 1` -upper | `upper(string T) -> T` | `SELECT upper('helloworld') FROM my-index LIMIT 1` +ascii | `ascii(string T) -> integer` | `SELECT ascii('h')` +concat | `concat(str1, str2) -> string` | `SELECT concat('hello', 'world')` +concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws("-", "Tutorial", "is", "fun!")` +left | `left(string T, integer) -> T` | `SELECT left('hello', 2)` +length | `length(string) -> integer` | `SELECT length('hello')` +locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> INTEGER` | `SELECT locate('o', 'hello')`, `SELECT locate('l', 'hello', 3)` +replace | `replace(string T, string, string) -> T` | `SELECT replace('hello', 'l', 'x')` +right | `right(string T, integer) -> T` | `SELECT right('hello', 1)` +rtrim | `rtrim(string T) -> T` | `SELECT rtrim('hello ')` +substring | `substring(string T, integer, integer) -> T` | `SELECT substring('hello, 2, 4)` +trim | `trim(string T) -> T` | `SELECT trim(' hello')` +upper | `upper(string T) -> T` | `SELECT upper('hello world')` ## Aggregate Function | Specification | Example :--- | :--- | :--- -avg | `avg(number T) -> T` | `SELECT avg(2, 3) FROM my-index LIMIT 1` -count | `count(number T) -> T` | `SELECT count(date) FROM my-index LIMIT 1` -min | `min(number T, number) -> T` | `SELECT min(2, 3) FROM my-index LIMIT 1` +avg | `avg(number T) -> T` | `SELECT avg(2, 3)` +count | `count(number T) -> T` | `SELECT count(date) FROM my-index` +min | `min(number T, number) -> T` | `SELECT min(2, 3)` show | `show(string T) -> T` | `SHOW TABLES LIKE my-index` ## Advanced Function | Specification | Example :--- | :--- | :--- -if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1) FROM my-index LIMIT 1`, `SELECT if(true, 0, 1) FROM my-index LIMIT 1` -ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull('hello', 1) FROM my-index LIMIT 1`, `SELECT ifnull(null, 1) FROM my-index LIMIT 1` -isnull | `isnull(es_type) -> integer` | `SELECT isnull(null) FROM my-index LIMIT 1`, `SELECT isnull(1) FROM my-index LIMIT 1` +if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1)`, `SELECT if(true, 0, 1)` +ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull('hello', 1)`, `SELECT ifnull(null, 1)` +isnull | `isnull(es_type) -> integer` | `SELECT isnull(null)`, `SELECT isnull(1)` From fb40c93b09725efc60793d10f702a7988d4aaff2 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Thu, 8 Jun 2023 10:54:14 -0700 Subject: [PATCH 5/9] reformated table Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 296 +++++++++++++++---------------- 1 file changed, 148 insertions(+), 148 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index 0c2f670d68..5edbc5f8bc 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -18,170 +18,170 @@ The SQL plugin supports the following common functions shared across the SQL and ## Mathematical -Function | Specification | Example -:--- | :--- | :--- -abs | `abs(number T) -> T` | `SELECT abs(0.5)` -add | `add(number T, number T) -> T` | `SELECT add(1, 5)` -cbrt | `cbrt(number T) -> T` | `SELECT cbrt(0.5)` -ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` -conv | `conv(string T, int a, int b) -> T` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10)` -crc32 | `crc32(string T) -> T` | `SELECT crc32('MySQL')` -divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` -e | `e() -> double` | `SELECT e()` -exp | `exp(number T) -> T` | `SELECT exp(0.5)` -expm1 | `expm1(number T) -> T` | `SELECT expm1(0.5)` -floor | `floor(number T) -> T` | `SELECT floor(0.5) AS Rounded_Down` -ln | `ln(number T) -> double` | `SELECT ln(10)` -log | `log(number T) -> double` or `log(number T, number) -> double` | `SELECT log(10)` -log2 | `log2(number T) -> double` | `SELECT log2(10)` -log10 | `log10(number T) -> double` | `SELECT log10(10)` -mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` -modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` -multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` -pi | `pi() -> double` | `SELECT pi()` -pow | `pow(number T, number T) -> T` | `SELECT pow(2, 3)` -power | `power(number T, number) -> T` | `SELECT power(2, 3)` -rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5)` -rint | `rint(number T) -> T` | `SELECT rint(1.5)` -round | `round(number T) -> T` | `SELECT round(1.5)` -sign | `sign(number T) -> T` | `SELECT sign(1.5)` -signum | `signum(number T) -> T` | `SELECT signum(0.5)` -sqrt | `sqrt(number T) -> T` | `SELECT sqrt(0.5)` -strcmp | `strcmp(string T, string T) -> T` | `SELECT strcmp('hello', 'hello')` -subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` -truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` -+ | `number + number -> number` | `SELECT 1 + 5` -- | `number - number -> number` | `SELECT 3 - 2` -* | `number * number -> number` | `SELECT 2 * 3` -/ | `number / number -> number` | `SELECT 1 / 0.5` -% | `number % number -> number` | `SELECT 2 % 3` +| Function | Specification | Example | +|:---------|:-----------------------------------------------------------------|:------------------------------------------------------------------------------------| +| abs | `abs(number T) -> T` | `SELECT abs(0.5)` | +| add | `add(number T, number T) -> T` | `SELECT add(1, 5)` | +| cbrt | `cbrt(number T) -> double` | `SELECT cbrt(0.5)` | +| ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` | +| conv | `conv(string T, int a, int b) -> string` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10)` | +| crc32 | `crc32(string T) -> T` | `SELECT crc32('MySQL')` | +| divide | `divide(number T, number) -> T` | `SELECT divide(1, 0.5)` | +| e | `e() -> double` | `SELECT e()` | +| exp | `exp(number T) -> T` | `SELECT exp(0.5)` | +| expm1 | `expm1(number T) -> T` | `SELECT expm1(0.5)` | +| floor | `floor(number T) -> T` | `SELECT floor(0.5) AS Rounded_Down` | +| ln | `ln(number T) -> double` | `SELECT ln(10)` | +| log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10)` | +| log2 | `log2(number T) -> double` | `SELECT log2(10)` | +| log10 | `log10(number T) -> double` | `SELECT log10(10)` | +| mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` | +| modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` | +| multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` | +| pi | `pi() -> double` | `SELECT pi()` | +| pow | `pow(number T, number T) -> T` | `SELECT pow(2, 3)` | +| power | `power(number T, number T) -> T` | `SELECT power(2, 3)` | +| rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5)` | +| rint | `rint(number T) -> double` | `SELECT rint(1.5)` | +| round | `round(number T) -> T` | `SELECT round(1.5)` | +| sign | `sign(number T) -> T` | `SELECT sign(1.5)` | +| signum | `signum(number T) -> int` | `SELECT signum(0.5)` | +| sqrt | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | +| strcmp | `strcmp(string T, string T) -> int` | `SELECT strcmp('hello', 'hello')` | +| subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` | +| truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` | +| + | `number + number -> number` | `SELECT 1 + 5` | +| - | `number - number -> number` | `SELECT 3 - 2` | +| * | `number * number -> number` | `SELECT 2 * 3` | +| / | `number / number -> number` | `SELECT 1 / 0.5` | +| % | `number % number -> number` | `SELECT 2 % 3` | ## Trigonometric -Function | Specification | Example -:--- | :--- | :--- -acos | `acos(number T) -> double` | `SELECT acos(0.5)` -asin | `asin(number T) -> double` | `SELECT asin(0.5)` -atan | `atan(number T) -> double` | `SELECT atan(0.5)` -atan2 | `atan2(number T, number) -> double` | `SELECT atan2(1, 0.5)` -cos | `cos(number T) -> double` | `SELECT cos(0.5)` -cosh | `cosh(number T) -> double` | `SELECT cosh(0.5)` -cot | `cot(number T) -> double` | `SELECT cot(0.5)` -degrees | `degrees(number T) -> double` | `SELECT degrees(0.5)` -radians | `radians(number T) -> double` | `SELECT radians(0.5)` -sin | `sin(number T) -> double` | `SELECT sin(0.5)` -sinh | `sinh(number T) -> double` | `SELECT sinh(0.5)` -tan | `tan(number T) -> double` | `SELECT tan(0.5)` +| Function | Specification | Example | +|:---------|:--------------------------------------|:-----------------------| +| acos | `acos(number T) -> double` | `SELECT acos(0.5)` | +| asin | `asin(number T) -> double` | `SELECT asin(0.5)` | +| atan | `atan(number T) -> double` | `SELECT atan(0.5)` | +| atan2 | `atan2(number T, number T) -> double` | `SELECT atan2(1, 0.5)` | +| cos | `cos(number T) -> double` | `SELECT cos(0.5)` | +| cosh | `cosh(number T) -> double` | `SELECT cosh(0.5)` | +| cot | `cot(number T) -> double` | `SELECT cot(0.5)` | +| degrees | `degrees(number T) -> double` | `SELECT degrees(0.5)` | +| radians | `radians(number T) -> double` | `SELECT radians(0.5)` | +| sin | `sin(number T) -> double` | `SELECT sin(0.5)` | +| sinh | `sinh(number T) -> double` | `SELECT sinh(0.5)` | +| tan | `tan(number T) -> double` | `SELECT tan(0.5)` | ## Date and time Functions marked with * are only available in SQL. -Function | Specification | Example -:--- | :--- | :--- -adddate | `adddate(date, INTERVAL expr unit) -> date` | `SELECT adddate(date('2020-08-26'), INTERVAL 1 hour) FROM my-index LIMIT 1` -addtime | `addtime(date, date) -> date` | `SELECT addtime(date('2008-12-12'), date('2008-12-12'))` -convert_tz | `convert_tz(date, string, string) -> date` | `SELECT convert_tz('2008-12-25 05:30:00', '+00:00', 'America/Los_Angeles')` -curtime | `curtime() -> time` | `SELECT curtime()` -curdate | `curdate() -> date` | `SELECT curdate() FROM my-index LIMIT 1` -current_date | `current_date() -> date` | `SELECT current_date() FROM my-index LIMIT 1` -current_time | `current_time() -> time` | `SELECT current_time()` -current_timestamp | `current_timestamp() -> date` | `SELECT current_timestamp() FROM my-index LIMIT 1` -date | `date(date) -> date` | `SELECT date() FROM my-index LIMIT 1` -datediff | `datediff(date, date) -> integer` | `SELECT datediff(date('2000-01-02'), date('2000-01-01'))` -datetime | `datetime(string) -> datetime` | `SELECT datetime('2008-12-25 00:00:00')` -date_add | `date_add(date, INTERVAL integer UNIT)` | `SELECT date_add('2020-08-26'), INTERVAL 1 HOUR)` -date_format | `date_format(date, string) -> string` or `date_format(date, string, string) -> string` | `SELECT date_format(date, 'Y') FROM my-index LIMIT 1` -date_sub | `date_sub(date, INTERVAL expr unit) -> date` | `SELECT date_sub(date('2008-01-02'), INTERVAL 31 day) FROM my-index LIMIT 1` -dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date) FROM my-index LIMIT 1` -day | `day(date) -> integer` | `SELECT day(date('2020-08-25'))` -dayname | `dayname(date) -> string` | `SELECT dayname(date('2020-08-26')) FROM my-index LIMIT 1` -dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date) FROM my-index LIMIT 1` -dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date) FROM my-index LIMIT 1` -dayofyear | `dayofyear(date) -> integer` | `SELECT dayofyear(date('2020-08-26')) FROM my-index LIMIT 1` -dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26')) FROM my-index LIMIT 1` -day_of_month\* | `day_of_month(date) -> integer` | `SELECT day_of_month(date) FROM my-index LIMIT 1` -day_of_week\* | `day_of_week(date) -> integer` | `SELECT day_of_week(date('2020-08-26')) FROM my-index LIMIT 1` -day_of_year\* | `day_of_year(date) -> integer` | `SELECT day_of_year(date('2020-08-26')) FROM my-index LIMIT 1` -extract\* | `extract(part FROM date) -> integer` | `SELECT extract(MONTH FROM datetime('2020-08-26 10:11:12'))` -from_days | `from_days(N) -> integer` | `SELECT from_days(733687) FROM my-index LIMIT 1` -from_unixtime | `from_unixtime(N) -> date` | `SELECT from_unixtime(1220249547)` -get_format | `get_format(PART, string) -> string` | `SELECT get_format(DATE, 'USA')` -hour | `hour(time) -> integer` | `SELECT hour((time '01:02:03')) FROM my-index LIMIT 1` -hour_of_day\* | `hour_of_day(time) -> integer` | `SELECT hour_of_day((time '01:02:03')) FROM my-index LIMIT 1` -last_day\* | `last_day(date) -> integer` | `SELECT last_day(date('2020-08-26'))` -localtime | `localtime() -> date` | `SELECT localtime() FROM my-index LIMIT 1` -localtimestamp | `localtimestamp() -> date` | `SELECT localtimestamp() FROM my-index LIMIT 1` -makedate | `makedate(double, double) -> date` | `SELECT makedate(1945, 5.9)` -maketime | `maketime(integer, integer, integer) -> date` | `SELECT maketime(1, 2, 3) FROM my-index LIMIT 1` -microsecond | `microsecond(expr) -> integer` | `SELECT microsecond((time '01:02:03.123456')) FROM my-index LIMIT 1` -minute | `minute(expr) -> integer` | `SELECT minute((time '01:02:03')) FROM my-index LIMIT 1` -minute_of_day\* | `minute_of_day(expr) -> integer` | `SELECT minute_of_day((time '01:02:03')) FROM my-index LIMIT 1` -minute_of_hour\* | `minute_of_hour(expr) -> integer` | `SELECT minute_of_hour((time '01:02:03')) FROM my-index LIMIT 1` -month | `month(date) -> integer` | `SELECT month(date) FROM my-index` -month_of_year\* | `month_of_year(date) -> integer` | `SELECT month_of_year(date) FROM my-index` -monthname | `monthname(date) -> string` | `SELECT monthname(date) FROM my-index` -now | `now() -> date` | `SELECT now() FROM my-index LIMIT 1` -period_add | `period_add(integer, integer)` | `SELECT period_add(200801, 2)` -period_diff | `period_diff(integer, integer)` | `SELECT period_diff(200802, 200703)` -quarter | `quarter(date) -> integer` | `SELECT quarter(date('2020-08-26')) FROM my-index LIMIT 1` -second | `second(time) -> integer` | `SELECT second((time '01:02:03')) FROM my-index LIMIT 1` -second_of_minute\* | `second_of_minute(time) -> integer` | `SELECT second_of_minute((time '01:02:03')) FROM my-index LIMIT 1` -sec_to_time\* | `sec_to_time(integer) -> date` | `SELECT sec_to_time(10000)` -subdate | `subdate(date, INTERVAL expr unit) -> date, datetime` | `SELECT subdate(date('2008-01-02'), INTERVAL 31 day) FROM my-index LIMIT 1` -subtime | `subtime(date, date) -> date` | `SELECT subtime(date('2008-12-12'), date('2008-11-15'))` -str_to_date\* | `str_to_date(string, format) -> date` | `SELECT str_to_date("March 10 2000", %M %d %Y")` -time | `time(expr) -> time` | `SELECT time('13:49:00') FROM my-index LIMIT 1` -timediff | `timediff(time, time) -> time` | `SELECT timediff(time('23:59:59'), time('13:00:00'))` -timestamp | `timestamp(date) -> date` | `SELECT timestamp(date) FROM my-index LIMIT 1` -timestampadd | `timestampadd(interval, integer, date) -> date)` | `SELECT timestampadd(DAY, 17, datetime('2000-01-01 00:00:00'))` -timestampdiff | `timestampdiff(interval, date, date) -> integer` | `SELECT timestampdiff(YEAR, '1997-01-01 00:00:00, '2001-03-06 00:00:00')` -time_format | `time_format(date, string) -> string` | `SELECT time_format('1998-01-31 13:14:15.012345', '%f %H %h %I %i %p %r %S %s %T')` -time_to_sec | `time_to_sec(time) -> long` | `SELECT time_to_sec(time '22:23:00') FROM my-index LIMIT 1` -to_days | `to_days(date) -> long` | `SELECT to_days(date '2008-10-07') FROM my-index LIMIT 1` -to_seconds | `to_seconds(date) -> integer` | `SELECT to_seconds(date('2008-10-07')` -unix_timestamp | `unix_timestamp(date) -> double` | `SELECT unix_timestamp(timestamp('1996-11-15 17:05:42'))` -utc_date | `utc_date() -> date` | `SELECT utc_date()` -utc_time | `utc_time() -> date` | `SELECT utc_time()` -utc_timestamp | `utc_timestamp() -> date` | `SELECT utc_timestamp()` -week | `week(date[mode]) -> integer` | `SELECT week(date('2008-02-20')) FROM my-index LIMIT 1` -weekofyear | `weekofyear(date[mode]) -> integer` | `SELECT weekofyear(date('2008-02-20')) FROM my-index LIMIT 1` -week_of_year\* | `week_of_year(date[mode]) -> integer` | `SELECT week_of_year(date('2008-02-20')) FROM my-index LIMIT 1` -year | `year(date) -> integer` | `SELECT year(date) FROM my-index LIMIT 1` -yearweek\* | `yearweek(date[mode]) -> integer` | `SELECT yearweek(date('2008-02-20')) FROM my-index LIMIT 1` +| Function | Specification | Example | +|:-------------------|:---------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------| +| adddate | `adddate(date, INTERVAL expr unit) -> date` | `SELECT adddate(date('2020-08-26'), INTERVAL 1 hour)` | +| addtime | `addtime(date, date) -> date` | `SELECT addtime(date('2008-12-12'), date('2008-12-12'))` | +| convert_tz | `convert_tz(date, string, string) -> date` | `SELECT convert_tz('2008-12-25 05:30:00', '+00:00', 'America/Los_Angeles')` | +| curtime | `curtime() -> time` | `SELECT curtime()` | +| curdate | `curdate() -> date` | `SELECT curdate()` | +| current_date | `current_date() -> date` | `SELECT current_date()` | +| current_time | `current_time() -> time` | `SELECT current_time()` | +| current_timestamp | `current_timestamp() -> date` | `SELECT current_timestamp()` | +| date | `date(date) -> date` | `SELECT date()` | +| datediff | `datediff(date, date) -> integer` | `SELECT datediff(date('2000-01-02'), date('2000-01-01'))` | +| datetime | `datetime(string) -> datetime` | `SELECT datetime('2008-12-25 00:00:00')` | +| date_add | `date_add(date, INTERVAL integer UNIT)` | `SELECT date_add('2020-08-26'), INTERVAL 1 HOUR)` | +| date_format | `date_format(date, string) -> string` or `date_format(date, string, string) -> string` | `SELECT date_format(date('2020-08-26'), 'Y')` | +| date_sub | `date_sub(date, INTERVAL expr unit) -> date` | `SELECT date_sub(date('2008-01-02'), INTERVAL 31 day)` | +| dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2001-05-07'))` | +| day | `day(date) -> integer` | `SELECT day(date('2020-08-25'))` | +| dayname | `dayname(date) -> string` | `SELECT dayname(date('2020-08-26'))` | +| dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2020-08-26'))` | +| dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | +| dayofyear | `dayofyear(date) -> integer` | `SELECT dayofyear(date('2020-08-26'))` | +| dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | +| day_of_month\* | `day_of_month(date) -> integer` | `SELECT day_of_month(('2020-08-26'))` | +| day_of_week\* | `day_of_week(date) -> integer` | `SELECT day_of_week(date('2020-08-26'))` | +| day_of_year\* | `day_of_year(date) -> integer` | `SELECT day_of_year(date('2020-08-26'))` | +| extract\* | `extract(part FROM date) -> integer` | `SELECT extract(MONTH FROM datetime('2020-08-26 10:11:12'))` | +| from_days | `from_days(N) -> integer` | `SELECT from_days(733687)` | +| from_unixtime | `from_unixtime(N) -> date` | `SELECT from_unixtime(1220249547)` | +| get_format | `get_format(PART, string) -> string` | `SELECT get_format(DATE, 'USA')` | +| hour | `hour(time) -> integer` | `SELECT hour((time '01:02:03'))` | +| hour_of_day\* | `hour_of_day(time) -> integer` | `SELECT hour_of_day((time '01:02:03'))` | +| last_day\* | `last_day(date) -> integer` | `SELECT last_day(date('2020-08-26'))` | +| localtime | `localtime() -> date` | `SELECT localtime()` | +| localtimestamp | `localtimestamp() -> date` | `SELECT localtimestamp()` | +| makedate | `makedate(double, double) -> date` | `SELECT makedate(1945, 5.9)` | +| maketime | `maketime(integer, integer, integer) -> date` | `SELECT maketime(1, 2, 3)` | +| microsecond | `microsecond(expr) -> integer` | `SELECT microsecond((time '01:02:03.123456'))` | +| minute | `minute(expr) -> integer` | `SELECT minute((time '01:02:03'))` | +| minute_of_day\* | `minute_of_day(expr) -> integer` | `SELECT minute_of_day((time '01:02:03'))` | +| minute_of_hour\* | `minute_of_hour(expr) -> integer` | `SELECT minute_of_hour((time '01:02:03'))` | +| month | `month(date) -> integer` | `SELECT month(date('2020-08-26'))` | +| month_of_year\* | `month_of_year(date) -> integer` | `SELECT month_of_year(date('2020-08-26'))` | +| monthname | `monthname(date) -> string` | `SELECT monthname(date('2020-08-26'))` | +| now | `now() -> date` | `SELECT now()` | +| period_add | `period_add(integer, integer)` | `SELECT period_add(200801, 2)` | +| period_diff | `period_diff(integer, integer)` | `SELECT period_diff(200802, 200703)` | +| quarter | `quarter(date) -> integer` | `SELECT quarter(date('2020-08-26'))` | +| second | `second(time) -> integer` | `SELECT second((time '01:02:03'))` | +| second_of_minute\* | `second_of_minute(time) -> integer` | `SELECT second_of_minute((time '01:02:03'))` | +| sec_to_time\* | `sec_to_time(integer) -> date` | `SELECT sec_to_time(10000)` | +| subdate | `subdate(date, INTERVAL expr unit) -> date, datetime` | `SELECT subdate(date('2008-01-02'), INTERVAL 31 day)` | +| subtime | `subtime(date, date) -> date` | `SELECT subtime(date('2008-12-12'), date('2008-11-15'))` | +| str_to_date\* | `str_to_date(string, format) -> date` | `SELECT str_to_date("March 10 2000", %M %d %Y")` | +| time | `time(expr) -> time` | `SELECT time('13:49:00')` | +| timediff | `timediff(time, time) -> time` | `SELECT timediff(time('23:59:59'), time('13:00:00'))` | +| timestamp | `timestamp(date) -> date` | `SELECT timestamp('2001-05-07')` | +| timestampadd | `timestampadd(interval, integer, date) -> date)` | `SELECT timestampadd(DAY, 17, datetime('2000-01-01 00:00:00'))` | +| timestampdiff | `timestampdiff(interval, date, date) -> integer` | `SELECT timestampdiff(YEAR, '1997-01-01 00:00:00, '2001-03-06 00:00:00')` | +| time_format | `time_format(date, string) -> string` | `SELECT time_format('1998-01-31 13:14:15.012345', '%f %H %h %I %i %p %r %S %s %T')` | +| time_to_sec | `time_to_sec(time) -> long` | `SELECT time_to_sec(time '22:23:00')` | +| to_days | `to_days(date) -> long` | `SELECT to_days(date '2008-10-07')` | +| to_seconds | `to_seconds(date) -> integer` | `SELECT to_seconds(date('2008-10-07')` | +| unix_timestamp | `unix_timestamp(date) -> double` | `SELECT unix_timestamp(timestamp('1996-11-15 17:05:42'))` | +| utc_date | `utc_date() -> date` | `SELECT utc_date()` | +| utc_time | `utc_time() -> date` | `SELECT utc_time()` | +| utc_timestamp | `utc_timestamp() -> date` | `SELECT utc_timestamp()` | +| week | `week(date[mode]) -> integer` | `SELECT week(date('2008-02-20'))` | +| weekofyear | `weekofyear(date[mode]) -> integer` | `SELECT weekofyear(date('2008-02-20'))` | +| week_of_year\* | `week_of_year(date[mode]) -> integer` | `SELECT week_of_year(date('2008-02-20'))` | +| year | `year(date) -> integer` | `SELECT year(date('2001-07-05'))` | +| yearweek\* | `yearweek(date[mode]) -> integer` | `SELECT yearweek(date('2008-02-20'))` | ## String -Function | Specification | Example -:--- | :--- | :--- -ascii | `ascii(string T) -> integer` | `SELECT ascii('h')` -concat | `concat(str1, str2) -> string` | `SELECT concat('hello', 'world')` -concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws("-", "Tutorial", "is", "fun!")` -left | `left(string T, integer) -> T` | `SELECT left('hello', 2)` -length | `length(string) -> integer` | `SELECT length('hello')` -locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> INTEGER` | `SELECT locate('o', 'hello')`, `SELECT locate('l', 'hello', 3)` -replace | `replace(string T, string, string) -> T` | `SELECT replace('hello', 'l', 'x')` -right | `right(string T, integer) -> T` | `SELECT right('hello', 1)` -rtrim | `rtrim(string T) -> T` | `SELECT rtrim('hello ')` -substring | `substring(string T, integer, integer) -> T` | `SELECT substring('hello, 2, 4)` -trim | `trim(string T) -> T` | `SELECT trim(' hello')` -upper | `upper(string T) -> T` | `SELECT upper('hello world')` +| Function | Specification | Example | +|:----------|:------------------------------------------------------------------------------------|:----------------------------------------------------------------| +| ascii | `ascii(string T) -> integer` | `SELECT ascii('h')` | +| concat | `concat(str1, str2) -> string` | `SELECT concat('hello', 'world')` | +| concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws("-", "Tutorial", "is", "fun!")` | +| left | `left(string T, integer) -> T` | `SELECT left('hello', 2)` | +| length | `length(string) -> integer` | `SELECT length('hello')` | +| locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> INTEGER` | `SELECT locate('o', 'hello')`, `SELECT locate('l', 'hello', 3)` | +| replace | `replace(string T, string, string) -> T` | `SELECT replace('hello', 'l', 'x')` | +| right | `right(string T, integer) -> T` | `SELECT right('hello', 1)` | +| rtrim | `rtrim(string T) -> T` | `SELECT rtrim('hello ')` | +| substring | `substring(string T, integer, integer) -> T` | `SELECT substring('hello, 2, 4)` | +| trim | `trim(string T) -> T` | `SELECT trim(' hello')` | +| upper | `upper(string T) -> T` | `SELECT upper('hello world')` | ## Aggregate -Function | Specification | Example -:--- | :--- | :--- -avg | `avg(number T) -> T` | `SELECT avg(2, 3)` -count | `count(number T) -> T` | `SELECT count(date) FROM my-index` -min | `min(number T, number) -> T` | `SELECT min(2, 3)` -show | `show(string T) -> T` | `SHOW TABLES LIKE my-index` +| Function | Specification | Example | +|:---------|:-----------------------|:-----------------------------------| +| avg | `avg(number T) -> T` | `SELECT avg(column) FROM my-index` | +| count | `count(number T) -> T` | `SELECT count(date) FROM my-index` | +| min | `min(number T) -> T` | `SELECT min(column) FROM my-index` | +| show | `show(string T) -> T` | `SHOW TABLES LIKE my-index` | ## Advanced -Function | Specification | Example -:--- | :--- | :--- -if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1)`, `SELECT if(true, 0, 1)` -ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull('hello', 1)`, `SELECT ifnull(null, 1)` -isnull | `isnull(es_type) -> integer` | `SELECT isnull(null)`, `SELECT isnull(1)` +| Function | Specification | Example | +|:---------|:-------------------------------------------|:------------------------------------------------------| +| if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1)`, `SELECT if(true, 0, 1)` | +| ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull('hello', 1)`, `SELECT ifnull(null, 1)` | +| isnull | `isnull(es_type) -> integer` | `SELECT isnull(null)`, `SELECT isnull(1)` | ## Relevance-based search (full-text search) From 5dd158263f928a256544983da013b0c299542106 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Thu, 8 Jun 2023 13:47:27 -0700 Subject: [PATCH 6/9] updated data types of functions and made some corrections Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 68 ++++++++++++++++---------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index 5edbc5f8bc..c02614fe24 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -24,13 +24,13 @@ The SQL plugin supports the following common functions shared across the SQL and | add | `add(number T, number T) -> T` | `SELECT add(1, 5)` | | cbrt | `cbrt(number T) -> double` | `SELECT cbrt(0.5)` | | ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` | -| conv | `conv(string T, int a, int b) -> string` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10)` | -| crc32 | `crc32(string T) -> T` | `SELECT crc32('MySQL')` | -| divide | `divide(number T, number) -> T` | `SELECT divide(1, 0.5)` | +| conv | `conv(string T, integer, integer) -> string` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10)` | +| crc32 | `crc32(string) -> string` | `SELECT crc32('MySQL')` | +| divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` | | e | `e() -> double` | `SELECT e()` | -| exp | `exp(number T) -> T` | `SELECT exp(0.5)` | -| expm1 | `expm1(number T) -> T` | `SELECT expm1(0.5)` | -| floor | `floor(number T) -> T` | `SELECT floor(0.5) AS Rounded_Down` | +| exp | `exp(number T) -> double` | `SELECT exp(0.5)` | +| expm1 | `expm1(number T) -> double` | `SELECT expm1(0.5)` | +| floor | `floor(number T) -> long` | `SELECT floor(0.5) AS Rounded_Down` | | ln | `ln(number T) -> double` | `SELECT ln(10)` | | log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10)` | | log2 | `log2(number T) -> double` | `SELECT log2(10)` | @@ -39,22 +39,22 @@ The SQL plugin supports the following common functions shared across the SQL and | modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` | | multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` | | pi | `pi() -> double` | `SELECT pi()` | -| pow | `pow(number T, number T) -> T` | `SELECT pow(2, 3)` | -| power | `power(number T, number T) -> T` | `SELECT power(2, 3)` | -| rand | `rand() -> number` or `rand(number T) -> T` | `SELECT rand(0.5)` | +| pow | `pow(number T, number T) -> double` | `SELECT pow(2, 3)` | +| power | `power(number T, number T) -> double` | `SELECT power(2, 3)` | +| rand | `rand() -> float` or `rand(number T) -> float` | `SELECT rand(0.5)` | | rint | `rint(number T) -> double` | `SELECT rint(1.5)` | -| round | `round(number T) -> T` | `SELECT round(1.5)` | -| sign | `sign(number T) -> T` | `SELECT sign(1.5)` | -| signum | `signum(number T) -> int` | `SELECT signum(0.5)` | +| round | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5)` | +| sign | `sign(number T) -> integer` | `SELECT sign(1.5)` | +| signum | `signum(number T) -> integer` | `SELECT signum(0.5)` | | sqrt | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | -| strcmp | `strcmp(string T, string T) -> int` | `SELECT strcmp('hello', 'hello')` | +| strcmp | `strcmp(string T, string T) -> integer` | `SELECT strcmp('hello', 'hello')` | | subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` | | truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` | -| + | `number + number -> number` | `SELECT 1 + 5` | -| - | `number - number -> number` | `SELECT 3 - 2` | -| * | `number * number -> number` | `SELECT 2 * 3` | -| / | `number / number -> number` | `SELECT 1 / 0.5` | -| % | `number % number -> number` | `SELECT 2 % 3` | +| + | `number T + number T -> T` | `SELECT 1 + 5` | +| - | `number T - number T -> T` | `SELECT 3 - 2` | +| * | `number T * number T -> T` | `SELECT 2 * 3` | +| / | `number T / number T -> T` | `SELECT 1 / 0.5` | +| % | `number T % number T -> T` | `SELECT 2 % 3` | ## Trigonometric @@ -153,27 +153,27 @@ Functions marked with * are only available in SQL. | Function | Specification | Example | |:----------|:------------------------------------------------------------------------------------|:----------------------------------------------------------------| -| ascii | `ascii(string T) -> integer` | `SELECT ascii('h')` | -| concat | `concat(str1, str2) -> string` | `SELECT concat('hello', 'world')` | +| ascii | `ascii(string) -> integer` | `SELECT ascii('h')` | +| concat | `concat(string, string) -> string` | `SELECT concat('hello', 'world')` | | concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws("-", "Tutorial", "is", "fun!")` | -| left | `left(string T, integer) -> T` | `SELECT left('hello', 2)` | +| left | `left(string, integer) -> string` | `SELECT left('hello', 2)` | | length | `length(string) -> integer` | `SELECT length('hello')` | -| locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> INTEGER` | `SELECT locate('o', 'hello')`, `SELECT locate('l', 'hello', 3)` | -| replace | `replace(string T, string, string) -> T` | `SELECT replace('hello', 'l', 'x')` | -| right | `right(string T, integer) -> T` | `SELECT right('hello', 1)` | -| rtrim | `rtrim(string T) -> T` | `SELECT rtrim('hello ')` | -| substring | `substring(string T, integer, integer) -> T` | `SELECT substring('hello, 2, 4)` | -| trim | `trim(string T) -> T` | `SELECT trim(' hello')` | -| upper | `upper(string T) -> T` | `SELECT upper('hello world')` | +| locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> integer` | `SELECT locate('o', 'hello')`, `SELECT locate('l', 'hello', 3)` | +| replace | `replace(string, string, string) -> string` | `SELECT replace('hello', 'l', 'x')` | +| right | `right(string, integer) -> string` | `SELECT right('hello', 1)` | +| rtrim | `rtrim(string) -> string` | `SELECT rtrim('hello ')` | +| substring | `substring(string, integer, integer) -> string` | `SELECT substring('hello, 2, 4)` | +| trim | `trim(string) -> string` | `SELECT trim(' hello')` | +| upper | `upper(string) -> string` | `SELECT upper('hello world')` | ## Aggregate -| Function | Specification | Example | -|:---------|:-----------------------|:-----------------------------------| -| avg | `avg(number T) -> T` | `SELECT avg(column) FROM my-index` | -| count | `count(number T) -> T` | `SELECT count(date) FROM my-index` | -| min | `min(number T) -> T` | `SELECT min(column) FROM my-index` | -| show | `show(string T) -> T` | `SHOW TABLES LIKE my-index` | +| Function | Specification | Example | +|:---------|:-------------------------|:-----------------------------------| +| avg | `avg(number T) -> T` | `SELECT avg(column) FROM my-index` | +| count | `count(number T) -> T` | `SELECT count(date) FROM my-index` | +| min | `min(number T) -> T` | `SELECT min(column) FROM my-index` | +| show | `show(string) -> string` | `SHOW TABLES LIKE my-index` | ## Advanced From 9442d3b1e8ec65a7c0e9b166073cf2b8281553d1 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Mon, 12 Jun 2023 11:34:21 -0700 Subject: [PATCH 7/9] removed missing brackets, fixed incorrect ifnull documentation Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index c02614fe24..cf9a5b745a 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -30,9 +30,9 @@ The SQL plugin supports the following common functions shared across the SQL and | e | `e() -> double` | `SELECT e()` | | exp | `exp(number T) -> double` | `SELECT exp(0.5)` | | expm1 | `expm1(number T) -> double` | `SELECT expm1(0.5)` | -| floor | `floor(number T) -> long` | `SELECT floor(0.5) AS Rounded_Down` | +| floor | `floor(number T) -> long` | `SELECT floor(0.5)` | | ln | `ln(number T) -> double` | `SELECT ln(10)` | -| log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10)` | +| log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10), log(2, 16)` | | log2 | `log2(number T) -> double` | `SELECT log2(10)` | | log10 | `log10(number T) -> double` | `SELECT log10(10)` | | mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` | @@ -41,9 +41,9 @@ The SQL plugin supports the following common functions shared across the SQL and | pi | `pi() -> double` | `SELECT pi()` | | pow | `pow(number T, number T) -> double` | `SELECT pow(2, 3)` | | power | `power(number T, number T) -> double` | `SELECT power(2, 3)` | -| rand | `rand() -> float` or `rand(number T) -> float` | `SELECT rand(0.5)` | +| rand | `rand() -> float` or `rand(number T) -> float` | `SELECT rand(), rand(0.5)` | | rint | `rint(number T) -> double` | `SELECT rint(1.5)` | -| round | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5)` | +| round | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5), round(1.175, 2)` | | sign | `sign(number T) -> integer` | `SELECT sign(1.5)` | | signum | `signum(number T) -> integer` | `SELECT signum(0.5)` | | sqrt | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | @@ -99,24 +99,24 @@ Functions marked with * are only available in SQL. | dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | | dayofyear | `dayofyear(date) -> integer` | `SELECT dayofyear(date('2020-08-26'))` | | dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | -| day_of_month\* | `day_of_month(date) -> integer` | `SELECT day_of_month(('2020-08-26'))` | +| day_of_month\* | `day_of_month(date) -> integer` | `SELECT day_of_month(date('2020-08-26'))` | | day_of_week\* | `day_of_week(date) -> integer` | `SELECT day_of_week(date('2020-08-26'))` | | day_of_year\* | `day_of_year(date) -> integer` | `SELECT day_of_year(date('2020-08-26'))` | | extract\* | `extract(part FROM date) -> integer` | `SELECT extract(MONTH FROM datetime('2020-08-26 10:11:12'))` | | from_days | `from_days(N) -> integer` | `SELECT from_days(733687)` | | from_unixtime | `from_unixtime(N) -> date` | `SELECT from_unixtime(1220249547)` | | get_format | `get_format(PART, string) -> string` | `SELECT get_format(DATE, 'USA')` | -| hour | `hour(time) -> integer` | `SELECT hour((time '01:02:03'))` | -| hour_of_day\* | `hour_of_day(time) -> integer` | `SELECT hour_of_day((time '01:02:03'))` | +| hour | `hour(time) -> integer` | `SELECT hour(time '01:02:03')` | +| hour_of_day\* | `hour_of_day(time) -> integer` | `SELECT hour_of_day(time '01:02:03')` | | last_day\* | `last_day(date) -> integer` | `SELECT last_day(date('2020-08-26'))` | | localtime | `localtime() -> date` | `SELECT localtime()` | | localtimestamp | `localtimestamp() -> date` | `SELECT localtimestamp()` | | makedate | `makedate(double, double) -> date` | `SELECT makedate(1945, 5.9)` | | maketime | `maketime(integer, integer, integer) -> date` | `SELECT maketime(1, 2, 3)` | -| microsecond | `microsecond(expr) -> integer` | `SELECT microsecond((time '01:02:03.123456'))` | -| minute | `minute(expr) -> integer` | `SELECT minute((time '01:02:03'))` | -| minute_of_day\* | `minute_of_day(expr) -> integer` | `SELECT minute_of_day((time '01:02:03'))` | -| minute_of_hour\* | `minute_of_hour(expr) -> integer` | `SELECT minute_of_hour((time '01:02:03'))` | +| microsecond | `microsecond(expr) -> integer` | `SELECT microsecond(time '01:02:03.123456')` | +| minute | `minute(expr) -> integer` | `SELECT minute(time '01:02:03')` | +| minute_of_day\* | `minute_of_day(expr) -> integer` | `SELECT minute_of_day(time '01:02:03')` | +| minute_of_hour\* | `minute_of_hour(expr) -> integer` | `SELECT minute_of_hour(time '01:02:03')` | | month | `month(date) -> integer` | `SELECT month(date('2020-08-26'))` | | month_of_year\* | `month_of_year(date) -> integer` | `SELECT month_of_year(date('2020-08-26'))` | | monthname | `monthname(date) -> string` | `SELECT monthname(date('2020-08-26'))` | @@ -124,8 +124,8 @@ Functions marked with * are only available in SQL. | period_add | `period_add(integer, integer)` | `SELECT period_add(200801, 2)` | | period_diff | `period_diff(integer, integer)` | `SELECT period_diff(200802, 200703)` | | quarter | `quarter(date) -> integer` | `SELECT quarter(date('2020-08-26'))` | -| second | `second(time) -> integer` | `SELECT second((time '01:02:03'))` | -| second_of_minute\* | `second_of_minute(time) -> integer` | `SELECT second_of_minute((time '01:02:03'))` | +| second | `second(time) -> integer` | `SELECT second(time '01:02:03')` | +| second_of_minute\* | `second_of_minute(time) -> integer` | `SELECT second_of_minute(time '01:02:03')` | | sec_to_time\* | `sec_to_time(integer) -> date` | `SELECT sec_to_time(10000)` | | subdate | `subdate(date, INTERVAL expr unit) -> date, datetime` | `SELECT subdate(date('2008-01-02'), INTERVAL 31 day)` | | subtime | `subtime(date, date) -> date` | `SELECT subtime(date('2008-12-12'), date('2008-11-15'))` | @@ -138,7 +138,7 @@ Functions marked with * are only available in SQL. | time_format | `time_format(date, string) -> string` | `SELECT time_format('1998-01-31 13:14:15.012345', '%f %H %h %I %i %p %r %S %s %T')` | | time_to_sec | `time_to_sec(time) -> long` | `SELECT time_to_sec(time '22:23:00')` | | to_days | `to_days(date) -> long` | `SELECT to_days(date '2008-10-07')` | -| to_seconds | `to_seconds(date) -> integer` | `SELECT to_seconds(date('2008-10-07')` | +| to_seconds | `to_seconds(date) -> integer` | `SELECT to_seconds(date('2008-10-07'))` | | unix_timestamp | `unix_timestamp(date) -> double` | `SELECT unix_timestamp(timestamp('1996-11-15 17:05:42'))` | | utc_date | `utc_date() -> date` | `SELECT utc_date()` | | utc_time | `utc_time() -> date` | `SELECT utc_time()` | @@ -177,11 +177,11 @@ Functions marked with * are only available in SQL. ## Advanced -| Function | Specification | Example | -|:---------|:-------------------------------------------|:------------------------------------------------------| -| if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1)`, `SELECT if(true, 0, 1)` | -| ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull('hello', 1)`, `SELECT ifnull(null, 1)` | -| isnull | `isnull(es_type) -> integer` | `SELECT isnull(null)`, `SELECT isnull(1)` | +| Function | Specification | Example | +|:---------|:-------------------------------------------|:--------------------------------------------------| +| if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1)`, `SELECT if(true, 0, 1)` | +| ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull(0, 1)`, `SELECT ifnull(null, 1)` | +| isnull | `isnull(es_type) -> integer` | `SELECT isnull(null)`, `SELECT isnull(1)` | ## Relevance-based search (full-text search) From 66167c7576539273e82e3a233d2ea72b3c3345cb Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Mon, 12 Jun 2023 14:52:38 -0700 Subject: [PATCH 8/9] fixed more minor mistakes and confirmed all function examples work Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 122 +++++++++++++++---------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index cf9a5b745a..5c9391c05d 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -18,43 +18,43 @@ The SQL plugin supports the following common functions shared across the SQL and ## Mathematical -| Function | Specification | Example | -|:---------|:-----------------------------------------------------------------|:------------------------------------------------------------------------------------| -| abs | `abs(number T) -> T` | `SELECT abs(0.5)` | -| add | `add(number T, number T) -> T` | `SELECT add(1, 5)` | -| cbrt | `cbrt(number T) -> double` | `SELECT cbrt(0.5)` | -| ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` | -| conv | `conv(string T, integer, integer) -> string` | `SELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10)` | -| crc32 | `crc32(string) -> string` | `SELECT crc32('MySQL')` | -| divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` | -| e | `e() -> double` | `SELECT e()` | -| exp | `exp(number T) -> double` | `SELECT exp(0.5)` | -| expm1 | `expm1(number T) -> double` | `SELECT expm1(0.5)` | -| floor | `floor(number T) -> long` | `SELECT floor(0.5)` | -| ln | `ln(number T) -> double` | `SELECT ln(10)` | -| log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10), log(2, 16)` | -| log2 | `log2(number T) -> double` | `SELECT log2(10)` | -| log10 | `log10(number T) -> double` | `SELECT log10(10)` | -| mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` | -| modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` | -| multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` | -| pi | `pi() -> double` | `SELECT pi()` | -| pow | `pow(number T, number T) -> double` | `SELECT pow(2, 3)` | -| power | `power(number T, number T) -> double` | `SELECT power(2, 3)` | -| rand | `rand() -> float` or `rand(number T) -> float` | `SELECT rand(), rand(0.5)` | -| rint | `rint(number T) -> double` | `SELECT rint(1.5)` | -| round | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5), round(1.175, 2)` | -| sign | `sign(number T) -> integer` | `SELECT sign(1.5)` | -| signum | `signum(number T) -> integer` | `SELECT signum(0.5)` | -| sqrt | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | -| strcmp | `strcmp(string T, string T) -> integer` | `SELECT strcmp('hello', 'hello')` | -| subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` | -| truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` | -| + | `number T + number T -> T` | `SELECT 1 + 5` | -| - | `number T - number T -> T` | `SELECT 3 - 2` | -| * | `number T * number T -> T` | `SELECT 2 * 3` | -| / | `number T / number T -> T` | `SELECT 1 / 0.5` | -| % | `number T % number T -> T` | `SELECT 2 % 3` | +| Function | Specification | Example | +|:---------|:-----------------------------------------------------------------|:-----------------------------------------------| +| abs | `abs(number T) -> T` | `SELECT abs(0.5)` | +| add | `add(number T, number T) -> T` | `SELECT add(1, 5)` | +| cbrt | `cbrt(number T) -> double` | `SELECT cbrt(8)` | +| ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` | +| conv | `conv(string T, integer, integer) -> string` | `SELECT conv('2C', 16, 10), conv(1111, 2, 10)` | +| crc32 | `crc32(string) -> string` | `SELECT crc32('MySQL')` | +| divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` | +| e | `e() -> double` | `SELECT e()` | +| exp | `exp(number T) -> double` | `SELECT exp(0.5)` | +| expm1 | `expm1(number T) -> double` | `SELECT expm1(0.5)` | +| floor | `floor(number T) -> long` | `SELECT floor(0.5)` | +| ln | `ln(number T) -> double` | `SELECT ln(10)` | +| log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10)`, `SELECT log(2, 16)` | +| log2 | `log2(number T) -> double` | `SELECT log2(10)` | +| log10 | `log10(number T) -> double` | `SELECT log10(10)` | +| mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` | +| modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` | +| multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` | +| pi | `pi() -> double` | `SELECT pi()` | +| pow | `pow(number T, number T) -> double` | `SELECT pow(2, 3)` | +| power | `power(number T, number T) -> double` | `SELECT power(2, 3)` | +| rand | `rand() -> float` or `rand(number T) -> float` | `SELECT rand()`, `SELECT rand(0.5)` | +| rint | `rint(number T) -> double` | `SELECT rint(1.5)` | +| round | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5)`, `SELECT round(1.175, 2)` | +| sign | `sign(number T) -> integer` | `SELECT sign(1.5)` | +| signum | `signum(number T) -> integer` | `SELECT signum(0.5)` | +| sqrt | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | +| strcmp | `strcmp(string T, string T) -> integer` | `SELECT strcmp('hello', 'hello world')` | +| subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` | +| truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` | +| + | `number T + number T -> T` | `SELECT 1 + 5` | +| - | `number T - number T -> T` | `SELECT 3 - 2` | +| * | `number T * number T -> T` | `SELECT 2 * 3` | +| / | `number T / number T -> T` | `SELECT 1 / 0.5` | +| % | `number T % number T -> T` | `SELECT 2 % 3` | ## Trigonometric @@ -86,10 +86,10 @@ Functions marked with * are only available in SQL. | current_date | `current_date() -> date` | `SELECT current_date()` | | current_time | `current_time() -> time` | `SELECT current_time()` | | current_timestamp | `current_timestamp() -> date` | `SELECT current_timestamp()` | -| date | `date(date) -> date` | `SELECT date()` | +| date | `date(date) -> date` | `SELECT date('2000-01-02')` | | datediff | `datediff(date, date) -> integer` | `SELECT datediff(date('2000-01-02'), date('2000-01-01'))` | | datetime | `datetime(string) -> datetime` | `SELECT datetime('2008-12-25 00:00:00')` | -| date_add | `date_add(date, INTERVAL integer UNIT)` | `SELECT date_add('2020-08-26'), INTERVAL 1 HOUR)` | +| date_add | `date_add(date, INTERVAL integer UNIT)` | `SELECT date_add('2020-08-26', INTERVAL 1 HOUR)` | | date_format | `date_format(date, string) -> string` or `date_format(date, string, string) -> string` | `SELECT date_format(date('2020-08-26'), 'Y')` | | date_sub | `date_sub(date, INTERVAL expr unit) -> date` | `SELECT date_sub(date('2008-01-02'), INTERVAL 31 day)` | | dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2001-05-07'))` | @@ -129,12 +129,12 @@ Functions marked with * are only available in SQL. | sec_to_time\* | `sec_to_time(integer) -> date` | `SELECT sec_to_time(10000)` | | subdate | `subdate(date, INTERVAL expr unit) -> date, datetime` | `SELECT subdate(date('2008-01-02'), INTERVAL 31 day)` | | subtime | `subtime(date, date) -> date` | `SELECT subtime(date('2008-12-12'), date('2008-11-15'))` | -| str_to_date\* | `str_to_date(string, format) -> date` | `SELECT str_to_date("March 10 2000", %M %d %Y")` | +| str_to_date\* | `str_to_date(string, format) -> date` | `SELECT str_to_date("01,5,2013", "%d,%m,%Y")` | | time | `time(expr) -> time` | `SELECT time('13:49:00')` | | timediff | `timediff(time, time) -> time` | `SELECT timediff(time('23:59:59'), time('13:00:00'))` | -| timestamp | `timestamp(date) -> date` | `SELECT timestamp('2001-05-07')` | +| timestamp | `timestamp(date) -> date` | `SELECT timestamp('2001-05-07 00:00:00')` | | timestampadd | `timestampadd(interval, integer, date) -> date)` | `SELECT timestampadd(DAY, 17, datetime('2000-01-01 00:00:00'))` | -| timestampdiff | `timestampdiff(interval, date, date) -> integer` | `SELECT timestampdiff(YEAR, '1997-01-01 00:00:00, '2001-03-06 00:00:00')` | +| timestampdiff | `timestampdiff(interval, date, date) -> integer` | `SELECT timestampdiff(YEAR, '1997-01-01 00:00:00', '2001-03-06 00:00:00')` | | time_format | `time_format(date, string) -> string` | `SELECT time_format('1998-01-31 13:14:15.012345', '%f %H %h %I %i %p %r %S %s %T')` | | time_to_sec | `time_to_sec(time) -> long` | `SELECT time_to_sec(time '22:23:00')` | | to_days | `to_days(date) -> long` | `SELECT to_days(date '2008-10-07')` | @@ -151,20 +151,20 @@ Functions marked with * are only available in SQL. ## String -| Function | Specification | Example | -|:----------|:------------------------------------------------------------------------------------|:----------------------------------------------------------------| -| ascii | `ascii(string) -> integer` | `SELECT ascii('h')` | -| concat | `concat(string, string) -> string` | `SELECT concat('hello', 'world')` | -| concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws("-", "Tutorial", "is", "fun!")` | -| left | `left(string, integer) -> string` | `SELECT left('hello', 2)` | -| length | `length(string) -> integer` | `SELECT length('hello')` | -| locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> integer` | `SELECT locate('o', 'hello')`, `SELECT locate('l', 'hello', 3)` | -| replace | `replace(string, string, string) -> string` | `SELECT replace('hello', 'l', 'x')` | -| right | `right(string, integer) -> string` | `SELECT right('hello', 1)` | -| rtrim | `rtrim(string) -> string` | `SELECT rtrim('hello ')` | -| substring | `substring(string, integer, integer) -> string` | `SELECT substring('hello, 2, 4)` | -| trim | `trim(string) -> string` | `SELECT trim(' hello')` | -| upper | `upper(string) -> string` | `SELECT upper('hello world')` | +| Function | Specification | Example | +|:----------|:------------------------------------------------------------------------------------|:---------------------------------------------------------------| +| ascii | `ascii(string) -> integer` | `SELECT ascii('h')` | +| concat | `concat(string, string) -> string` | `SELECT concat('hello', 'world')` | +| concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws(" ", "Hello", "World!")` | +| left | `left(string, integer) -> string` | `SELECT left('hello', 2)` | +| length | `length(string) -> integer` | `SELECT length('hello')` | +| locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> integer` | `SELECT locate('o', 'hello')`, `locate('l', 'hello world', 5)` | +| replace | `replace(string, string, string) -> string` | `SELECT replace('hello', 'l', 'x')` | +| right | `right(string, integer) -> string` | `SELECT right('hello', 2)` | +| rtrim | `rtrim(string) -> string` | `SELECT rtrim('hello ')` | +| substring | `substring(string, integer, integer) -> string` | `SELECT substring('hello', 2, 4)` | +| trim | `trim(string) -> string` | `SELECT trim(' hello')` | +| upper | `upper(string) -> string` | `SELECT upper('hello world')` | ## Aggregate @@ -177,11 +177,11 @@ Functions marked with * are only available in SQL. ## Advanced -| Function | Specification | Example | -|:---------|:-------------------------------------------|:--------------------------------------------------| -| if | `if(boolean, es_type, es_type) -> es_type` | `SELECT if(false, 0, 1)`, `SELECT if(true, 0, 1)` | -| ifnull | `ifnull(es_type, es_type) -> es_type` | `SELECT ifnull(0, 1)`, `SELECT ifnull(null, 1)` | -| isnull | `isnull(es_type) -> integer` | `SELECT isnull(null)`, `SELECT isnull(1)` | +| Function | Specification | Example | +|:---------|:-------------------------------------------|:--------------------------------------------| +| if | `if(boolean, os_type, os_type) -> os_type` | `SELECT if(false, 0, 1),if(true, 0, 1)` | +| ifnull | `ifnull(os_type, os_type) -> os_type` | `SELECT ifnull(0, 1), ifnull(null, 1)` | +| isnull | `isnull(os_type) -> integer` | `SELECT isnull(null), isnull(1)` | ## Relevance-based search (full-text search) From b0deab104cdfda685152ea972e61d8f18fb9b512 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Mon, 12 Jun 2023 14:58:48 -0700 Subject: [PATCH 9/9] added ticks to all function names to get it to pass the linter Signed-off-by: Matthew Wells --- _search-plugins/sql/functions.md | 292 +++++++++++++++---------------- 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/_search-plugins/sql/functions.md b/_search-plugins/sql/functions.md index 5c9391c05d..de3b578e1a 100644 --- a/_search-plugins/sql/functions.md +++ b/_search-plugins/sql/functions.md @@ -18,170 +18,170 @@ The SQL plugin supports the following common functions shared across the SQL and ## Mathematical -| Function | Specification | Example | -|:---------|:-----------------------------------------------------------------|:-----------------------------------------------| -| abs | `abs(number T) -> T` | `SELECT abs(0.5)` | -| add | `add(number T, number T) -> T` | `SELECT add(1, 5)` | -| cbrt | `cbrt(number T) -> double` | `SELECT cbrt(8)` | -| ceil | `ceil(number T) -> T` | `SELECT ceil(0.5)` | -| conv | `conv(string T, integer, integer) -> string` | `SELECT conv('2C', 16, 10), conv(1111, 2, 10)` | -| crc32 | `crc32(string) -> string` | `SELECT crc32('MySQL')` | -| divide | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` | -| e | `e() -> double` | `SELECT e()` | -| exp | `exp(number T) -> double` | `SELECT exp(0.5)` | -| expm1 | `expm1(number T) -> double` | `SELECT expm1(0.5)` | -| floor | `floor(number T) -> long` | `SELECT floor(0.5)` | -| ln | `ln(number T) -> double` | `SELECT ln(10)` | -| log | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10)`, `SELECT log(2, 16)` | -| log2 | `log2(number T) -> double` | `SELECT log2(10)` | -| log10 | `log10(number T) -> double` | `SELECT log10(10)` | -| mod | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` | -| modulus | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` | -| multiply | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` | -| pi | `pi() -> double` | `SELECT pi()` | -| pow | `pow(number T, number T) -> double` | `SELECT pow(2, 3)` | -| power | `power(number T, number T) -> double` | `SELECT power(2, 3)` | -| rand | `rand() -> float` or `rand(number T) -> float` | `SELECT rand()`, `SELECT rand(0.5)` | -| rint | `rint(number T) -> double` | `SELECT rint(1.5)` | -| round | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5)`, `SELECT round(1.175, 2)` | -| sign | `sign(number T) -> integer` | `SELECT sign(1.5)` | -| signum | `signum(number T) -> integer` | `SELECT signum(0.5)` | -| sqrt | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | -| strcmp | `strcmp(string T, string T) -> integer` | `SELECT strcmp('hello', 'hello world')` | -| subtract | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` | -| truncate | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` | -| + | `number T + number T -> T` | `SELECT 1 + 5` | -| - | `number T - number T -> T` | `SELECT 3 - 2` | -| * | `number T * number T -> T` | `SELECT 2 * 3` | -| / | `number T / number T -> T` | `SELECT 1 / 0.5` | -| % | `number T % number T -> T` | `SELECT 2 % 3` | +| Function | Specification | Example | +|:-----------|:-----------------------------------------------------------------|:-----------------------------------------------| +| `abs` | `abs(number T) -> T` | `SELECT abs(0.5)` | +| `add` | `add(number T, number T) -> T` | `SELECT add(1, 5)` | +| `cbrt` | `cbrt(number T) -> double` | `SELECT cbrt(8)` | +| `ceil` | `ceil(number T) -> T` | `SELECT ceil(0.5)` | +| `conv` | `conv(string T, integer, integer) -> string` | `SELECT conv('2C', 16, 10), conv(1111, 2, 10)` | +| `crc32` | `crc32(string) -> string` | `SELECT crc32('MySQL')` | +| `divide` | `divide(number T, number T) -> T` | `SELECT divide(1, 0.5)` | +| `e` | `e() -> double` | `SELECT e()` | +| `exp` | `exp(number T) -> double` | `SELECT exp(0.5)` | +| `expm1` | `expm1(number T) -> double` | `SELECT expm1(0.5)` | +| `floor` | `floor(number T) -> long` | `SELECT floor(0.5)` | +| `ln` | `ln(number T) -> double` | `SELECT ln(10)` | +| `log` | `log(number T) -> double` or `log(number T, number T) -> double` | `SELECT log(10)`, `SELECT log(2, 16)` | +| `log2` | `log2(number T) -> double` | `SELECT log2(10)` | +| `log10` | `log10(number T) -> double` | `SELECT log10(10)` | +| `mod` | `mod(number T, number T) -> T` | `SELECT mod(2, 3)` | +| `modulus` | `modulus(number T, number T) -> T` | `SELECT modulus(2, 3)` | +| `multiply` | `multiply(number T, number T) -> T` | `SELECT multiply(2, 3)` | +| `pi` | `pi() -> double` | `SELECT pi()` | +| `pow` | `pow(number T, number T) -> double` | `SELECT pow(2, 3)` | +| `power` | `power(number T, number T) -> double` | `SELECT power(2, 3)` | +| `rand` | `rand() -> float` or `rand(number T) -> float` | `SELECT rand()`, `SELECT rand(0.5)` | +| `rint` | `rint(number T) -> double` | `SELECT rint(1.5)` | +| `round` | `round(number T) -> T` or `round(number T, integer) -> T` | `SELECT round(1.5)`, `SELECT round(1.175, 2)` | +| `sign` | `sign(number T) -> integer` | `SELECT sign(1.5)` | +| `signum` | `signum(number T) -> integer` | `SELECT signum(0.5)` | +| `sqrt` | `sqrt(number T) -> double` | `SELECT sqrt(0.5)` | +| `strcmp` | `strcmp(string T, string T) -> integer` | `SELECT strcmp('hello', 'hello world')` | +| `subtract` | `subtract(number T, number T) -> T` | `SELECT subtract(3, 2)` | +| `truncate` | `truncate(number T, number T) -> T` | `SELECT truncate(56.78, 1)` | +| `+` | `number T + number T -> T` | `SELECT 1 + 5` | +| `-` | `number T - number T -> T` | `SELECT 3 - 2` | +| `*` | `number T * number T -> T` | `SELECT 2 * 3` | +| `/` | `number T / number T -> T` | `SELECT 1 / 0.5` | +| `%` | `number T % number T -> T` | `SELECT 2 % 3` | ## Trigonometric -| Function | Specification | Example | -|:---------|:--------------------------------------|:-----------------------| -| acos | `acos(number T) -> double` | `SELECT acos(0.5)` | -| asin | `asin(number T) -> double` | `SELECT asin(0.5)` | -| atan | `atan(number T) -> double` | `SELECT atan(0.5)` | -| atan2 | `atan2(number T, number T) -> double` | `SELECT atan2(1, 0.5)` | -| cos | `cos(number T) -> double` | `SELECT cos(0.5)` | -| cosh | `cosh(number T) -> double` | `SELECT cosh(0.5)` | -| cot | `cot(number T) -> double` | `SELECT cot(0.5)` | -| degrees | `degrees(number T) -> double` | `SELECT degrees(0.5)` | -| radians | `radians(number T) -> double` | `SELECT radians(0.5)` | -| sin | `sin(number T) -> double` | `SELECT sin(0.5)` | -| sinh | `sinh(number T) -> double` | `SELECT sinh(0.5)` | -| tan | `tan(number T) -> double` | `SELECT tan(0.5)` | +| Function | Specification | Example | +|:----------|:--------------------------------------|:-----------------------| +| `acos` | `acos(number T) -> double` | `SELECT acos(0.5)` | +| `asin` | `asin(number T) -> double` | `SELECT asin(0.5)` | +| `atan` | `atan(number T) -> double` | `SELECT atan(0.5)` | +| `atan2` | `atan2(number T, number T) -> double` | `SELECT atan2(1, 0.5)` | +| `cos` | `cos(number T) -> double` | `SELECT cos(0.5)` | +| `cosh` | `cosh(number T) -> double` | `SELECT cosh(0.5)` | +| `cot` | `cot(number T) -> double` | `SELECT cot(0.5)` | +| `degrees` | `degrees(number T) -> double` | `SELECT degrees(0.5)` | +| `radians` | `radians(number T) -> double` | `SELECT radians(0.5)` | +| `sin` | `sin(number T) -> double` | `SELECT sin(0.5)` | +| `sinh` | `sinh(number T) -> double` | `SELECT sinh(0.5)` | +| `tan` | `tan(number T) -> double` | `SELECT tan(0.5)` | ## Date and time Functions marked with * are only available in SQL. -| Function | Specification | Example | -|:-------------------|:---------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------| -| adddate | `adddate(date, INTERVAL expr unit) -> date` | `SELECT adddate(date('2020-08-26'), INTERVAL 1 hour)` | -| addtime | `addtime(date, date) -> date` | `SELECT addtime(date('2008-12-12'), date('2008-12-12'))` | -| convert_tz | `convert_tz(date, string, string) -> date` | `SELECT convert_tz('2008-12-25 05:30:00', '+00:00', 'America/Los_Angeles')` | -| curtime | `curtime() -> time` | `SELECT curtime()` | -| curdate | `curdate() -> date` | `SELECT curdate()` | -| current_date | `current_date() -> date` | `SELECT current_date()` | -| current_time | `current_time() -> time` | `SELECT current_time()` | -| current_timestamp | `current_timestamp() -> date` | `SELECT current_timestamp()` | -| date | `date(date) -> date` | `SELECT date('2000-01-02')` | -| datediff | `datediff(date, date) -> integer` | `SELECT datediff(date('2000-01-02'), date('2000-01-01'))` | -| datetime | `datetime(string) -> datetime` | `SELECT datetime('2008-12-25 00:00:00')` | -| date_add | `date_add(date, INTERVAL integer UNIT)` | `SELECT date_add('2020-08-26', INTERVAL 1 HOUR)` | -| date_format | `date_format(date, string) -> string` or `date_format(date, string, string) -> string` | `SELECT date_format(date('2020-08-26'), 'Y')` | -| date_sub | `date_sub(date, INTERVAL expr unit) -> date` | `SELECT date_sub(date('2008-01-02'), INTERVAL 31 day)` | -| dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2001-05-07'))` | -| day | `day(date) -> integer` | `SELECT day(date('2020-08-25'))` | -| dayname | `dayname(date) -> string` | `SELECT dayname(date('2020-08-26'))` | -| dayofmonth | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2020-08-26'))` | -| dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | -| dayofyear | `dayofyear(date) -> integer` | `SELECT dayofyear(date('2020-08-26'))` | -| dayofweek | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | -| day_of_month\* | `day_of_month(date) -> integer` | `SELECT day_of_month(date('2020-08-26'))` | -| day_of_week\* | `day_of_week(date) -> integer` | `SELECT day_of_week(date('2020-08-26'))` | -| day_of_year\* | `day_of_year(date) -> integer` | `SELECT day_of_year(date('2020-08-26'))` | -| extract\* | `extract(part FROM date) -> integer` | `SELECT extract(MONTH FROM datetime('2020-08-26 10:11:12'))` | -| from_days | `from_days(N) -> integer` | `SELECT from_days(733687)` | -| from_unixtime | `from_unixtime(N) -> date` | `SELECT from_unixtime(1220249547)` | -| get_format | `get_format(PART, string) -> string` | `SELECT get_format(DATE, 'USA')` | -| hour | `hour(time) -> integer` | `SELECT hour(time '01:02:03')` | -| hour_of_day\* | `hour_of_day(time) -> integer` | `SELECT hour_of_day(time '01:02:03')` | -| last_day\* | `last_day(date) -> integer` | `SELECT last_day(date('2020-08-26'))` | -| localtime | `localtime() -> date` | `SELECT localtime()` | -| localtimestamp | `localtimestamp() -> date` | `SELECT localtimestamp()` | -| makedate | `makedate(double, double) -> date` | `SELECT makedate(1945, 5.9)` | -| maketime | `maketime(integer, integer, integer) -> date` | `SELECT maketime(1, 2, 3)` | -| microsecond | `microsecond(expr) -> integer` | `SELECT microsecond(time '01:02:03.123456')` | -| minute | `minute(expr) -> integer` | `SELECT minute(time '01:02:03')` | -| minute_of_day\* | `minute_of_day(expr) -> integer` | `SELECT minute_of_day(time '01:02:03')` | -| minute_of_hour\* | `minute_of_hour(expr) -> integer` | `SELECT minute_of_hour(time '01:02:03')` | -| month | `month(date) -> integer` | `SELECT month(date('2020-08-26'))` | -| month_of_year\* | `month_of_year(date) -> integer` | `SELECT month_of_year(date('2020-08-26'))` | -| monthname | `monthname(date) -> string` | `SELECT monthname(date('2020-08-26'))` | -| now | `now() -> date` | `SELECT now()` | -| period_add | `period_add(integer, integer)` | `SELECT period_add(200801, 2)` | -| period_diff | `period_diff(integer, integer)` | `SELECT period_diff(200802, 200703)` | -| quarter | `quarter(date) -> integer` | `SELECT quarter(date('2020-08-26'))` | -| second | `second(time) -> integer` | `SELECT second(time '01:02:03')` | -| second_of_minute\* | `second_of_minute(time) -> integer` | `SELECT second_of_minute(time '01:02:03')` | -| sec_to_time\* | `sec_to_time(integer) -> date` | `SELECT sec_to_time(10000)` | -| subdate | `subdate(date, INTERVAL expr unit) -> date, datetime` | `SELECT subdate(date('2008-01-02'), INTERVAL 31 day)` | -| subtime | `subtime(date, date) -> date` | `SELECT subtime(date('2008-12-12'), date('2008-11-15'))` | -| str_to_date\* | `str_to_date(string, format) -> date` | `SELECT str_to_date("01,5,2013", "%d,%m,%Y")` | -| time | `time(expr) -> time` | `SELECT time('13:49:00')` | -| timediff | `timediff(time, time) -> time` | `SELECT timediff(time('23:59:59'), time('13:00:00'))` | -| timestamp | `timestamp(date) -> date` | `SELECT timestamp('2001-05-07 00:00:00')` | -| timestampadd | `timestampadd(interval, integer, date) -> date)` | `SELECT timestampadd(DAY, 17, datetime('2000-01-01 00:00:00'))` | -| timestampdiff | `timestampdiff(interval, date, date) -> integer` | `SELECT timestampdiff(YEAR, '1997-01-01 00:00:00', '2001-03-06 00:00:00')` | -| time_format | `time_format(date, string) -> string` | `SELECT time_format('1998-01-31 13:14:15.012345', '%f %H %h %I %i %p %r %S %s %T')` | -| time_to_sec | `time_to_sec(time) -> long` | `SELECT time_to_sec(time '22:23:00')` | -| to_days | `to_days(date) -> long` | `SELECT to_days(date '2008-10-07')` | -| to_seconds | `to_seconds(date) -> integer` | `SELECT to_seconds(date('2008-10-07'))` | -| unix_timestamp | `unix_timestamp(date) -> double` | `SELECT unix_timestamp(timestamp('1996-11-15 17:05:42'))` | -| utc_date | `utc_date() -> date` | `SELECT utc_date()` | -| utc_time | `utc_time() -> date` | `SELECT utc_time()` | -| utc_timestamp | `utc_timestamp() -> date` | `SELECT utc_timestamp()` | -| week | `week(date[mode]) -> integer` | `SELECT week(date('2008-02-20'))` | -| weekofyear | `weekofyear(date[mode]) -> integer` | `SELECT weekofyear(date('2008-02-20'))` | -| week_of_year\* | `week_of_year(date[mode]) -> integer` | `SELECT week_of_year(date('2008-02-20'))` | -| year | `year(date) -> integer` | `SELECT year(date('2001-07-05'))` | -| yearweek\* | `yearweek(date[mode]) -> integer` | `SELECT yearweek(date('2008-02-20'))` | +| Function | Specification | Example | +|:---------------------|:---------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------| +| `adddate` | `adddate(date, INTERVAL expr unit) -> date` | `SELECT adddate(date('2020-08-26'), INTERVAL 1 hour)` | +| `addtime` | `addtime(date, date) -> date` | `SELECT addtime(date('2008-12-12'), date('2008-12-12'))` | +| `convert_tz` | `convert_tz(date, string, string) -> date` | `SELECT convert_tz('2008-12-25 05:30:00', '+00:00', 'America/Los_Angeles')` | +| `curtime` | `curtime() -> time` | `SELECT curtime()` | +| `curdate` | `curdate() -> date` | `SELECT curdate()` | +| `current_date` | `current_date() -> date` | `SELECT current_date()` | +| `current_time` | `current_time() -> time` | `SELECT current_time()` | +| `current_timestamp` | `current_timestamp() -> date` | `SELECT current_timestamp()` | +| `date` | `date(date) -> date` | `SELECT date('2000-01-02')` | +| `datediff` | `datediff(date, date) -> integer` | `SELECT datediff(date('2000-01-02'), date('2000-01-01'))` | +| `datetime` | `datetime(string) -> datetime` | `SELECT datetime('2008-12-25 00:00:00')` | +| `date_add` | `date_add(date, INTERVAL integer UNIT)` | `SELECT date_add('2020-08-26', INTERVAL 1 HOUR)` | +| `date_format` | `date_format(date, string) -> string` or `date_format(date, string, string) -> string` | `SELECT date_format(date('2020-08-26'), 'Y')` | +| `date_sub` | `date_sub(date, INTERVAL expr unit) -> date` | `SELECT date_sub(date('2008-01-02'), INTERVAL 31 day)` | +| `dayofmonth` | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2001-05-07'))` | +| `day` | `day(date) -> integer` | `SELECT day(date('2020-08-25'))` | +| `dayname` | `dayname(date) -> string` | `SELECT dayname(date('2020-08-26'))` | +| `dayofmonth` | `dayofmonth(date) -> integer` | `SELECT dayofmonth(date('2020-08-26'))` | +| `dayofweek` | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | +| `dayofyear` | `dayofyear(date) -> integer` | `SELECT dayofyear(date('2020-08-26'))` | +| `dayofweek` | `dayofweek(date) -> integer` | `SELECT dayofweek(date('2020-08-26'))` | +| `day_of_month`\* | `day_of_month(date) -> integer` | `SELECT day_of_month(date('2020-08-26'))` | +| `day_of_week`\* | `day_of_week(date) -> integer` | `SELECT day_of_week(date('2020-08-26'))` | +| `day_of_year`\* | `day_of_year(date) -> integer` | `SELECT day_of_year(date('2020-08-26'))` | +| `extract`\* | `extract(part FROM date) -> integer` | `SELECT extract(MONTH FROM datetime('2020-08-26 10:11:12'))` | +| `from_days` | `from_days(N) -> integer` | `SELECT from_days(733687)` | +| `from_unixtime` | `from_unixtime(N) -> date` | `SELECT from_unixtime(1220249547)` | +| `get_format` | `get_format(PART, string) -> string` | `SELECT get_format(DATE, 'USA')` | +| `hour` | `hour(time) -> integer` | `SELECT hour(time '01:02:03')` | +| `hour_of_day`\* | `hour_of_day(time) -> integer` | `SELECT hour_of_day(time '01:02:03')` | +| `last_day`\* | `last_day(date) -> integer` | `SELECT last_day(date('2020-08-26'))` | +| `localtime` | `localtime() -> date` | `SELECT localtime()` | +| `localtimestamp` | `localtimestamp() -> date` | `SELECT localtimestamp()` | +| `makedate` | `makedate(double, double) -> date` | `SELECT makedate(1945, 5.9)` | +| `maketime` | `maketime(integer, integer, integer) -> date` | `SELECT maketime(1, 2, 3)` | +| `microsecond` | `microsecond(expr) -> integer` | `SELECT microsecond(time '01:02:03.123456')` | +| `minute` | `minute(expr) -> integer` | `SELECT minute(time '01:02:03')` | +| `minute_of_day`\* | `minute_of_day(expr) -> integer` | `SELECT minute_of_day(time '01:02:03')` | +| `minute_of_hour`\* | `minute_of_hour(expr) -> integer` | `SELECT minute_of_hour(time '01:02:03')` | +| `month` | `month(date) -> integer` | `SELECT month(date('2020-08-26'))` | +| `month_of_year`\* | `month_of_year(date) -> integer` | `SELECT month_of_year(date('2020-08-26'))` | +| `monthname` | `monthname(date) -> string` | `SELECT monthname(date('2020-08-26'))` | +| `now` | `now() -> date` | `SELECT now()` | +| `period_add` | `period_add(integer, integer)` | `SELECT period_add(200801, 2)` | +| `period_diff` | `period_diff(integer, integer)` | `SELECT period_diff(200802, 200703)` | +| `quarter` | `quarter(date) -> integer` | `SELECT quarter(date('2020-08-26'))` | +| `second` | `second(time) -> integer` | `SELECT second(time '01:02:03')` | +| `second_of_minute`\* | `second_of_minute(time) -> integer` | `SELECT second_of_minute(time '01:02:03')` | +| `sec_to_time`\* | `sec_to_time(integer) -> date` | `SELECT sec_to_time(10000)` | +| `subdate` | `subdate(date, INTERVAL expr unit) -> date, datetime` | `SELECT subdate(date('2008-01-02'), INTERVAL 31 day)` | +| `subtime` | `subtime(date, date) -> date` | `SELECT subtime(date('2008-12-12'), date('2008-11-15'))` | +| `str_to_date`\* | `str_to_date(string, format) -> date` | `SELECT str_to_date("01,5,2013", "%d,%m,%Y")` | +| `time` | `time(expr) -> time` | `SELECT time('13:49:00')` | +| `timediff` | `timediff(time, time) -> time` | `SELECT timediff(time('23:59:59'), time('13:00:00'))` | +| `timestamp` | `timestamp(date) -> date` | `SELECT timestamp('2001-05-07 00:00:00')` | +| `timestampadd` | `timestampadd(interval, integer, date) -> date)` | `SELECT timestampadd(DAY, 17, datetime('2000-01-01 00:00:00'))` | +| `timestampdiff` | `timestampdiff(interval, date, date) -> integer` | `SELECT timestampdiff(YEAR, '1997-01-01 00:00:00', '2001-03-06 00:00:00')` | +| `time_format` | `time_format(date, string) -> string` | `SELECT time_format('1998-01-31 13:14:15.012345', '%f %H %h %I %i %p %r %S %s %T')` | +| `time_to_sec` | `time_to_sec(time) -> long` | `SELECT time_to_sec(time '22:23:00')` | +| `to_days` | `to_days(date) -> long` | `SELECT to_days(date '2008-10-07')` | +| `to_seconds` | `to_seconds(date) -> integer` | `SELECT to_seconds(date('2008-10-07'))` | +| `unix_timestamp` | `unix_timestamp(date) -> double` | `SELECT unix_timestamp(timestamp('1996-11-15 17:05:42'))` | +| `utc_date` | `utc_date() -> date` | `SELECT utc_date()` | +| `utc_time` | `utc_time() -> date` | `SELECT utc_time()` | +| `utc_timestamp` | `utc_timestamp() -> date` | `SELECT utc_timestamp()` | +| `week` | `week(date[mode]) -> integer` | `SELECT week(date('2008-02-20'))` | +| `weekofyear` | `weekofyear(date[mode]) -> integer` | `SELECT weekofyear(date('2008-02-20'))` | +| `week_of_year`\* | `week_of_year(date[mode]) -> integer` | `SELECT week_of_year(date('2008-02-20'))` | +| `year` | `year(date) -> integer` | `SELECT year(date('2001-07-05'))` | +| `yearweek`\* | `yearweek(date[mode]) -> integer` | `SELECT yearweek(date('2008-02-20'))` | ## String -| Function | Specification | Example | -|:----------|:------------------------------------------------------------------------------------|:---------------------------------------------------------------| -| ascii | `ascii(string) -> integer` | `SELECT ascii('h')` | -| concat | `concat(string, string) -> string` | `SELECT concat('hello', 'world')` | -| concat_ws | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws(" ", "Hello", "World!")` | -| left | `left(string, integer) -> string` | `SELECT left('hello', 2)` | -| length | `length(string) -> integer` | `SELECT length('hello')` | -| locate | `locate(string, string, integer) -> integer` or `locate(string, string) -> integer` | `SELECT locate('o', 'hello')`, `locate('l', 'hello world', 5)` | -| replace | `replace(string, string, string) -> string` | `SELECT replace('hello', 'l', 'x')` | -| right | `right(string, integer) -> string` | `SELECT right('hello', 2)` | -| rtrim | `rtrim(string) -> string` | `SELECT rtrim('hello ')` | -| substring | `substring(string, integer, integer) -> string` | `SELECT substring('hello', 2, 4)` | -| trim | `trim(string) -> string` | `SELECT trim(' hello')` | -| upper | `upper(string) -> string` | `SELECT upper('hello world')` | +| Function | Specification | Example | +|:------------|:------------------------------------------------------------------------------------|:---------------------------------------------------------------| +| `ascii` | `ascii(string) -> integer` | `SELECT ascii('h')` | +| `concat` | `concat(string, string) -> string` | `SELECT concat('hello', 'world')` | +| `concat_ws` | `concat_ws(separator, string, string…) -> string` | `SELECT concat_ws(" ", "Hello", "World!")` | +| `left` | `left(string, integer) -> string` | `SELECT left('hello', 2)` | +| `length` | `length(string) -> integer` | `SELECT length('hello')` | +| `locate` | `locate(string, string, integer) -> integer` or `locate(string, string) -> integer` | `SELECT locate('o', 'hello')`, `locate('l', 'hello world', 5)` | +| `replace` | `replace(string, string, string) -> string` | `SELECT replace('hello', 'l', 'x')` | +| `right` | `right(string, integer) -> string` | `SELECT right('hello', 2)` | +| `rtrim` | `rtrim(string) -> string` | `SELECT rtrim('hello ')` | +| `substring` | `substring(string, integer, integer) -> string` | `SELECT substring('hello', 2, 4)` | +| `trim` | `trim(string) -> string` | `SELECT trim(' hello')` | +| `upper` | `upper(string) -> string` | `SELECT upper('hello world')` | ## Aggregate | Function | Specification | Example | |:---------|:-------------------------|:-----------------------------------| -| avg | `avg(number T) -> T` | `SELECT avg(column) FROM my-index` | -| count | `count(number T) -> T` | `SELECT count(date) FROM my-index` | -| min | `min(number T) -> T` | `SELECT min(column) FROM my-index` | -| show | `show(string) -> string` | `SHOW TABLES LIKE my-index` | +| `avg` | `avg(number T) -> T` | `SELECT avg(column) FROM my-index` | +| `count` | `count(number T) -> T` | `SELECT count(date) FROM my-index` | +| `min` | `min(number T) -> T` | `SELECT min(column) FROM my-index` | +| `show` | `show(string) -> string` | `SHOW TABLES LIKE my-index` | ## Advanced -| Function | Specification | Example | -|:---------|:-------------------------------------------|:--------------------------------------------| -| if | `if(boolean, os_type, os_type) -> os_type` | `SELECT if(false, 0, 1),if(true, 0, 1)` | -| ifnull | `ifnull(os_type, os_type) -> os_type` | `SELECT ifnull(0, 1), ifnull(null, 1)` | -| isnull | `isnull(os_type) -> integer` | `SELECT isnull(null), isnull(1)` | +| Function | Specification | Example | +|:---------|:-------------------------------------------|:----------------------------------------| +| `if` | `if(boolean, os_type, os_type) -> os_type` | `SELECT if(false, 0, 1),if(true, 0, 1)` | +| `ifnull` | `ifnull(os_type, os_type) -> os_type` | `SELECT ifnull(0, 1), ifnull(null, 1)` | +| `isnull` | `isnull(os_type) -> integer` | `SELECT isnull(null), isnull(1)` | ## Relevance-based search (full-text search)