From 4941aec7304e17091d2a8296b04cbb6984f742c6 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 12 Mar 2025 09:21:42 -0600 Subject: [PATCH] Updates SQL reference (#5886) * sql reference updates * updated emphasis markers to pass lint --- .../reference/sql/functions/binary-string.md | 19 ++ .../reference/sql/functions/hashing.md | 19 ++ .../reference/sql/operators/comparison.md | 28 +- .../reference/sql/functions/binary-string.md | 19 ++ .../reference/sql/functions/hashing.md | 19 ++ .../reference/sql/operators/comparison.md | 28 +- .../reference/sql/functions/binary-string.md | 19 ++ .../reference/sql/functions/hashing.md | 19 ++ .../reference/sql/operators/comparison.md | 28 +- .../reference/sql/functions/binary-string.md | 19 ++ .../core/reference/sql/functions/hashing.md | 19 ++ .../reference/sql/operators/comparison.md | 28 +- .../reference/sql/functions/binary-string.md | 19 ++ .../reference/sql/functions/hashing.md | 19 ++ .../reference/sql/operators/comparison.md | 28 +- .../sql-reference/functions/aggregate.md | 276 ++++++++++++++---- .../sql-reference/functions/binary-string.md | 68 +++++ .../sql-reference/functions/conditional.md | 122 ++++++++ .../shared/sql-reference/functions/hashing.md | 231 +++++++++++++++ .../shared/sql-reference/functions/math.md | 113 +++---- .../shared/sql-reference/functions/misc.md | 9 + .../functions/regular-expression.md | 56 +++- .../sql-reference/functions/selector.md | 92 ++++-- .../shared/sql-reference/functions/string.md | 189 +++++------- .../sql-reference/functions/time-and-date.md | 28 +- .../sql-reference/operators/comparison.md | 165 ++++++++++- 26 files changed, 1334 insertions(+), 345 deletions(-) create mode 100644 content/influxdb3/cloud-dedicated/reference/sql/functions/binary-string.md create mode 100644 content/influxdb3/cloud-dedicated/reference/sql/functions/hashing.md create mode 100644 content/influxdb3/cloud-serverless/reference/sql/functions/binary-string.md create mode 100644 content/influxdb3/cloud-serverless/reference/sql/functions/hashing.md create mode 100644 content/influxdb3/clustered/reference/sql/functions/binary-string.md create mode 100644 content/influxdb3/clustered/reference/sql/functions/hashing.md create mode 100644 content/influxdb3/core/reference/sql/functions/binary-string.md create mode 100644 content/influxdb3/core/reference/sql/functions/hashing.md create mode 100644 content/influxdb3/enterprise/reference/sql/functions/binary-string.md create mode 100644 content/influxdb3/enterprise/reference/sql/functions/hashing.md create mode 100644 content/shared/sql-reference/functions/binary-string.md create mode 100644 content/shared/sql-reference/functions/hashing.md diff --git a/content/influxdb3/cloud-dedicated/reference/sql/functions/binary-string.md b/content/influxdb3/cloud-dedicated/reference/sql/functions/binary-string.md new file mode 100644 index 000000000..0ab01ed56 --- /dev/null +++ b/content/influxdb3/cloud-dedicated/reference/sql/functions/binary-string.md @@ -0,0 +1,19 @@ +--- +title: SQL binary string functions +list_title: Binary string functions +description: > + Use binary string functions to encode and decode binary string values in + SQL queries. +menu: + influxdb3_cloud_dedicated: + name: Binary string + parent: sql-functions +weight: 308 + +source: /content/shared/sql-reference/functions/binary-string.md +--- + + diff --git a/content/influxdb3/cloud-dedicated/reference/sql/functions/hashing.md b/content/influxdb3/cloud-dedicated/reference/sql/functions/hashing.md new file mode 100644 index 000000000..1241011f5 --- /dev/null +++ b/content/influxdb3/cloud-dedicated/reference/sql/functions/hashing.md @@ -0,0 +1,19 @@ +--- +title: SQL hashing functions +list_title: Hashing functions +description: > + Use hashing functions to hash string values in SQL queries using established + hashing algorithms. +menu: + influxdb3_cloud_dedicated: + name: Hashing + parent: sql-functions +weight: 309 + +source: /shared/sql-reference/functions/hashing.md +--- + + diff --git a/content/influxdb3/cloud-dedicated/reference/sql/operators/comparison.md b/content/influxdb3/cloud-dedicated/reference/sql/operators/comparison.md index 5b62f6189..e0ce9d05c 100644 --- a/content/influxdb3/cloud-dedicated/reference/sql/operators/comparison.md +++ b/content/influxdb3/cloud-dedicated/reference/sql/operators/comparison.md @@ -10,19 +10,21 @@ menu: parent: Operators weight: 302 list_code_example: | - | Operator | Meaning | Example | - | :------: | :------------------------------------------------------- | :---------------- | - | `=` | Equal to | `123 = 123` | - | `<>` | Not equal to | `123 <> 456` | - | `!=` | Not equal to | `123 != 456` | - | `>` | Greater than | `3 > 2` | - | `>=` | Greater than or equal to | `3 >= 2` | - | `<` | Less than | `1 < 2` | - | `<=` | Less than or equal to | `1 <= 2` | - | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | - | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | - | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | - | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | + | Operator | Meaning | Example | + | :--------------------: | :------------------------------------------------------- | :------------------------- | + | `=` | Equal to | `123 = 123` | + | `<>` | Not equal to | `123 <> 456` | + | `!=` | Not equal to | `123 != 456` | + | `>` | Greater than | `3 > 2` | + | `>=` | Greater than or equal to | `3 >= 2` | + | `<` | Less than | `1 < 2` | + | `<=` | Less than or equal to | `1 <= 2` | + | `IS DISTINCT FROM` | Is distinct from | `0 IS DISTINCT FROM 1` | + | `IS NOT DISTINCT FROM` | Is not distinct from | `0 IS NOT DISTINCT FROM 1` | + | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | + | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | + | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | + | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | source: /content/shared/sql-reference/operators/comparison.md --- diff --git a/content/influxdb3/cloud-serverless/reference/sql/functions/binary-string.md b/content/influxdb3/cloud-serverless/reference/sql/functions/binary-string.md new file mode 100644 index 000000000..1bf81bfc1 --- /dev/null +++ b/content/influxdb3/cloud-serverless/reference/sql/functions/binary-string.md @@ -0,0 +1,19 @@ +--- +title: SQL binary string functions +list_title: Binary string functions +description: > + Use binary string functions to encode and decode binary string values in + SQL queries. +menu: + influxdb3_cloud_serverless: + name: Binary string + parent: sql-functions +weight: 308 + +source: /content/shared/sql-reference/functions/binary-string.md +--- + + diff --git a/content/influxdb3/cloud-serverless/reference/sql/functions/hashing.md b/content/influxdb3/cloud-serverless/reference/sql/functions/hashing.md new file mode 100644 index 000000000..5d4b4a201 --- /dev/null +++ b/content/influxdb3/cloud-serverless/reference/sql/functions/hashing.md @@ -0,0 +1,19 @@ +--- +title: SQL hashing functions +list_title: Hashing functions +description: > + Use hashing functions to hash string values in SQL queries using established + hashing algorithms. +menu: + influxdb3_cloud_serverless: + name: Hashing + parent: sql-functions +weight: 309 + +source: /shared/sql-reference/functions/hashing.md +--- + + diff --git a/content/influxdb3/cloud-serverless/reference/sql/operators/comparison.md b/content/influxdb3/cloud-serverless/reference/sql/operators/comparison.md index 559c06fd1..fa3b47962 100644 --- a/content/influxdb3/cloud-serverless/reference/sql/operators/comparison.md +++ b/content/influxdb3/cloud-serverless/reference/sql/operators/comparison.md @@ -10,19 +10,21 @@ menu: parent: Operators weight: 302 list_code_example: | - | Operator | Meaning | Example | - | :------: | :------------------------------------------------------- | :---------------- | - | `=` | Equal to | `123 = 123` | - | `<>` | Not equal to | `123 <> 456` | - | `!=` | Not equal to | `123 != 456` | - | `>` | Greater than | `3 > 2` | - | `>=` | Greater than or equal to | `3 >= 2` | - | `<` | Less than | `1 < 2` | - | `<=` | Less than or equal to | `1 <= 2` | - | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | - | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | - | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | - | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | + | Operator | Meaning | Example | + | :--------------------: | :------------------------------------------------------- | :------------------------- | + | `=` | Equal to | `123 = 123` | + | `<>` | Not equal to | `123 <> 456` | + | `!=` | Not equal to | `123 != 456` | + | `>` | Greater than | `3 > 2` | + | `>=` | Greater than or equal to | `3 >= 2` | + | `<` | Less than | `1 < 2` | + | `<=` | Less than or equal to | `1 <= 2` | + | `IS DISTINCT FROM` | Is distinct from | `0 IS DISTINCT FROM 1` | + | `IS NOT DISTINCT FROM` | Is not distinct from | `0 IS NOT DISTINCT FROM 1` | + | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | + | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | + | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | + | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | source: /content/shared/sql-reference/operators/comparison.md --- diff --git a/content/influxdb3/clustered/reference/sql/functions/binary-string.md b/content/influxdb3/clustered/reference/sql/functions/binary-string.md new file mode 100644 index 000000000..382881271 --- /dev/null +++ b/content/influxdb3/clustered/reference/sql/functions/binary-string.md @@ -0,0 +1,19 @@ +--- +title: SQL binary string functions +list_title: Binary string functions +description: > + Use binary string functions to encode and decode binary string values in + SQL queries. +menu: + influxdb3_clustered: + name: Binary string + parent: sql-functions +weight: 308 + +source: /content/shared/sql-reference/functions/binary-string.md +--- + + diff --git a/content/influxdb3/clustered/reference/sql/functions/hashing.md b/content/influxdb3/clustered/reference/sql/functions/hashing.md new file mode 100644 index 000000000..38a2a7482 --- /dev/null +++ b/content/influxdb3/clustered/reference/sql/functions/hashing.md @@ -0,0 +1,19 @@ +--- +title: SQL hashing functions +list_title: Hashing functions +description: > + Use hashing functions to hash string values in SQL queries using established + hashing algorithms. +menu: + influxdb3_clustered: + name: Hashing + parent: sql-functions +weight: 309 + +source: /shared/sql-reference/functions/hashing.md +--- + + diff --git a/content/influxdb3/clustered/reference/sql/operators/comparison.md b/content/influxdb3/clustered/reference/sql/operators/comparison.md index 8fd9b248f..f268787a8 100644 --- a/content/influxdb3/clustered/reference/sql/operators/comparison.md +++ b/content/influxdb3/clustered/reference/sql/operators/comparison.md @@ -10,19 +10,21 @@ menu: parent: Operators weight: 302 list_code_example: | - | Operator | Meaning | Example | - | :------: | :------------------------------------------------------- | :---------------- | - | `=` | Equal to | `123 = 123` | - | `<>` | Not equal to | `123 <> 456` | - | `!=` | Not equal to | `123 != 456` | - | `>` | Greater than | `3 > 2` | - | `>=` | Greater than or equal to | `3 >= 2` | - | `<` | Less than | `1 < 2` | - | `<=` | Less than or equal to | `1 <= 2` | - | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | - | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | - | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | - | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | + | Operator | Meaning | Example | + | :--------------------: | :------------------------------------------------------- | :------------------------- | + | `=` | Equal to | `123 = 123` | + | `<>` | Not equal to | `123 <> 456` | + | `!=` | Not equal to | `123 != 456` | + | `>` | Greater than | `3 > 2` | + | `>=` | Greater than or equal to | `3 >= 2` | + | `<` | Less than | `1 < 2` | + | `<=` | Less than or equal to | `1 <= 2` | + | `IS DISTINCT FROM` | Is distinct from | `0 IS DISTINCT FROM 1` | + | `IS NOT DISTINCT FROM` | Is not distinct from | `0 IS NOT DISTINCT FROM 1` | + | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | + | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | + | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | + | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | source: /content/shared/sql-reference/operators/comparison.md --- diff --git a/content/influxdb3/core/reference/sql/functions/binary-string.md b/content/influxdb3/core/reference/sql/functions/binary-string.md new file mode 100644 index 000000000..60241d103 --- /dev/null +++ b/content/influxdb3/core/reference/sql/functions/binary-string.md @@ -0,0 +1,19 @@ +--- +title: SQL binary string functions +list_title: Binary string functions +description: > + Use binary string functions to encode and decode binary string values in + SQL queries. +menu: + influxdb3_core: + name: Binary string + parent: sql-functions +weight: 308 + +source: /content/shared/sql-reference/functions/binary-string.md +--- + + diff --git a/content/influxdb3/core/reference/sql/functions/hashing.md b/content/influxdb3/core/reference/sql/functions/hashing.md new file mode 100644 index 000000000..5e0248f84 --- /dev/null +++ b/content/influxdb3/core/reference/sql/functions/hashing.md @@ -0,0 +1,19 @@ +--- +title: SQL hashing functions +list_title: Hashing functions +description: > + Use hashing functions to hash string values in SQL queries using established + hashing algorithms. +menu: + influxdb3_core: + name: Hashing + parent: sql-functions +weight: 309 + +source: /shared/sql-reference/functions/hashing.md +--- + + diff --git a/content/influxdb3/core/reference/sql/operators/comparison.md b/content/influxdb3/core/reference/sql/operators/comparison.md index ac28aac1f..2896cc0df 100644 --- a/content/influxdb3/core/reference/sql/operators/comparison.md +++ b/content/influxdb3/core/reference/sql/operators/comparison.md @@ -10,19 +10,21 @@ menu: parent: Operators weight: 302 list_code_example: | - | Operator | Meaning | Example | - | :------: | :------------------------------------------------------- | :---------------- | - | `=` | Equal to | `123 = 123` | - | `<>` | Not equal to | `123 <> 456` | - | `!=` | Not equal to | `123 != 456` | - | `>` | Greater than | `3 > 2` | - | `>=` | Greater than or equal to | `3 >= 2` | - | `<` | Less than | `1 < 2` | - | `<=` | Less than or equal to | `1 <= 2` | - | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | - | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | - | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | - | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | + | Operator | Meaning | Example | + | :--------------------: | :------------------------------------------------------- | :------------------------- | + | `=` | Equal to | `123 = 123` | + | `<>` | Not equal to | `123 <> 456` | + | `!=` | Not equal to | `123 != 456` | + | `>` | Greater than | `3 > 2` | + | `>=` | Greater than or equal to | `3 >= 2` | + | `<` | Less than | `1 < 2` | + | `<=` | Less than or equal to | `1 <= 2` | + | `IS DISTINCT FROM` | Is distinct from | `0 IS DISTINCT FROM 1` | + | `IS NOT DISTINCT FROM` | Is not distinct from | `0 IS NOT DISTINCT FROM 1` | + | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | + | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | + | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | + | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | source: /content/shared/sql-reference/operators/comparison.md --- diff --git a/content/influxdb3/enterprise/reference/sql/functions/binary-string.md b/content/influxdb3/enterprise/reference/sql/functions/binary-string.md new file mode 100644 index 000000000..00de57a3c --- /dev/null +++ b/content/influxdb3/enterprise/reference/sql/functions/binary-string.md @@ -0,0 +1,19 @@ +--- +title: SQL binary string functions +list_title: Binary string functions +description: > + Use binary string functions to encode and decode binary string values in + SQL queries. +menu: + influxdb3_enterprise: + name: Binary string + parent: sql-functions +weight: 308 + +source: /content/shared/sql-reference/functions/binary-string.md +--- + + diff --git a/content/influxdb3/enterprise/reference/sql/functions/hashing.md b/content/influxdb3/enterprise/reference/sql/functions/hashing.md new file mode 100644 index 000000000..4770d5336 --- /dev/null +++ b/content/influxdb3/enterprise/reference/sql/functions/hashing.md @@ -0,0 +1,19 @@ +--- +title: SQL hashing functions +list_title: Hashing functions +description: > + Use hashing functions to hash string values in SQL queries using established + hashing algorithms. +menu: + influxdb3_enterprise: + name: Hashing + parent: sql-functions +weight: 309 + +source: /shared/sql-reference/functions/hashing.md +--- + + diff --git a/content/influxdb3/enterprise/reference/sql/operators/comparison.md b/content/influxdb3/enterprise/reference/sql/operators/comparison.md index c7eb269f5..6ae8950f7 100644 --- a/content/influxdb3/enterprise/reference/sql/operators/comparison.md +++ b/content/influxdb3/enterprise/reference/sql/operators/comparison.md @@ -10,19 +10,21 @@ menu: parent: Operators weight: 302 list_code_example: | - | Operator | Meaning | Example | - | :------: | :------------------------------------------------------- | :---------------- | - | `=` | Equal to | `123 = 123` | - | `<>` | Not equal to | `123 <> 456` | - | `!=` | Not equal to | `123 != 456` | - | `>` | Greater than | `3 > 2` | - | `>=` | Greater than or equal to | `3 >= 2` | - | `<` | Less than | `1 < 2` | - | `<=` | Less than or equal to | `1 <= 2` | - | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | - | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | - | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | - | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | + | Operator | Meaning | Example | + | :--------------------: | :------------------------------------------------------- | :------------------------- | + | `=` | Equal to | `123 = 123` | + | `<>` | Not equal to | `123 <> 456` | + | `!=` | Not equal to | `123 != 456` | + | `>` | Greater than | `3 > 2` | + | `>=` | Greater than or equal to | `3 >= 2` | + | `<` | Less than | `1 < 2` | + | `<=` | Less than or equal to | `1 <= 2` | + | `IS DISTINCT FROM` | Is distinct from | `0 IS DISTINCT FROM 1` | + | `IS NOT DISTINCT FROM` | Is not distinct from | `0 IS NOT DISTINCT FROM 1` | + | `~` | Matches a regular expression | `'abc' ~ 'a.*'` | + | `~*` | Matches a regular expression _(case-insensitive)_ | `'Abc' ~* 'A.*'` | + | `!~` | Does not match a regular expression | `'abc' !~ 'd.*'` | + | `!~*` | Does not match a regular expression _(case-insensitive)_ | `'Abc' !~* 'a.*'` | source: /content/shared/sql-reference/operators/comparison.md --- diff --git a/content/shared/sql-reference/functions/aggregate.md b/content/shared/sql-reference/functions/aggregate.md index b6b26fa1e..1cf76088c 100644 --- a/content/shared/sql-reference/functions/aggregate.md +++ b/content/shared/sql-reference/functions/aggregate.md @@ -12,11 +12,14 @@ aggregate value. - [bool_or](#bool_or) - [count](#count) - [first_value](#first_value) + - [grouping](#grouping) - [last_value](#last_value) - [max](#max) - [mean](#mean) - [median](#median) - [min](#min) + - [nth_value](#nth_value) + - [string_agg](#string_agg) - [sum](#sum) - [Statistical aggregate functions](#statistical-aggregate-functions) - [corr](#corr) @@ -37,7 +40,9 @@ aggregate value. - [stddev_samp](#stddev_samp) - [var](#var) - [var_pop](#var_pop) + - [var_population](#var_population) - [var_samp](#var_samp) + - [var_sample](#var_sample) - [Approximate aggregate functions](#approximate-aggregate-functions) - [approx_distinct](#approx_distinct) - [approx_median](#approx_median) @@ -57,11 +62,14 @@ aggregate value. - [bool_or](#bool_or) - [count](#count) - [first_value](#first_value) +- [grouping](#grouping) - [last_value](#last_value) - [max](#max) - [mean](#mean) - [median](#median) - [min](#min) +- [nth_value](#nth_value) +- [string_agg](#string_agg) - [sum](#sum) ### array_agg @@ -69,9 +77,8 @@ aggregate value. Returns an array created from the expression elements. > [!Note] -> `array_agg` returns a `LIST` arrow type which is not supported by InfluxDB. -> To use with InfluxDB, use bracket notation to reference the index of an element -> in the returned array. Arrays are 1-indexed. +> `array_agg` returns a `LIST` arrow type. Use bracket notation to reference the +> index of an element in the returned array. Arrays are 1-indexed. ```sql array_agg(expression) @@ -85,8 +92,7 @@ array_agg(expression) {{< expand-wrapper >}} {{% expand "View `array_agg` query example" %}} -_The following example uses the sample data set provided in the -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -124,18 +130,22 @@ avg(expression) {{< expand-wrapper >}} {{% expand "View `avg` query example" %}} +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql SELECT location, - avg(water_level) AS water_level_avg -FROM h2o_feet + avg(precip) AS avg_precip +FROM weather GROUP BY location ``` -| location | water_level_avg | -| :----------- | -----------------: | -| coyote_creek | 5.359142420303919 | -| santa_monica | 3.5307120942458843 | +| location | avg_precip | +| :------------ | -------------------: | +| Concord | 0.027120658135283374 | +| Hayward | 0.03708029197080292 | +| San Francisco | 0.03750912408759125 | {{% /expand %}} {{< /expand-wrapper >}} @@ -397,6 +407,45 @@ GROUP BY location {{% /expand %}} {{< /expand-wrapper >}} +### grouping + +Returns 1 if the data is aggregated across the specified column, or 0 if it is +not aggregated in the result set. + +```sql +grouping(expression) +``` + +##### Arguments + +- **expression**: Expression to evaluate whether data is aggregated across the + specified column. Can be a constant, column, or function. + +{{< expand-wrapper >}} +{{% expand "View `grouping` query example" %}} + +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT + location, + avg(temp_max) AS avg_max_temp, + grouping(location) AS grouping +FROM weather +GROUP BY GROUPING SETS ((location), ()) +``` + +| location | avg_max_temp | grouping | +| :------------ | ----------------: | -------: | +| Concord | 75.54379562043796 | 0 | +| Hayward | 69.12043795620438 | 0 | +| San Francisco | 67.59945255474453 | 0 | +| | 70.75456204379562 | 1 | + +{{% /expand %}} +{{< /expand-wrapper >}} + ### last_value Returns the last element in an aggregation group according to the specified ordering. @@ -453,18 +502,22 @@ _To return both the maximum value and its associated timestamp, use {{< expand-wrapper >}} {{% expand "View `max` query example" %}} +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql SELECT location, - max(water_level) AS water_level_max -FROM h2o_feet + max(precip) AS max_precip +FROM weather GROUP BY location ``` -| location | water_level_max | -| :----------- | --------------: | -| santa_monica | 7.205 | -| coyote_creek | 9.964 | +| location | max_precip | +| :------------ | ---------: | +| Concord | 4.53 | +| Hayward | 4.34 | +| San Francisco | 4.02 | {{% /expand %}} {{< /expand-wrapper >}} @@ -489,18 +542,22 @@ median(expression) {{< expand-wrapper >}} {{% expand "View `median` query example" %}} +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql SELECT location, - median(water_level) AS water_level_max -FROM h2o_feet + median(temp_avg) AS median_temp_avg +FROM weather GROUP BY location ``` -| location | water_level_median | -| :----------- | -----------------: | -| coyote_creek | 5.4645 | -| santa_monica | 3.471 | +| location | median_temp_avg | +| :------------ | --------------: | +| Concord | 61.0 | +| Hayward | 59.0 | +| San Francisco | 58.0 | {{% /expand %}} {{< /expand-wrapper >}} @@ -524,18 +581,103 @@ _To return both the minimum value and its associated timestamp, use {{< expand-wrapper >}} {{% expand "View `min` query example" %}} +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql SELECT location, - min(water_level) AS water_level_min -FROM h2o_feet + min(temp_min) AS min_temp_min +FROM weather GROUP BY location ``` -| location | water_level_min | -| :----------- | --------------: | -| coyote_creek | -0.61 | -| santa_monica | -0.243 | +| location | min_temp_min | +| :------------ | -----------: | +| Concord | 28.0 | +| Hayward | 32.0 | +| San Francisco | 35.0 | + +{{% /expand %}} +{{< /expand-wrapper >}} + +### nth_value + +Returns the nth value in a group of values. + +```sql +nth_value(expression, n [ORDER BY order_expression_1, ... order_expression_n]) +``` + +##### arguments + +- **expression**: The column or expression to retrieve the nth value from. +- **n**: The position (nth) of the value to retrieve, based on the ordering. +- **order_expression_1, ... order_expression_n**: Expressions to order by. + Can be a column or function, and any combination of arithmetic operators. + +{{< expand-wrapper >}} +{{% expand "View `nth_value` query example" %}} + +_The following example uses the {{< influxdb3/home-sample-link >}}._ + +```sql +SELECT + room, + nth_value(temp, 3 ORDER BY time) AS "3rd_temp" +FROM + home +GROUP BY + room +``` + +| room | 3rd_temp | +| :---------- | -------: | +| Living Room | 21.8 | +| Kitchen | 22.7 | + +{{% /expand %}} +{{< /expand-wrapper >}} + +### string_agg + +Concatenates the values of string expressions and places separator values between them. + +```sql +string_agg(expression, delimiter) +``` + +##### Arguments + +- **expression**: The string expression to concatenate. + Can be a column or any valid string expression. +- **delimiter**: A literal string to use as a separator between the concatenated + values. + +{{< expand-wrapper >}} +{{% expand "View `string_agg` query example" %}} + +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT + location, + string_agg(temp_avg::STRING, ', ') AS string_agg +FROM + weather +WHERE + time > '2020-01-01T00:00:00Z' + AND time < '2020-01-05T00:00:00Z' +GROUP BY + location +``` + +| location | string_agg | +| :------------ | :--------------- | +| San Francisco | 54.0, 52.0, 54.0 | +| Hayward | 51.0, 50.0, 51.0 | +| Concord | 53.0, 49.0, 51.0 | {{% /expand %}} {{< /expand-wrapper >}} @@ -556,18 +698,22 @@ sum(expression) {{< expand-wrapper >}} {{% expand "View `sum` query example" %}} +_The following example uses the +[NOAA Bay Area weather data](/influxdb/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql SELECT location, - sum(water_level) AS water_level_sum -FROM h2o_feet + sum(precip) AS total_precip +FROM weather GROUP BY location ``` -| location | water_level_sum | -| :----------- | -----------------: | -| santa_monica | 27024.070369358 | -| coyote_creek | 40750.918963991004 | +| location | total_precip | +| :------------ | -----------------: | +| Concord | 29.670000000000012 | +| Hayward | 40.64 | +| San Francisco | 41.110000000000014 | {{% /expand %}} {{< /expand-wrapper >}} @@ -593,7 +739,9 @@ GROUP BY location - [stddev_samp](#stddev_samp) - [var](#var) - [var_pop](#var_pop) +- [var_population](#var_population) - [var_samp](#var_samp) +- [var_sample](#var_sample) ### corr @@ -611,8 +759,7 @@ corr(expression1, expression2) {{< expand-wrapper >}} {{% expand "View `corr` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -646,8 +793,7 @@ covar(expression1, expression2) {{< expand-wrapper >}} {{% expand "View `covar` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -681,8 +827,7 @@ covar_pop(expression1, expression2) {{< expand-wrapper >}} {{% expand "View `covar_pop` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -716,8 +861,7 @@ covar_samp(expression1, expression2) {{< expand-wrapper >}} {{% expand "View `covar_samp` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1099,8 +1243,7 @@ stddev(expression) {{< expand-wrapper >}} {{% expand "View `stddev` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1134,8 +1277,7 @@ stddev_pop(expression) {{< expand-wrapper >}} {{% expand "View `stddev_pop` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1169,8 +1311,7 @@ stddev_samp(expression) {{< expand-wrapper >}} {{% expand "View `stddev_samp` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1204,8 +1345,7 @@ var(expression) {{< expand-wrapper >}} {{% expand "View `var` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1236,11 +1376,14 @@ var_pop(expression) - **expression**: Expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators. +##### Aliases + +- var_population + {{< expand-wrapper >}} {{% expand "View `var_pop` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1258,6 +1401,10 @@ GROUP BY room {{% /expand %}} {{< /expand-wrapper >}} +### var_population + +_Alias of [var_pop](#var_pop)._ + ### var_samp Returns the statistical sample variance of a set of numbers. @@ -1271,11 +1418,14 @@ var_samp(expression) - **expression**: Expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators. +##### Aliases + +- var_sample + {{< expand-wrapper >}} {{% expand "View `var_samp` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1293,6 +1443,10 @@ GROUP BY room {{% /expand %}} {{< /expand-wrapper >}} +### var_sample + +_Alias of [var_samp](#var_samp)._ + ## Approximate aggregate functions - [approx_distinct](#approx_distinct) @@ -1317,8 +1471,7 @@ approx_distinct(expression) {{< expand-wrapper >}} {{% expand "View `approx_distinct` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1353,8 +1506,7 @@ approx_median(expression) {{< expand-wrapper >}} {{% expand "View `approx_median` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1394,8 +1546,7 @@ approx_percentile_cont(expression, percentile, centroids) {{< expand-wrapper >}} {{% expand "View `approx_percentile_cont` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -1433,8 +1584,7 @@ approx_percentile_cont_with_weight(expression, weight, percentile) {{< expand-wrapper >}} {{% expand "View `approx_percentile_cont_with_weight` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT diff --git a/content/shared/sql-reference/functions/binary-string.md b/content/shared/sql-reference/functions/binary-string.md new file mode 100644 index 000000000..42521e3f1 --- /dev/null +++ b/content/shared/sql-reference/functions/binary-string.md @@ -0,0 +1,68 @@ + +Use binary string functions to encode and decode binary string values in +SQL queries. + +- [decode](#decode) +- [encode](#encode) + +## decode + +Decode binary data from textual representation in string. + +```sql +decode(expression, format) +``` + +##### Arguments + +- **expression**: Expression containing encoded string data. + Can be a constant, column, or function, and any combination of string operators. +- **format**: Encoding format of the encoded string. Supported formats are: + - base64 + - hex + +##### Related functions + +[encode](#encode) + +## encode + +Encode binary data into a textual representation. + +```sql +encode(expression, format) +``` + +##### Arguments + +- **expression**: Expression containing string or binary data. + Can be a constant, column, or function, and any combination of string operators. +- **format**: Encoding format to use. Supported formats are: + - base64 + - hex + +##### Related functions + +[decode](#decode) + +{{< expand-wrapper >}} +{{% expand "View `encode` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + encode(location::string, 'hex') AS location_encoded +FROM weather +``` + +| location | location_encoded | +| :------------ | :------------------------- | +| Concord | 436f6e636f7264 | +| Hayward | 48617977617264 | +| San Francisco | 53616e204672616e636973636f | + +{{% /expand %}} +{{< /expand-wrapper >}} diff --git a/content/shared/sql-reference/functions/conditional.md b/content/shared/sql-reference/functions/conditional.md index e8abb272b..b3258ef81 100644 --- a/content/shared/sql-reference/functions/conditional.md +++ b/content/shared/sql-reference/functions/conditional.md @@ -5,6 +5,12 @@ functions for conditionally handling _null_ values: - [ifnull](#ifnull) - [nullif](#nullif) - [nvl](#nvl) +- [nvl2](#nvl2) + + ## coalesce @@ -50,10 +56,84 @@ FROM {{% /expand %}} {{< /expand-wrapper >}} + + ## ifnull _Alias of [nvl](#nvl)._ + + ## nullif Returns _null_ if _expression1_ equals _expression2_; otherwise it returns _expression1_. @@ -130,3 +210,45 @@ FROM {{% /expand %}} {{< /expand-wrapper >}} + +## nvl2 + +Returns _expression2_ if _expression1_ is **not** _null_; otherwise it returns _expression3_. + +```sql +nvl2(expression1, expression2, expression3) +``` + +##### Arguments + +- **expression1**: First expression to test for _null_. + Can be a constant, column, or function, and any combination of operators. +- **expression2**: Second expression to return if _expression1_ is not _null_. + Can be a constant, column, or function, and any combination of operators. +- **expression3**: Expression to return if _expression1_ is _null_. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `nvl2` query example" %}} + +```sql +SELECT + val1, + val2, + val3, + nvl2(val1, val2, val3) AS nvl2 +FROM + (values ('foo', 'bar', 'baz'), + (NULL, 'bar', 'baz'), + (NULL, NULL, 'baz'), + ) data(val1, val2, val3) +``` + +| val1 | val2 | val3 | nvl2 | +| :--: | :--: | :--: | :--: | +| foo | bar | baz | bar | +| | bar | baz | baz | +| | | baz | baz | + +{{% /expand %}} +{{< /expand-wrapper >}} diff --git a/content/shared/sql-reference/functions/hashing.md b/content/shared/sql-reference/functions/hashing.md new file mode 100644 index 000000000..54a3b5d64 --- /dev/null +++ b/content/shared/sql-reference/functions/hashing.md @@ -0,0 +1,231 @@ + +Use hashing functions to hash string values in SQL queries using established +hashing algorithms. + +- [digest](#digest) +- [md5](#md5) +- [sha224](#sha224) +- [sha256](#sha256) +- [sha384](#sha384) +- [sha512](#sha512) + +## digest + +Computes the binary hash of an expression using the specified algorithm. + +```sql +digest(expression, algorithm) +``` + +##### Arguments + +- **expression**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. +- **algorithm**: String expression specifying algorithm to use. + Must be one of the following: + + - md5 + - sha224 + - sha256 + - sha384 + - sha512 + - blake2s + - blake2b + - blake3 + +{{< expand-wrapper >}} +{{% expand "View `digest` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + digest(location, 'sha256') AS location_digest +FROM weather +``` + +| location | location_digest | +| :------------ | :--------------------------------------------------------------- | +| Concord | 21e60acfb20fca2e38c5e51191d44235949de045912dca77e978333c1ec965a2 | +| Hayward | 5d5b651a71084f3117cca3381ff7102efbc318c2026e1d09d5d4707354883102 | +| San Francisco | 5aa34886f7f3741de8460690b636f4c8b7c2044df88e2e8adbb4f7e6f8534931 | + +{{% /expand %}} +{{< /expand-wrapper >}} + +## md5 + +Computes an MD5 128-bit checksum for a string expression. + +```sql +md5(expression) +``` + +##### Arguments + +- **expression**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `md5` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + md5(location) AS location_md5 +FROM weather +``` + +| location | location_md5 | +| :------------ | :------------------------------- | +| Concord | 7c6a8e5769c20331e6a1b93a44021dbc | +| Hayward | 5823ccc25b256955c4e97cb4a23865ee | +| San Francisco | f4334fdfa1c728eae375fe781e2e2d9d | + +{{% /expand %}} +{{< /expand-wrapper >}} + +## sha224 + +Computes the SHA-224 hash of a binary string. + +```sql +sha224(expression) +``` + +##### Arguments + +- **expression**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `sha224` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + sha224(location) AS location_sha224 +FROM weather +``` + +| location | location_sha224 | +| :------------ | :------------------------------------------------------- | +| Concord | 3f6c0456de97d3d752672161db8e6f0df115979460a2276d64386114 | +| Hayward | 767cfab6a1562e54f6906c8b5c9ee64583caa3f4b6c37a4298a7639f | +| San Francisco | f723898f95bd53cdaf9c057b6f2cf0537b29e0bff077dabb39059b76 | + +{{% /expand %}} +{{< /expand-wrapper >}} + +## sha256 + +Computes the SHA-256 hash of a binary string. + +```sql +sha256(expression) +``` + +##### Arguments + +- **expression**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `sha256` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + sha256(location) AS location_sha256 +FROM weather +``` + +| location | location_sha256 | +| :------------ | :--------------------------------------------------------------- | +| Concord | 21e60acfb20fca2e38c5e51191d44235949de045912dca77e978333c1ec965a2 | +| Hayward | 5d5b651a71084f3117cca3381ff7102efbc318c2026e1d09d5d4707354883102 | +| San Francisco | 5aa34886f7f3741de8460690b636f4c8b7c2044df88e2e8adbb4f7e6f8534931 | + +{{% /expand %}} +{{< /expand-wrapper >}} + +## sha384 + +Computes the SHA-384 hash of a binary string. + +```sql +sha384(expression) +``` + +##### Arguments + +- **expression**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `sha384` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + sha384(location) AS location_sha384 +FROM weather +``` + +| location | location_sha384 | +| :------------ | :----------------------------------------------------------------------------------------------- | +| Concord | 19bf5ba95a6c4a28d2a997fa4e03e542d24b111593395b587a3b357af50cc687364f27b4e96935c234e2ae69236c7883 | +| Hayward | 8b034ee0f7c8d191e145002722bf296a7f310f455458b9ffdbafcb2da2e2300d0f1e7868c6b1d512c81ae0c055979abd | +| San Francisco | 15c0c4a0e80f198e922235ee30a5c2b1e288c88f61bfc55ef9723903a0e948a7de04b65aa35b4ba46251b90460bab625 | + +{{% /expand %}} +{{< /expand-wrapper >}} + +## sha512 + +Computes the SHA-512 hash of a binary string. + +```sql +sha512(expression) +``` + +##### Arguments + +- **expression**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `sha512` query example" %}} + +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + +```sql +SELECT DISTINCT + location, + sha512(location) AS location_sha512 +FROM weather +``` + +| location | location_sha512 | +| :------------ | :------------------------------------------------------------------------------------------------------------------------------- | +| Concord | 227e28fd661eebb39b10f49728d17b03e3a1f0cc2d2a413a9f124292d77249a2c0d7cf99941fd3d2eabea1b2894698bbd12c2cf3a7137ec67fca221ee57e0ca7 | +| Hayward | 2db79fba2fc2888f9826d95ce6bb2605d95b841da61f049e8a92467de0d6ec3161f3919275208a3c385f6412d7848bfc957e81cde550f4f28cd834a332381142 | +| San Francisco | 4c84f24d166978fb59d77779bf9a54ac112cba8e5f826c50440b2d3063fa0cbb0e2ccd30c93261a0f96805f71d15c3e726c9e00426161880e6a5dad267b2d883 | + +{{% /expand %}} +{{< /expand-wrapper >}} diff --git a/content/shared/sql-reference/functions/math.md b/content/shared/sql-reference/functions/math.md index 9c1e93eff..13896ec76 100644 --- a/content/shared/sql-reference/functions/math.md +++ b/content/shared/sql-reference/functions/math.md @@ -13,6 +13,7 @@ performing mathematic operations: - [ceil](#ceil) - [cos](#cos) - [cosh](#cosh) +- [cot](#cot) - [degrees](#degrees) - [exp](#exp) - [factorial](#factorial) @@ -56,8 +57,7 @@ abs(numeric_expression) {{< expand-wrapper >}} {{% expand "View `abs` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT abs(temp) AS abs FROM home LIMIT 3 @@ -88,8 +88,7 @@ acos(numeric_expression) {{< expand-wrapper >}} {{% expand "View `acos` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT acos(temp * .01) AS acos FROM home LIMIT 3 @@ -120,8 +119,7 @@ acosh(numeric_expression) {{< expand-wrapper >}} {{% expand "View `acosh` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT acosh(temp) AS acosh FROM home LIMIT 3 @@ -152,8 +150,7 @@ asin(numeric_expression) {{< expand-wrapper >}} {{% expand "View `asin` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT asin(temp * .01) AS asin FROM home LIMIT 3 @@ -184,8 +181,7 @@ asinh(numeric_expression) {{< expand-wrapper >}} {{% expand "View `asinh` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT asinh(temp) AS asinh FROM home LIMIT 3 @@ -216,8 +212,7 @@ atan(numeric_expression) {{< expand-wrapper >}} {{% expand "View `atan` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT atan(temp * .01) AS atan FROM home LIMIT 3 @@ -248,8 +243,7 @@ atanh(numeric_expression) {{< expand-wrapper >}} {{% expand "View `atanh` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT atanh(temp * .01) AS atanh FROM home LIMIT 3 @@ -282,8 +276,7 @@ atan2(expression_y, expression_x) {{< expand-wrapper >}} {{% expand "View `atan2` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT atan2(temp, hum) AS atan2 FROM home LIMIT 3 @@ -314,8 +307,7 @@ cbrt(numeric_expression) {{< expand-wrapper >}} {{% expand "View `cbrt` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT cbrt(temp) AS cbrt FROM home LIMIT 3 @@ -346,8 +338,7 @@ ceil(numeric_expression) {{< expand-wrapper >}} {{% expand "View `ceil` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT ceil(temp) AS ceil FROM home LIMIT 3 @@ -378,8 +369,7 @@ cos(numeric_expression) {{< expand-wrapper >}} {{% expand "View `cos` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT cos(temp) AS cos FROM home LIMIT 3 @@ -410,8 +400,7 @@ cosh(numeric_expression) {{< expand-wrapper >}} {{% expand "View `cosh` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT cosh(temp) AS cosh FROM home LIMIT 3 @@ -426,6 +415,38 @@ SELECT cosh(temp) AS cosh FROM home LIMIT 3 {{% /expand %}} {{< /expand-wrapper >}} +## cot + +Returns the cotangent of a number. + +```sql +cot(numeric_expression) +``` + +##### Arguments + +- **numeric_expression**: Numeric expression to operate on. + Can be a constant, column, or function, and any combination of operators. + +{{< expand-wrapper >}} +{{% expand "View `cot` query example" %}} + +_The following example uses the +[Random numbers sample dataset](/influxdb/version/reference/sample-data/#random-numbers-sample-data)._ + +```sql +SELECT cot(a) AS cot FROM numbers LIMIT 3 +``` + +| cot | +| -----------------: | +| 2.9293528483724423 | +| 3.705570308335524 | +| -3.314652247498361 | + +{{% /expand %}} +{{< /expand-wrapper >}} + ## degrees Converts radians to degrees. @@ -474,8 +495,7 @@ exp(numeric_expression) {{< expand-wrapper >}} {{% expand "View `exp` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT exp(temp) AS exp FROM home LIMIT 3 @@ -539,8 +559,7 @@ floor(numeric_expression) {{< expand-wrapper >}} {{% expand "View `floor` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT floor(temp) AS floor FROM home LIMIT 3 @@ -722,8 +741,7 @@ ln(numeric_expression) {{< expand-wrapper >}} {{% expand "View `ln` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT ln(temp) AS ln FROM home LIMIT 3 @@ -758,7 +776,7 @@ log([base, ]numeric_expression) {{% expand "View `log` query example" %}} _The following example uses the sample data set provided in the -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +{{ influxdb3/home-sample-link }}._ ```sql SELECT @@ -795,8 +813,7 @@ log10(numeric_expression) {{< expand-wrapper >}} {{% expand "View `log10` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT log10(temp) AS log10 FROM home LIMIT 3 @@ -827,8 +844,7 @@ log2(numeric_expression) {{< expand-wrapper >}} {{% expand "View `log2` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT log2(temp) AS log2 FROM home LIMIT 3 @@ -928,8 +944,7 @@ power(base, exponent) {{< expand-wrapper >}} {{% expand "View `power` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT power(temp, hum * .1) AS power FROM home LIMIT 3 @@ -992,8 +1007,7 @@ random() {{< expand-wrapper >}} {{% expand "View `random` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT temp * random() AS random FROM home LIMIT 3 @@ -1027,8 +1041,7 @@ round(numeric_expression) {{< expand-wrapper >}} {{% expand "View `round` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT round(temp) AS round FROM home LIMIT 3 @@ -1061,8 +1074,7 @@ signum(numeric_expression) {{< expand-wrapper >}} {{% expand "View `signum` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT signum(temp - 23) AS signum FROM home LIMIT 3 @@ -1093,8 +1105,7 @@ sin(numeric_expression) {{< expand-wrapper >}} {{% expand "View `sin` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT sin(temp) AS sin FROM home LIMIT 3 @@ -1125,8 +1136,7 @@ sinh(numeric_expression) {{< expand-wrapper >}} {{% expand "View `sinh ` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT sinh(temp) AS sinh FROM home LIMIT 3 @@ -1157,8 +1167,7 @@ sqrt(numeric_expression) {{< expand-wrapper >}} {{% expand "View `sqrt` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT sqrt(temp) AS sqrt FROM home LIMIT 3 @@ -1189,8 +1198,7 @@ tan(numeric_expression) {{< expand-wrapper >}} {{% expand "View `tan` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT tan(temp) AS tan FROM home LIMIT 3 @@ -1253,8 +1261,7 @@ trunc(numeric_expression) {{< expand-wrapper >}} {{% expand "View `trunc` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{ influxdb3/home-sample-link }}._ ```sql SELECT trunc(temp) AS trunc FROM home LIMIT 3 diff --git a/content/shared/sql-reference/functions/misc.md b/content/shared/sql-reference/functions/misc.md index 309a27d7d..e1ef37ba0 100644 --- a/content/shared/sql-reference/functions/misc.md +++ b/content/shared/sql-reference/functions/misc.md @@ -5,6 +5,7 @@ for performing a variety of operations: - [arrow_typeof](#arrow_typeof) - [interpolate](#interpolate) - [locf](#locf) +- [version](#version) ## arrow_cast @@ -232,3 +233,11 @@ struct('A', 'B', 3, 4) {{% /expand %}} {{< /expand-wrapper >}} --> + +## version + +Returns the version of DataFusion. + +```sql +version() +``` diff --git a/content/shared/sql-reference/functions/regular-expression.md b/content/shared/sql-reference/functions/regular-expression.md index 861b23233..c32e6bea2 100644 --- a/content/shared/sql-reference/functions/regular-expression.md +++ b/content/shared/sql-reference/functions/regular-expression.md @@ -4,10 +4,55 @@ regular expression [syntax](https://docs.rs/regex/latest/regex/#syntax) (excluding some features such as look-around and back-references) and supports the following regular expression functions: +- [regexp_count](#regexp_count) - [regexp_like](#regexp_like) - [regexp_match](#regexp_match) - [regexp_replace](#regexp_replace) +## regexp_count + +Returns the number of matches that a regular expression has in a string. + +```sql +regexp_count(str, regexp[, start, flags]) +``` + +##### Arguments + +- **str**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. +- **regexp**: Regular expression to operate on. + Can be a constant, column, or function, and any combination of operators. +- **start**: Optional start position (the first position is 1) to search for the regular expression. + Can be a constant, column, or function. +- **flags**: Optional regular expression flags that control the behavior of the + regular expression. The following flags are supported: + - **i**: (insensitive) Ignore case when matching. + - **m**: (multi-line) `^` and `$` match the beginning and end of a line, respectively. + - **s**: (single-line) `.` matches newline (`\n`). + - **R**: (CRLF) When multi-line mode is enabled, `\r\n` is used to delimit lines. + - **U**: (ungreedy) Swap the meaning of `x*` and `x*?`. + +{{< expand-wrapper >}} +{{% expand "View `regexp_count` query example" %}} + +_The following example uses the {{< influxdb3/home-sample-link >}}._ + +```sql +SELECT DISTINCT + room, + regexp_count(room::STRING, '[Ro]', 1, 'i') AS regexp_count +FROM home +``` + +| room | regexp_count | +| :---------- | -----------: | +| Kitchen | 0 | +| Living Room | 3 | + +{{% /expand %}} +{{< /expand-wrapper >}} + ## regexp_like True if a regular expression has at least one match in a string; @@ -34,8 +79,7 @@ regexp_like(str, regexp[, flags]) {{< expand-wrapper >}} {{% expand "View `regexp_like` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -73,11 +117,10 @@ regexp_match(str, regexp, flags) {{< expand-wrapper >}} {{% expand "View `regexp_match` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ > [!Note] -> `regexp_match` returns a _list_ Arrow type, which is not supported by InfluxDB. +> `regexp_match` returns a _list_ Arrow type. > Use _bracket notation_ to reference a value in the list. > Lists use 1-based indexing. @@ -120,8 +163,7 @@ regexp_replace(str, regexp, replacement, flags) {{< expand-wrapper >}} {{% expand "View `regexp_replace` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT diff --git a/content/shared/sql-reference/functions/selector.md b/content/shared/sql-reference/functions/selector.md index 228ae57aa..dbcaf81e0 100644 --- a/content/shared/sql-reference/functions/selector.md +++ b/content/shared/sql-reference/functions/selector.md @@ -72,16 +72,25 @@ selector_min(expression, timestamp) {{< expand-wrapper >}} {{% expand "View `selector_min` query example" %}} +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql -SELECT - selector_min(water_level, time)['time'] AS time, - selector_min(water_level, time)['value'] AS water_level -FROM h2o_feet +SELECT + location, + selector_min(temp_min, time)['time'] AS time, + selector_min(temp_min, time)['value'] AS min_temp +FROM + weather +GROUP BY + location ``` -| time | water_level | -| :------------------- | ----------: | -| 2019-08-28T14:30:00Z | -0.61 | +| location | time | min_temp | ++---------------+---------------------+----------+ +| Concord | 2022-01-02T00:00:00 | 28.0 | +| Hayward | 2021-01-26T00:00:00 | 32.0 | +| San Francisco | 2022-01-02T00:00:00 | 35.0 | {{% /expand %}} {{< /expand-wrapper >}} @@ -105,16 +114,25 @@ selector_max(expression, timestamp) {{< expand-wrapper >}} {{% expand "View `selector_max` query example" %}} +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql -SELECT - selector_max(water_level, time)['time'] AS time, - selector_max(water_level, time)['value'] AS water_level -FROM h2o_feet +SELECT + location, + selector_max(temp_max, time)['time'] AS time, + selector_max(temp_max, time)['value'] AS max_temp +FROM + weather +GROUP BY + location ``` -| time | water_level | -| :------------------- | ----------: | -| 2019-08-28T07:24:00Z | 9.964 | +| location | time | max_temp | +| :------------ | :------------------ | -------: | +| Concord | 2020-09-07T00:00:00 | 112.0 | +| Hayward | 2022-09-06T00:00:00 | 107.0 | +| San Francisco | 2020-09-06T00:00:00 | 102.0 | {{% /expand %}} {{< /expand-wrapper >}} @@ -138,16 +156,25 @@ selector_first(expression, timestamp) {{< expand-wrapper >}} {{% expand "View `selector_first` query example" %}} +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql -SELECT - selector_first(water_level, time)['time'] AS time, - selector_first(water_level, time)['value'] AS water_level -FROM h2o_feet +SELECT + location, + selector_first(precip, time)['time'] AS time, + selector_first(precip, time)['value'] AS first_precip +FROM + (SELECT * FROM weather WHERE precip > 0) +GROUP BY + location ``` -| time | water_level | -| :------------------- | ----------: | -| 2019-08-28T07:24:00Z | 9.964 | +| location | time | first_precip | +| :------------ | :------------------ | -----------: | +| Concord | 2020-01-08T00:00:00 | 0.01 | +| Hayward | 2020-01-09T00:00:00 | 0.17 | +| San Francisco | 2020-01-07T00:00:00 | 0.03 | {{% /expand %}} {{< /expand-wrapper >}} @@ -171,16 +198,25 @@ selector_last(expression, timestamp) {{< expand-wrapper >}} {{% expand "View `selector_last` query example" %}} +_The following example uses the +[NOAA Bay Area weather sample data](/influxdb3/version/reference/sample-data/#noaa-bay-area-weather-data)._ + ```sql -SELECT - selector_last(water_level, time)['time'] AS time, - selector_last(water_level, time)['value'] AS water_level -FROM h2o_feet +SELECT + location, + selector_last(precip, time)['time'] AS time, + selector_last(precip, time)['value'] AS last_precip +FROM + (SELECT * FROM weather WHERE precip > 0) +GROUP BY + location ``` -| time | water_level | -| :------------------- | ----------: | -| 2019-09-17T21:42:00Z | 4.938 | +| location | time | last_precip | +| :------------ | :------------------ | ----------: | +| Concord | 2022-12-31T00:00:00 | 3.04 | +| Hayward | 2022-12-31T00:00:00 | 4.34 | +| San Francisco | 2022-12-31T00:00:00 | 3.67 | {{% /expand %}} {{< /expand-wrapper >}} diff --git a/content/shared/sql-reference/functions/string.md b/content/shared/sql-reference/functions/string.md index 3011eb836..fc2d39076 100644 --- a/content/shared/sql-reference/functions/string.md +++ b/content/shared/sql-reference/functions/string.md @@ -6,9 +6,10 @@ operating on string values: - [btrim](#btrim) - [char_length](#char_length) - [character_length](#character_length) +- [chr](#chr) - [concat](#concat) - [concat_ws](#concat_ws) -- [chr](#chr) +- [contains](#contains) - [ends_with](#ends_with) - [find_in_set](#find_in_set) - [initcap](#initcap) @@ -19,7 +20,6 @@ operating on string values: - [lower](#lower) - [lpad](#lpad) - [ltrim](#ltrim) -- [md5](#md5) - [octet_length](#octet_length) - [overlay](#overlay) - [position](#position) @@ -34,6 +34,8 @@ operating on string values: - [strpos](#strpos) - [substr](#substr) - [substr_index](#substr_index) +- [substring](#substring) +- [substring_index](#substring_index) - [to_hex](#to_hex) - [translate](#translate) - [trim](#trim) @@ -64,8 +66,7 @@ ascii(str) {{< expand-wrapper >}} {{% expand "View `ascii` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -106,8 +107,7 @@ bit_length(str) {{< expand-wrapper >}} {{% expand "View `bit_length` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -151,8 +151,7 @@ btrim(str[, trim_str]) {{< expand-wrapper >}} {{% expand "View `btrim` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -177,6 +176,47 @@ _Alias of [length](#length)._ _Alias of [length](#length)._ +## chr + +Returns the character with the specified ASCII or Unicode code value. + +``` +chr(expression) +``` + +#### Arguments + +- **expression**: Expression containing the ASCII or Unicode code value to operate on. + Can be a constant, column, or function, and any combination of arithmetic or + string operators. + +##### Related functions + +[ascii](#ascii) + +{{< expand-wrapper >}} +{{% expand "View `chr` query example" %}} + +```sql +SELECT + ascii, + chr(ascii) AS chr +FROM + (values (112), + (75), + (214) + ) data(ascii) +``` + +| ascii | chr | +| :---- | :-: | +| 112 | p | +| 75 | K | +| 214 | Ö | + +{{% /expand %}} +{{< /expand-wrapper >}} + ## concat Concatenates multiple strings together. @@ -198,8 +238,7 @@ concat(str[, ..., str_n]) {{< expand-wrapper >}} {{% expand "View `concat` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -244,8 +283,7 @@ concat_ws(separator, str[, ..., str_n]) {{< expand-wrapper >}} {{% expand "View `concat_ws` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT @@ -267,46 +305,19 @@ LIMIT 3 {{% /expand %}} {{< /expand-wrapper >}} -## chr +## contains -Returns the character with the specified ASCII or Unicode code value. - -``` -chr(expression) -``` - -#### Arguments - -- **expression**: Expression containing the ASCII or Unicode code value to operate on. - Can be a constant, column, or function, and any combination of arithmetic or - string operators. - -##### Related functions - -[ascii](#ascii) - -{{< expand-wrapper >}} -{{% expand "View `chr` query example" %}} +Returns true if a string contains a search string (case-sensitive). ```sql -SELECT - ascii, - chr(ascii) AS chr -FROM - (values (112), - (75), - (214) - ) data(ascii) +contains(str, search_str) ``` -| ascii | chr | -| :---- | :-: | -| 112 | p | -| 75 | K | -| 214 | Ö | +##### Arguments -{{% /expand %}} -{{< /expand-wrapper >}} +- **str**: String expression to operate on. + Can be a constant, column, or function, and any combination of operators. +- **search_str**: The string to search for in _str_. ## ends_with @@ -486,8 +497,7 @@ left(str, n) {{< expand-wrapper >}} {{% expand "View `left` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -534,8 +544,7 @@ length(str) {{< expand-wrapper >}} {{% expand "View `length` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -612,8 +621,7 @@ lower(str) {{< expand-wrapper >}} {{% expand "View `lower` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -654,8 +662,7 @@ lpad(str, n[, padding_str]) {{< expand-wrapper >}} {{% expand "View `lpad` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -714,40 +721,6 @@ FROM {{% /expand %}} {{< /expand-wrapper >}} -## md5 - -Computes an MD5 128-bit checksum for a string expression. - -```sql -md5(str) -``` - -##### Arguments - -- **expression**: String expression to operate on. - Can be a constant, column, or function, and any combination of string operators. - -{{< expand-wrapper >}} -{{% expand "View `md5` query example" %}} - -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ - -```sql -SELECT DISTINCT - room, - md5(room) AS md5 -FROM home -``` - -| room | md5 | -| :---------- | :------------------------------- | -| Kitchen | 33fa00a66f2edf0d1c5697a9f8693ba8 | -| Living Room | f45b0e6aec165544faccaf2cad820542 | - -{{% /expand %}} -{{< /expand-wrapper >}} - ## octet_length Returns the length of a string in bytes. @@ -773,8 +746,7 @@ octet_length(str) {{< expand-wrapper >}} {{% expand "View `octet_length` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -929,8 +901,7 @@ replace(str, substr, replacement) {{< expand-wrapper >}} {{% expand "View `replace` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -963,8 +934,7 @@ reverse(str) {{< expand-wrapper >}} {{% expand "View `reverse` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1002,8 +972,7 @@ right(str, n) {{< expand-wrapper >}} {{% expand "View `right` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1044,8 +1013,7 @@ rpad(str, n[, padding_str]) {{< expand-wrapper >}} {{% expand "View `rpad` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1160,8 +1128,7 @@ starts_with(str, substr) {{< expand-wrapper >}} {{% expand "View `starts_with` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1202,8 +1169,7 @@ strpos(str, substr) {{< expand-wrapper >}} {{% expand "View `strpos` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1241,8 +1207,7 @@ substr(str, start_pos[, length]) {{< expand-wrapper >}} {{% expand "View `substr` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1306,6 +1271,14 @@ FROM {{% /expand %}} {{< /expand-wrapper >}} +## substring + +_Alias of [substr](#substr)._ + +## substring_index + +_Alias of [substr_index](#substr_index)._ + ## translate Translates characters in a string to specified translation characters. @@ -1323,8 +1296,7 @@ translate(str, chars, translation) {{< expand-wrapper >}} {{% expand "View `translate` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1440,8 +1412,7 @@ upper(str) {{< expand-wrapper >}} {{% expand "View `upper` query example" %}} -_The following example uses the sample data set provided in -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +_The following example uses the {{< influxdb3/home-sample-link >}}._ ```sql SELECT DISTINCT @@ -1470,7 +1441,7 @@ uuid() {{% expand "View `uuid` query example" %}} _The following example uses the sample data set provided in the -[Get started with InfluxDB tutorial](/influxdb/version/get-started/write/#construct-line-protocol)._ +{{< influxdb3/home-sample-link >}}._ ```sql SELECT diff --git a/content/shared/sql-reference/functions/time-and-date.md b/content/shared/sql-reference/functions/time-and-date.md index d7fedd40d..a4e82d375 100644 --- a/content/shared/sql-reference/functions/time-and-date.md +++ b/content/shared/sql-reference/functions/time-and-date.md @@ -3,12 +3,14 @@ that are useful when working with time series data. - [current_date](#current_date) - [current_time](#current_time) +- [current_timestamp](#current_timestamp) - [date_bin](#date_bin) - [date_bin_gapfill](#date_bin_gapfill) - [date_bin_wallclock](#date_bin_wallclock) - [date_bin_wallclock_gapfill](#date_bin_wallclock_gapfill) - [date_trunc](#date_trunc) - [datetrunc](#datetrunc) +- [date_format](#date_format) - [date_part](#date_part) - [datepart](#datepart) - [extract](#extract) @@ -76,10 +78,6 @@ LIMIT 3 Returns the current UTC time. -> [!Note] -> `current_date` returns a `TIME64` Arrow type, which isn't supported by InfluxDB. -> To use with InfluxDB, [cast the return value to a string](/influxdb/version/query-data/sql/cast-types/#cast-to-a-string-type). - The `current_time()` return value is determined at query time and returns the same time, no matter when in the query plan the function executes. @@ -97,7 +95,7 @@ _The following example uses the sample data set provided in the SELECT time, temp, - current_time()::STRING AS current_time + current_time() AS current_time FROM home LIMIT 3 ``` @@ -111,6 +109,10 @@ LIMIT 3 {{% /expand %}} {{< /expand-wrapper >}} +## current_timestamp + +_Alias of [now](#now)._ + ## date_bin Calculates time intervals and returns the start of the interval nearest to the specified timestamp. @@ -397,7 +399,7 @@ date_bin_wallclock(interval, expression[, origin_timestamp]) > > #### Avoid bins in time zone discontinuities > - > [Time zone shifts](#time-zone-shifts) result in *discontinuities*–breaks + > [Time zone shifts](#time-zone-shifts) result in _discontinuities_–breaks > in the continuity of time intervals (losing an hour or gaining an hour)–that > can result in unexpected timestamps when using `date_bin_wallclock`. > Avoid using an `interval` and `origin_timestamp` combination that results in a @@ -536,7 +538,7 @@ date_bin_wallclock_gapfill(interval, expression[, origin_timestamp]) > > #### Avoid bins in time zone discontinuities > - > [Time zone shifts](#time-zone-shifts) result in *discontinuities*–breaks + > [Time zone shifts](#time-zone-shifts) result in _discontinuities_–breaks > in the continuity of time intervals (losing an hour or gaining an hour)–that > can result in unexpected timestamps when using `date_bin_wallclock_gapfill`. > Avoid using an `interval` and `origin_timestamp` combination that results in a @@ -761,6 +763,10 @@ ORDER BY week _Alias of [date_trunc](#date_trunc)._ +## date_format + +_Alias of [to_char](#to_char)._ + ## date_part Returns the specified part of the date as an integer. @@ -954,6 +960,10 @@ no matter when in the query plan the function executes. now() ``` +##### Aliases + +- [current_timestamp](#current_timestamp) + {{< expand-wrapper >}} {{% expand "View `now` query example" %}} @@ -993,6 +1003,10 @@ to_char(expression, format) - **format**: [Rust Chrono format string](https://docs.rs/chrono/latest/chrono/format/strftime/index.html) to use to convert the expression. +##### Aliases + +- [date_format](#date_format) + {{< expand-wrapper >}} {{% expand "View `to_char` query example" %}} diff --git a/content/shared/sql-reference/operators/comparison.md b/content/shared/sql-reference/operators/comparison.md index 1dc8fe84d..00581c96c 100644 --- a/content/shared/sql-reference/operators/comparison.md +++ b/content/shared/sql-reference/operators/comparison.md @@ -2,19 +2,23 @@ Comparison operators evaluate the relationship between the left and right operands and returns `true` or `false`. -| Operator | Meaning | | -| :------: | :------------------------------------------------------- | :------------------------------------------------------ | -| `=` | Equal to | [{{< icon "link" >}}](#equal-to) | -| `<>` | Not equal to | [{{< icon "link" >}}](#not-equal-to) | -| `!=` | Not equal to | [{{< icon "link" >}}](#not-equal-to) | -| `>` | Greater than | [{{< icon "link" >}}](#greater-than) | -| `>=` | Greater than or equal to | [{{< icon "link" >}}](#greater-than-or-equal) | -| `<` | Less than | [{{< icon "link" >}}](#less-than) | -| `<=` | Less than or equal to | [{{< icon "link" >}}](#less-than-or-equal) | -| `~` | Matches a regular expression | [{{< icon "link" >}}](#regexp-match) | -| `~*` | Matches a regular expression _(case-insensitive)_ | [{{< icon "link" >}}](#regexp-match-case-insensitive) | -| `!~` | Does not match a regular expression | [{{< icon "link" >}}](#regexp-nomatch) | -| `!~*` | Does not match a regular expression _(case-insensitive)_ | [{{< icon "link" >}}](#regexp-nomatch-case-insensitive) | +| Operator | Meaning | | +| :--------------------: | :------------------------------------------------------- | :------------------------------------------------------ | +| `=` | Equal to | [{{< icon "link" >}}](#equal-to) | +| `<>` | Not equal to | [{{< icon "link" >}}](#not-equal-to) | +| `!=` | Not equal to | [{{< icon "link" >}}](#not-equal-to) | +| `>` | Greater than | [{{< icon "link" >}}](#greater-than) | +| `>=` | Greater than or equal to | [{{< icon "link" >}}](#greater-than-or-equal) | +| `<` | Less than | [{{< icon "link" >}}](#less-than) | +| `<=` | Less than or equal to | [{{< icon "link" >}}](#less-than-or-equal) | +| `IS DISTINCT FROM` | Is distinct from | [{{< icon "link" >}}](#is-distinct-from) | +| `IS NOT DISTINCT FROM` | Is not distinct from | [{{< icon "link" >}}](#is-not-distinct-from) | +| `~` | Matches a regular expression | [{{< icon "link" >}}](#regexp-match) | +| `~*` | Matches a regular expression _(case-insensitive)_ | [{{< icon "link" >}}](#regexp-match-case-insensitive) | +| `!~` | Does not match a regular expression | [{{< icon "link" >}}](#regexp-nomatch) | +| `!~*` | Does not match a regular expression _(case-insensitive)_ | [{{< icon "link" >}}](#regexp-nomatch-case-insensitive) | + + ## = {#equal-to .monospace} @@ -169,6 +173,141 @@ SELECT 1 <= 2 {{% /flex-content %}} {{< /flex >}} +## IS DISTINCT FROM {.monospace} + +The `IS DISTINCT FROM` operator is a _NULL_-safe operator that returns +`true` if both operands are not equal; otherwise, it returns `false`. +This operator guarantees the result of a comparison is `true` or `false` and not +an empty set. + +{{< flex >}} +{{% flex-content "two-thirds operator-example" %}} + +```sql +SELECT 0 IS DISTINCT FROM NULL +``` + +{{% /flex-content %}} +{{% flex-content "third operator-example" %}} + +| Int64(0) IS DISTINCT FROM NULL | +| :----------------------------- | +| true | + +{{% /flex-content %}} +{{< /flex >}} + +## IS NOT DISTINCT FROM {.monospace} + +The `IS NOT DISTINCT FROM` operator is a _NULL_-safe operator that returns +`true` if both operands are equal or _NULL_; otherwise, it returns `false`. +This operator negates [`IS DISTINCT FROM`](#is-distinct-from). + + + +{{< flex >}} +{{% flex-content "two-thirds operator-example" %}} + +```sql +SELECT NULL IS NOT DISTINCT FROM NULL +``` + +{{% /flex-content %}} +{{% flex-content "third operator-example" %}} + +| NULL IS NOT DISTINCT FROM NULL | +| :----------------------------- | +| true | + +{{% /flex-content %}} +{{< /flex >}} + + + ## ~ {#regexp-match .monospace} The `~` operator compares the left string operand to the right regular expression