diff --git a/modules/ROOT/nav.adoc b/modules/ROOT/nav.adoc index 78d6a9346..6c269c407 100644 --- a/modules/ROOT/nav.adoc +++ b/modules/ROOT/nav.adoc @@ -671,6 +671,7 @@ ***** xref:reference:sql/sql-functions/math-functions/sin.adoc[] ***** xref:reference:sql/sql-functions/math-functions/sinh.adoc[] ***** xref:reference:sql/sql-functions/math-functions/sqrt.adoc[] +***** xref:reference:sql/sql-functions/math-functions/tanh.adoc[] ***** xref:reference:sql/sql-functions/math-functions/to-char-from-number.adoc[] **** xref:reference:sql/sql-functions/other-functions/index.adoc[Other] ***** xref:reference:sql/sql-functions/other-functions/coalesce.adoc[] diff --git a/modules/reference/pages/sql/sql-data-types/interval.adoc b/modules/reference/pages/sql/sql-data-types/interval.adoc index 2a0067b12..462f38e8f 100644 --- a/modules/reference/pages/sql/sql-data-types/interval.adoc +++ b/modules/reference/pages/sql/sql-data-types/interval.adoc @@ -145,7 +145,7 @@ SELECT INTERVAL '2-4 5 DAYS 04:05:06.070809' YEAR TO MONTH as "Interval"; === Extract data from interval -To extract interval numbers from a timestamp, use the `EXTRACT` function: +To extract interval numbers from a timestamp, use the `extract` function: [source,sql] ---- diff --git a/modules/reference/pages/sql/sql-data-types/text.adoc b/modules/reference/pages/sql/sql-data-types/text.adoc index cf7d521d0..f11084941 100644 --- a/modules/reference/pages/sql/sql-data-types/text.adoc +++ b/modules/reference/pages/sql/sql-data-types/text.adoc @@ -40,9 +40,9 @@ The following output shows the created table: +---------------+---------------+---------------+ ---- -== Text with SUBSTR function +== Text with substr function -The `SUBSTR` function extracts a specific number of characters from a text. +The `substr` function extracts a specific number of characters from a text. === Syntax diff --git a/modules/reference/pages/sql/sql-functions/math-functions/greatest.adoc b/modules/reference/pages/sql/sql-functions/math-functions/greatest.adoc index fc304afac..b6a714091 100644 --- a/modules/reference/pages/sql/sql-functions/math-functions/greatest.adoc +++ b/modules/reference/pages/sql/sql-functions/math-functions/greatest.adoc @@ -1,8 +1,8 @@ -= GREATEST -:description: The `GREATEST` function returns the largest value from a set of values. += greatest +:description: The `greatest` function returns the largest value from a set of values. :page-topic-type: reference -The `GREATEST` function returns the greatest value from a set of values. The arguments must be of compatible types. For example, comparing a text value with a number returns an error. +The `greatest` function returns the greatest value from a set of values. The arguments must be of compatible types. For example, comparing a text value with a number returns an error. == Syntax @@ -98,7 +98,7 @@ greatest === Use table data -You can also use `GREATEST` to find the greatest value across columns. For example, create a table named `Student` that stores student names and scores. +You can also use `greatest` to find the greatest value across columns. For example, create a table named `Student` that stores student names and scores. [source,sql] ---- diff --git a/modules/reference/pages/sql/sql-functions/math-functions/index.adoc b/modules/reference/pages/sql/sql-functions/math-functions/index.adoc index ec11c0e28..4d78887cd 100644 --- a/modules/reference/pages/sql/sql-functions/math-functions/index.adoc +++ b/modules/reference/pages/sql/sql-functions/math-functions/index.adoc @@ -14,8 +14,8 @@ Mathematical, trigonometric, and hyperbolic functions in Redpanda SQL are design |xref:reference:sql/sql-functions/math-functions/ceil.adoc[`ceil()`] |This function rounds up to the nearest positive or negative integer value greater than or equal to the argument |xref:reference:sql/sql-functions/math-functions/exp.adoc[`exp()`] |This function returns the exponential value of a number specified in the argument |xref:reference:sql/sql-functions/math-functions/floor.adoc[`floor()`] |This function returns a number rounded down that is less than or equal to the specified argument -|xref:reference:sql/sql-functions/math-functions/greatest.adoc[`GREATEST`] |This function extracts the greatest or largest value from a set of values. -|xref:reference:sql/sql-functions/math-functions/least.adoc[`LEAST`] |This function returns the least or smallest value in a list of values +|xref:reference:sql/sql-functions/math-functions/greatest.adoc[`greatest()`] |This function extracts the greatest or largest value from a set of values. +|xref:reference:sql/sql-functions/math-functions/least.adoc[`least()`] |This function returns the least or smallest value in a list of values |xref:reference:sql/sql-functions/math-functions/ln.adoc[`ln()`] |This function returns the natural logarithm (base e) of its argument |xref:reference:sql/sql-functions/math-functions/log.adoc[`log()`] |This function returns the base-10 logarithm or logarithm of the specified base of a given number |xref:reference:sql/sql-functions/math-functions/power.adoc[`power()`] |This function returns the value of a number raised to the power of another number specified in the arguments @@ -45,7 +45,7 @@ These trigonometric functions take arguments and return values of type `double p |`cosd` |Calculates the cosine of a given argument, where the argument is in degrees. |`cosd(argument)` |`select cosd(60);` Returns: `0.5000000000000001` |`cot` |Calculates the cotangent of a given argument, where the argument is in radians. |`cot(argument)` |`select cot(0.5);` Returns: `1.8304877` |`cotd` |Calculates the cotangent of a given argument, where the argument is in degrees. |`cotd(argument)` |`select cotd(45);` Returns: `1.0000000000000002` -|xref:reference:sql/sql-functions/math-functions/sin.adoc[sin] |Calculates the sine of a given argument, where the argument is in radians. |`sin(argument)` |`select sin(1);` Returns: `0.8414709848078965` +|xref:reference:sql/sql-functions/math-functions/sin.adoc[`sin`] |Calculates the sine of a given argument, where the argument is in radians. |`sin(argument)` |`select sin(1);` Returns: `0.8414709848078965` |`sind` |Calculates the sine of a given argument, where the argument is in degrees. |`sind(argument)` |`select sind(30);` Returns: `0.49999999999999994` |`tan` |Calculates the tangent of a given argument, where the argument is in radians. |`tan(argument)` |`select tan(1);` Returns: `1.5574077246549023` |`tand` |Calculates the tangent of a given argument, where the argument is in degrees. |`tand(argument)` |`select tand(45);` Returns: `0.9999999999999999` @@ -56,6 +56,7 @@ These trigonometric functions take arguments and return values of type `double p [width="100%",cols="6%,32%,26%,36%",options="header",] |=== |*Function* |*Description* |*Syntax* |*Example* -|xref:reference:sql/sql-functions/math-functions/cosh.adoc[cosh] |Calculates the hyperbolic cosine of a given argument. |`cosh(argument)` |`select cosh(1);` Returns: `1.5430806348152437` -|xref:reference:sql/sql-functions/math-functions/sinh.adoc[sinh] |Calculates the hyperbolic sine of a given argument. |`sinh(argument)` |`select sinh(1);` Returns: `1.1752011936438014` +|xref:reference:sql/sql-functions/math-functions/cosh.adoc[`cosh`] |Calculates the hyperbolic cosine of a given argument. |`cosh(argument)` |`select cosh(1);` Returns: `1.5430806348152437` +|xref:reference:sql/sql-functions/math-functions/sinh.adoc[`sinh`] |Calculates the hyperbolic sine of a given argument. |`sinh(argument)` |`select sinh(1);` Returns: `1.1752011936438014` +|xref:reference:sql/sql-functions/math-functions/tanh.adoc[`tanh`] |Calculates the hyperbolic tangent of a given argument. |`tanh(argument)` |`select tanh(1);` Returns: `0.7615941559557649` |=== diff --git a/modules/reference/pages/sql/sql-functions/math-functions/least.adoc b/modules/reference/pages/sql/sql-functions/math-functions/least.adoc index 27a008317..0aea0b52e 100644 --- a/modules/reference/pages/sql/sql-functions/math-functions/least.adoc +++ b/modules/reference/pages/sql/sql-functions/math-functions/least.adoc @@ -1,14 +1,14 @@ -= LEAST -:description: The `LEAST` function returns the smallest value in a list of values. += least +:description: The `least` function returns the smallest value in a list of values. :page-topic-type: reference -The `LEAST` function returns the least or smallest value in a list of values. It needs at least one argument to work with. If different types are mixed, like a text and a number, it returns an error. +The `least` function returns the least or smallest value in a list of values. It needs at least one argument to work with. If different types are mixed, like a text and a number, it returns an error. For example, comparing the greatest value among 4, "`two`", and 9 would result in an error. == Syntax -The syntax for the `LEAST` function is: +The syntax for the `least` function is: [source,sql] ---- @@ -29,7 +29,7 @@ Where: == Examples -These examples show how to use the `LEAST` function: +These examples show how to use the `least` function: === Basic usage diff --git a/modules/reference/pages/sql/sql-functions/math-functions/tanh.adoc b/modules/reference/pages/sql/sql-functions/math-functions/tanh.adoc new file mode 100644 index 000000000..e72f4b124 --- /dev/null +++ b/modules/reference/pages/sql/sql-functions/math-functions/tanh.adoc @@ -0,0 +1,69 @@ += tanh +:description: The `tanh()` function returns the hyperbolic tangent of a specified numeric argument. +:page-topic-type: reference + +The `tanh()` function returns the hyperbolic tangent of a specified numeric argument. + +== Syntax + +[source,sql] +---- +TANH(x) +---- + +== Arguments + +* `x`: A number of type `real` or `double precision`, including zero. + +== Return type + +Same as the input type (`real` or `double precision`). + +== Examples + +=== Positive value + +[source,sql] +---- +SELECT TANH(1); +---- + +[source,sql] +---- + tanh +-------------------- + 0.7615941559557649 +(1 row) +---- + +=== Negative value + +`TANH(-x)` returns the negative of `TANH(x)`: + +[source,sql] +---- +SELECT TANH(-1); +---- + +[source,sql] +---- + tanh +--------------------- + -0.7615941559557649 +(1 row) +---- + +=== Zero + +[source,sql] +---- +SELECT TANH(0); +---- + +[source,sql] +---- + tanh +------ + 0 +(1 row) +---- diff --git a/modules/reference/pages/sql/sql-functions/other-functions/coalesce.adoc b/modules/reference/pages/sql/sql-functions/other-functions/coalesce.adoc index 0c66b6904..0c4552e01 100644 --- a/modules/reference/pages/sql/sql-functions/other-functions/coalesce.adoc +++ b/modules/reference/pages/sql/sql-functions/other-functions/coalesce.adoc @@ -1,12 +1,12 @@ -= COALESCE -:description: The `COALESCE` function returns the first non-NULL argument from a list of arguments. += coalesce +:description: The `coalesce` function returns the first non-NULL argument from a list of arguments. :page-topic-type: reference -The `COALESCE` function returns the first non-NULL argument from a list of arguments. After finding the first non-NULL argument, the function stops evaluating the remaining arguments. +The `coalesce` function returns the first non-NULL argument from a list of arguments. After finding the first non-NULL argument, the function stops evaluating the remaining arguments. [NOTE] ==== -If all arguments are NULL, `COALESCE` returns NULL. +If all arguments are NULL, `coalesce` returns NULL. ==== == Syntax @@ -20,17 +20,17 @@ COALESCE (argument_1, argument_2, …); Key points from the syntax: -* `COALESCE` requires a minimum of two inputs. +* `coalesce` requires a minimum of two inputs. * It can take an unlimited number of arguments. * Evaluation occurs sequentially from left to right, stopping at the first non-null value. == Examples -Here are some examples to illustrate the application of `COALESCE`: +Here are some examples to illustrate the application of `coalesce`: === Return the first non-null value -In this example, a set of values is provided. The `COALESCE` function returns the first non-null value from this set. +In this example, a set of values is provided. The `coalesce` function returns the first non-null value from this set. [source,sql] ---- @@ -91,7 +91,7 @@ In this query, NULL appears in the first, second, fourth, and last positions: Select COALESCE(NULL, NULL ,3, NULL, 7,9,4,5, NULL); ---- -The `COALESCE` function ignores the first two NULLs and returns the first non-null value, `3`. It does not process the subsequent NULL values. +The `coalesce` function ignores the first two NULLs and returns the first non-null value, `3`. It does not process the subsequent NULL values. [source,sql] ---- @@ -109,7 +109,7 @@ Assume that the given values are entirely composed of nulls. Select COALESCE(NULL, NULL ,NULL, NULL); ---- -In this case, the `COALESCE` function returns an empty value (NULL). +In this case, the `coalesce` function returns an empty value (NULL). [source,sql] ---- @@ -117,7 +117,7 @@ In this case, the `COALESCE` function returns an empty value (NULL). ---------- ---- -=== `COALESCE` with table data +=== `coalesce` with table data Consider the `employee_absent` table, which comprises a mix of NULL and non-null values: @@ -156,7 +156,7 @@ SELECT * FROM employee_absent; Emily | HR | ---- -The following query uses the `COALESCE` function on the `absent` column. It retrieves names and absences (with `out of office` for NULL values) for each employee. +The following query uses the `coalesce` function on the `absent` column. It retrieves names and absences (with `out of office` for NULL values) for each employee. [source,sql] ---- @@ -174,7 +174,7 @@ SELECT emp_name, COALESCE(absent, 'out of office') AS DisplayAbsent FROM employe Emily | out of office ---- -=== Error output in `COALESCE` +=== Error output in `coalesce` When specifying arguments with different datatypes, they should be convertible. @@ -183,7 +183,7 @@ When specifying arguments with different datatypes, they should be convertible. Select Coalesce ('x',NULL,1); ---- -If the datatypes cannot be converted, the `COALESCE` function generates an error. +If the datatypes cannot be converted, the `coalesce` function generates an error. [source,sql] ---- diff --git a/modules/reference/pages/sql/sql-functions/other-functions/index.adoc b/modules/reference/pages/sql/sql-functions/other-functions/index.adoc index ed37a6b3f..959f023f1 100644 --- a/modules/reference/pages/sql/sql-functions/other-functions/index.adoc +++ b/modules/reference/pages/sql/sql-functions/other-functions/index.adoc @@ -1,5 +1,5 @@ = Other Functions -:description: Reference for other Redpanda SQL functions, including `COALESCE`, `NULLIF`, and PostgreSQL system information functions. +:description: Reference for other Redpanda SQL functions, including `coalesce`, `nullif`, and PostgreSQL system information functions. :page-topic-type: reference Besides xref:reference:sql/sql-functions/math-functions/index.adoc[math], xref:reference:sql/sql-functions/aggregate-functions/index.adoc[aggregate], xref:reference:sql/sql-functions/window-functions/index.adoc[window], xref:reference:sql/sql-functions/string-functions/index.adoc[string], xref:reference:sql/sql-functions/timestamp-functions/index.adoc[timestamp], and xref:reference:sql/sql-functions/json-functions/index.adoc[`json`] functions, Redpanda SQL also supports these functions: @@ -7,25 +7,25 @@ Besides xref:reference:sql/sql-functions/math-functions/index.adoc[math], xref:r [cols="46%,54%",options="header",] |=== |Function |Description -|xref:reference:sql/sql-functions/other-functions/coalesce.adoc[`COALESCE`] |Returns the first argument that is not NULL, while the remaining arguments from the first non-null argument are not evaluated. -|xref:reference:sql/sql-functions/other-functions/current-database.adoc[current_database()] |Returns the current database's name. -|xref:reference:sql/sql-functions/other-functions/current-schema.adoc[current_schema()] |Returns the schema's name (first in the search path). -|xref:reference:sql/sql-functions/other-functions/has-schema-privilege.adoc[has_schema_privilege()] |Checks whether the current user has specific privileges on a schema. -|xref:reference:sql/sql-functions/other-functions/nullif.adoc[`NULLIF`] |Replaces a given value with NULL if it matches a specific criterion. -|xref:reference:sql/sql-functions/other-functions/pg-get-expr.adoc[pg_get_expr()] |Retrieves the internal form of an individual expression (such as the default value for a column). -|xref:reference:sql/sql-functions/other-functions/pg-total-relation-size.adoc[pg_total_relation_size()] |Retrieves the size of a table. -|xref:reference:sql/sql-functions/other-functions/pg-typeof.adoc[pg_typeof()] |Retrieves the data type of any given value. -|xref:reference:sql/sql-functions/other-functions/pg-encoding-to-char.adoc[pg_encoding_to_char()] |Converts an encoding internal identifier to a human-readable name. -|xref:reference:sql/sql-functions/other-functions/pg-get-indexdef.adoc[pg_get_indexdef()] |Reconstructs the PostgreSQL command used to retrieve the definition of a specified index. -|xref:reference:sql/sql-functions/other-functions/pg-get-userbyid.adoc[pg_get_userbyid()] |Retrieves the name of a user (role) given its unique identifier (OID). -|xref:reference:sql/sql-functions/other-functions/pg-relation-is-publishable.adoc[pg_relation_is_publishable()] |Determines whether a specified relation (table) can be published in a publication. -|xref:reference:sql/sql-functions/other-functions/pg-size-pretty.adoc[pg_size_pretty()] |Converts sizes in bytes into a human-readable format. -|xref:reference:sql/sql-functions/other-functions/pg-table-size.adoc[pg_table_size()] |Retrieves the size of a specific table, including its associated storage components but excluding indexes. -|xref:reference:sql/sql-functions/other-functions/pg-table-is-visible.adoc[pg_table_is_visible()] |Checks whether a specified table (or other database object) is visible in the current schema search path. -|xref:reference:sql/sql-functions/other-functions/pg-get-constraintdef.adoc[pg_get_constraintdef()] |Retrieves the definition of a specific constraint in a human-readable format. -|xref:reference:sql/sql-functions/other-functions/pg-get-statisticsobjdef-columns.adoc[pg_get_statisticsobjdef_columns()] |Retrieves the definitions of columns associated with a specified statistics object. -|xref:reference:sql/sql-functions/other-functions/obj-description.adoc[obj_description()] |Returns the comment associated with a specific database object. -|xref:reference:sql/sql-functions/other-functions/col-description.adoc[col_description()] |Retrieves the comment associated with a specified table column based on its name. -|xref:reference:sql/sql-functions/other-functions/shobj-description.adoc[shobj_description()] |Retrieves the comment associated with a shared database object. -|xref:reference:sql/sql-functions/other-functions/pg-backend-pid.adoc[pg_backend_pid()] |Returns the process ID (PID) of the node handling the current session. +|xref:reference:sql/sql-functions/other-functions/coalesce.adoc[`coalesce()`] |Returns the first argument that is not NULL, while the remaining arguments from the first non-null argument are not evaluated. +|xref:reference:sql/sql-functions/other-functions/current-database.adoc[`current_database()`] |Returns the current database's name. +|xref:reference:sql/sql-functions/other-functions/current-schema.adoc[`current_schema()`] |Returns the schema's name (first in the search path). +|xref:reference:sql/sql-functions/other-functions/has-schema-privilege.adoc[`has_schema_privilege()`] |Checks whether the current user has specific privileges on a schema. +|xref:reference:sql/sql-functions/other-functions/nullif.adoc[`nullif()`] |Replaces a given value with NULL if it matches a specific criterion. +|xref:reference:sql/sql-functions/other-functions/pg-get-expr.adoc[`pg_get_expr()`] |Retrieves the internal form of an individual expression (such as the default value for a column). +|xref:reference:sql/sql-functions/other-functions/pg-total-relation-size.adoc[`pg_total_relation_size()`] |Retrieves the size of a table. +|xref:reference:sql/sql-functions/other-functions/pg-typeof.adoc[`pg_typeof()`] |Retrieves the data type of any given value. +|xref:reference:sql/sql-functions/other-functions/pg-encoding-to-char.adoc[`pg_encoding_to_char()`] |Converts an encoding internal identifier to a human-readable name. +|xref:reference:sql/sql-functions/other-functions/pg-get-indexdef.adoc[`pg_get_indexdef()`] |Reconstructs the PostgreSQL command used to retrieve the definition of a specified index. +|xref:reference:sql/sql-functions/other-functions/pg-get-userbyid.adoc[`pg_get_userbyid()`] |Retrieves the name of a user (role) given its unique identifier (OID). +|xref:reference:sql/sql-functions/other-functions/pg-relation-is-publishable.adoc[`pg_relation_is_publishable()`] |Determines whether a specified relation (table) can be published in a publication. +|xref:reference:sql/sql-functions/other-functions/pg-size-pretty.adoc[`pg_size_pretty()`] |Converts sizes in bytes into a human-readable format. +|xref:reference:sql/sql-functions/other-functions/pg-table-size.adoc[`pg_table_size()`] |Retrieves the size of a specific table, including its associated storage components but excluding indexes. +|xref:reference:sql/sql-functions/other-functions/pg-table-is-visible.adoc[`pg_table_is_visible()`] |Checks whether a specified table (or other database object) is visible in the current schema search path. +|xref:reference:sql/sql-functions/other-functions/pg-get-constraintdef.adoc[`pg_get_constraintdef()`] |Retrieves the definition of a specific constraint in a human-readable format. +|xref:reference:sql/sql-functions/other-functions/pg-get-statisticsobjdef-columns.adoc[`pg_get_statisticsobjdef_columns()`] |Retrieves the definitions of columns associated with a specified statistics object. +|xref:reference:sql/sql-functions/other-functions/obj-description.adoc[`obj_description()`] |Returns the comment associated with a specific database object. +|xref:reference:sql/sql-functions/other-functions/col-description.adoc[`col_description()`] |Retrieves the comment associated with a specified table column based on its name. +|xref:reference:sql/sql-functions/other-functions/shobj-description.adoc[`shobj_description()`] |Retrieves the comment associated with a shared database object. +|xref:reference:sql/sql-functions/other-functions/pg-backend-pid.adoc[`pg_backend_pid()`] |Returns the process ID (PID) of the node handling the current session. |=== diff --git a/modules/reference/pages/sql/sql-functions/other-functions/nullif.adoc b/modules/reference/pages/sql/sql-functions/other-functions/nullif.adoc index 8098a11f9..d86d07ea6 100644 --- a/modules/reference/pages/sql/sql-functions/other-functions/nullif.adoc +++ b/modules/reference/pages/sql/sql-functions/other-functions/nullif.adoc @@ -1,8 +1,8 @@ -= NULLIF -:description: The `NULLIF` function replaces a given value with NULL if it matches a specific criterion. += nullif +:description: The `nullif` function replaces a given value with NULL if it matches a specific criterion. :page-topic-type: reference -The `NULLIF` function replaces a given value with NULL if it matches a specific criterion. +The `nullif` function replaces a given value with NULL if it matches a specific criterion. == Syntax @@ -11,21 +11,21 @@ The `NULLIF` function replaces a given value with NULL if it matches a specific NULLIF(argument_1,argument_2); ---- -The `NULLIF` function takes two arguments: +The `nullif` function takes two arguments: * The first argument is the value to evaluate. * The second argument is the value to treat as NULL if the first argument matches it. [TIP] ==== -If the first argument matches the second argument, the `NULLIF` function returns `NULL`. Otherwise, it returns the first argument as-is. +If the first argument matches the second argument, the `nullif` function returns `NULL`. Otherwise, it returns the first argument as-is. ==== == Examples === Handle equal values -In this case, the `NULLIF` function compares the values 4 and 4. +In this case, the `nullif` function compares the values 4 and 4. [source,sql] ---- @@ -42,14 +42,14 @@ The result is `NULL` because the two values being compared are equal (4 = 4). === Handle different values -This example uses the `NULLIF` function to manage different values. +This example uses the `nullif` function to manage different values. [source,sql] ---- SELECT NULLIF (9, 0); ---- -The result is `9` because the second value in the `NULLIF` function is 0 (the two values are not equal). +The result is `9` because the second value in the `nullif` function is 0 (the two values are not equal). [source,sql] ---- @@ -60,7 +60,7 @@ The result is `9` because the second value in the `NULLIF` function is 0 (the tw === String comparison -In this case, the `NULLIF` function compares the strings `L` and `O`. +In this case, the `nullif` function compares the strings `L` and `O`. [source,sql] ---- @@ -122,7 +122,7 @@ SELECT name, NULLIF(salary, 0) AS adjusted_salary FROM employees; ---- -The `NULLIF` function checks whether the `salary` value is 0. If it is, the function returns NULL. Otherwise, it returns the original `salary` value. +The `nullif` function checks whether the `salary` value is 0. If it is, the function returns NULL. Otherwise, it returns the original `salary` value. [source,sql] ---- @@ -173,7 +173,7 @@ SELECT * FROM fractions; 15 | 3 ---- -Here, the `NULLIF` function is applied to the `denominator` column. If the `denominator` is 0, the function returns NULL, avoiding division by zero. +Here, the `nullif` function is applied to the `denominator` column. If the `denominator` is 0, the function returns NULL, avoiding division by zero. [source,sql] ---- diff --git a/modules/reference/pages/sql/sql-functions/string-functions/index.adoc b/modules/reference/pages/sql/sql-functions/string-functions/index.adoc index 7a47d666d..185659e4e 100644 --- a/modules/reference/pages/sql/sql-functions/string-functions/index.adoc +++ b/modules/reference/pages/sql/sql-functions/string-functions/index.adoc @@ -14,12 +14,12 @@ Use string functions to analyze and manipulate string values. Redpanda SQL suppo |xref:reference:sql/sql-functions/string-functions/starts-with.adoc[`starts_with()`] |Checks if a string starts with a specified substring |xref:reference:sql/sql-functions/string-functions/ends-with.adoc[`ends_with()`] |Checks if a string ends with a specified substring |xref:reference:sql/sql-functions/string-functions/concat.adoc[`concat()`] |Adds two or more strings together -|xref:reference:sql/sql-functions/string-functions/substring.adoc[`SUBSTRING`] |Extracts a substring from a string. `SUBSTR` is an alias. +|xref:reference:sql/sql-functions/string-functions/substring.adoc[`substring()`] |Extracts a substring from a string. `substr` is an alias. |xref:reference:sql/sql-functions/string-functions/strpos.adoc[`strpos()`] |Finds the position at which the substring starts within the string |xref:reference:sql/sql-functions/string-functions/regex/regexp-match.adoc[`regexp_match()`] |Matches a POSIX regular expression pattern to a string |xref:reference:sql/sql-functions/string-functions/regex/regexp-replace.adoc[`regexp_replace()`] |Substitutes new text for substrings that match POSIX regular expression patterns |xref:reference:sql/sql-functions/string-functions/replace.adoc[`replace()`] |Finds and replace occurrences of a substring in a string -|xref:reference:sql/sql-functions/string-functions/position.adoc[`POSITION`] |Returns the position of the first occurrence of a substring in a string +|xref:reference:sql/sql-functions/string-functions/position.adoc[`position()`] |Returns the position of the first occurrence of a substring in a string |=== == String operators diff --git a/modules/reference/pages/sql/sql-functions/string-functions/position.adoc b/modules/reference/pages/sql/sql-functions/string-functions/position.adoc index 390b6ae42..5fea7657f 100644 --- a/modules/reference/pages/sql/sql-functions/string-functions/position.adoc +++ b/modules/reference/pages/sql/sql-functions/string-functions/position.adoc @@ -1,8 +1,8 @@ -= POSITION -:description: The `POSITION` function returns the position of the first occurrence of a substring in a string. += position +:description: The `position` function returns the position of the first occurrence of a substring in a string. :page-topic-type: reference -The `POSITION` function returns the position of the first occurrence of a substring in a string. It works the same as xref:reference:sql/sql-functions/string-functions/strpos.adoc[`strpos()`], but it has slightly different syntax. +The `position` function returns the position of the first occurrence of a substring in a string. It works the same as xref:reference:sql/sql-functions/string-functions/strpos.adoc[`strpos()`], but it has slightly different syntax. == Syntax diff --git a/modules/reference/pages/sql/sql-functions/string-functions/strpos.adoc b/modules/reference/pages/sql/sql-functions/string-functions/strpos.adoc index aa1a36763..ee70fe950 100644 --- a/modules/reference/pages/sql/sql-functions/string-functions/strpos.adoc +++ b/modules/reference/pages/sql/sql-functions/string-functions/strpos.adoc @@ -14,7 +14,7 @@ The input and return must be of type `string`. *Special cases:* * Returns `NULL` if there are no input rows or `NULL` values. -* If the `SUBSTRING` is not found in the string, then the `strpos()` function will return 0. +* If the `substring` is not found in the string, then the `strpos()` function will return 0. == Examples diff --git a/modules/reference/pages/sql/sql-functions/string-functions/substring.adoc b/modules/reference/pages/sql/sql-functions/string-functions/substring.adoc index cd49b8aff..da7b1ba0a 100644 --- a/modules/reference/pages/sql/sql-functions/string-functions/substring.adoc +++ b/modules/reference/pages/sql/sql-functions/string-functions/substring.adoc @@ -1,12 +1,12 @@ -= SUBSTRING -:description: The `SUBSTRING` function extracts a part of a string. `SUBSTR` is an alias. += substring +:description: The `substring` function extracts a part of a string. `substr` is an alias. :page-topic-type: reference -The `SUBSTRING` function extracts a part of a string and returns the result. `SUBSTR` is an alias for `SUBSTRING`. Both names produce the same result. +The `substring` function extracts a part of a string and returns the result. `substr` is an alias for `substring`. Both names produce the same result. == Syntax -Use either name (`SUBSTRING` or `SUBSTR`) with the same syntax: +Use either name (`substring` or `substr`) with the same syntax: *2 Arguments* @@ -71,7 +71,7 @@ substring Redpanda ---- -=== `SUBSTRING` with specified `start_position` and `length` +=== `substring` with specified `start_position` and `length` In this example, the `start_position` is set to position 6 and 5 characters are extracted: @@ -89,7 +89,7 @@ Fruit melon ---- -=== `SUBSTRING` with `length` = 0 +=== `substring` with `length` = 0 This query extracts a string with `length` = 0: @@ -106,7 +106,7 @@ Fruit ------- ---- -=== `SUBSTRING` with `length` = negative value +=== `substring` with `length` = negative value This example shows what happens when `length` is specified with a negative value: @@ -122,7 +122,7 @@ Instead of extracting the string from the last characters, it returns an error: ERROR: Length of substring cannot be negative ---- -=== `SUBSTRING` with `start_position` > `string` +=== `substring` with `start_position` > `string` The string `Watermelon` has only ten characters. This example shows what happens when the specified `start_position` is larger than the string's characters: @@ -139,7 +139,7 @@ Fruit ------- ---- -=== `SUBSTRING` with 2 arguments +=== `substring` with 2 arguments In this example, the `start_position` is set to position 6: diff --git a/modules/reference/pages/sql/sql-functions/timestamp-functions/extract.adoc b/modules/reference/pages/sql/sql-functions/timestamp-functions/extract.adoc index 75909e36f..cdac656c0 100644 --- a/modules/reference/pages/sql/sql-functions/timestamp-functions/extract.adoc +++ b/modules/reference/pages/sql/sql-functions/timestamp-functions/extract.adoc @@ -1,8 +1,8 @@ -= EXTRACT -:description: The `EXTRACT` function retrieves a specified part (field) from a given date/time or interval value. += extract +:description: The `extract` function retrieves a specified part (field) from a given date/time or interval value. :page-topic-type: reference -The `EXTRACT` function retrieves a specified part (field) from a given date/time or interval value. It is commonly used to obtain components such as year, month, day, and hour from timestamps or dates. +The `extract` function retrieves a specified part (field) from a given date/time or interval value. It is commonly used to obtain components such as year, month, day, and hour from timestamps or dates. == Syntax @@ -16,7 +16,7 @@ EXTRACT (field FROM source) * `field`: String or identifier specifying the part of the date / time to extract. * `source`: Date / time value from which to extract the specified field. -This table shows the supported input and corresponding return types for the `EXTRACT` function: +This table shows the supported input and corresponding return types for the `extract` function: [width="100%",cols="24%,55%,21%",options="header",] |=== @@ -33,9 +33,9 @@ The SECOND field returns a fractional value as `double precision` to include fra == Examples -=== `EXTRACT` with timestamp - year +=== `extract` with timestamp - year -This example shows how to use the `EXTRACT` function to extract a given timestamp's year: +This example shows how to use the `extract` function to extract a given timestamp's year: [source,sql] ---- @@ -53,9 +53,9 @@ The query returns: +----------+ ---- -=== `EXTRACT` with timestamp - month +=== `extract` with timestamp - month -This example uses the `EXTRACT` function to extract a given timestamp's month: +This example uses the `extract` function to extract a given timestamp's month: [source,sql] ---- @@ -73,9 +73,9 @@ The query returns the month's part of the given timestamp: +----------+ ---- -=== `EXTRACT` with timestamp - seconds (including fractional seconds) +=== `extract` with timestamp - seconds (including fractional seconds) -This example uses the `EXTRACT` function to extract a given timestamp's seconds, including fractional seconds: +This example uses the `extract` function to extract a given timestamp's seconds, including fractional seconds: [source,sql] ---- diff --git a/modules/reference/pages/sql/sql-functions/timestamp-functions/index.adoc b/modules/reference/pages/sql/sql-functions/timestamp-functions/index.adoc index 322b81b9b..7da291e10 100644 --- a/modules/reference/pages/sql/sql-functions/timestamp-functions/index.adoc +++ b/modules/reference/pages/sql/sql-functions/timestamp-functions/index.adoc @@ -15,7 +15,7 @@ Timestamp functions return a date-time value based on a specified timestamp/inte |xref:reference:sql/sql-functions/timestamp-functions/timestamp-millis.adoc[`timestamp_millis()`] |Converts a UNIX timestamp in milliseconds to a timestamp. |xref:reference:sql/sql-functions/timestamp-functions/timestamp-micros.adoc[`timestamp_micros()`] |Converts a UNIX timestamp in microseconds to a timestamp. |xref:reference:sql/sql-functions/timestamp-functions/timestamp-trunc.adoc[`timestamp_trunc()`] |Truncates a given timestamp to the nearest time part. Supported time parts are YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND -|xref:reference:sql/sql-functions/timestamp-functions/extract.adoc[`EXTRACT`] |Extracts some part of a specified timestamp or interval. +|xref:reference:sql/sql-functions/timestamp-functions/extract.adoc[`extract()`] |Extracts some part of a specified timestamp or interval. |xref:reference:sql/sql-functions/timestamp-functions/to-timestamp.adoc[`to_timestamp()`] |Converts a string into a timestamp based on the provided format. |xref:reference:sql/sql-functions/timestamp-functions/date-trunc.adoc[`date_trunc()`] |Truncates intervals or timestamps/time zones to a specified field. |xref:reference:sql/sql-functions/timestamp-functions/to-char.adoc[`to_char()` from Timestamp] |Formats a timestamp into a string using a given format.