From 1fb539704ef8f9ebaa9ab9f42f214fdd7187f67d Mon Sep 17 00:00:00 2001 From: Blargian Date: Wed, 24 Apr 2024 18:43:44 +0200 Subject: [PATCH 1/3] Update length and lengthUTF8 --- .../functions/string-functions.md | 83 +++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/docs/en/sql-reference/functions/string-functions.md b/docs/en/sql-reference/functions/string-functions.md index 400d29364a2..14c52807d1e 100644 --- a/docs/en/sql-reference/functions/string-functions.md +++ b/docs/en/sql-reference/functions/string-functions.md @@ -88,20 +88,93 @@ Result: ## length -Returns the length of a string in bytes (not: in characters or Unicode code points). - -The function also works for arrays. +Returns the length of a string in bytes rather than in characters or Unicode code points. The function also works for arrays. Alias: `OCTET_LENGTH` +**Syntax** + +```sql +length(s) +``` + +**Parameters** + +- `s`: An input string. [String](../data-types/string)/[Array](../data-types/array). + +**Returned value** + +- Length of the string `s` in bytes. [UInt64](../data-types/int-uint). + +**Example** + +Query: + +```sql +SELECT length('Hello, world!'); +``` + +Result: + +```response +┌─length('Hello, world!')─┐ +│ 13 │ +└─────────────────────────┘ +``` + +Query: + +```sql +SELECT length([1, 2, 3, 4]); +``` + +Result: + +```response +┌─length([1, 2, 3, 4])─┐ +│ 4 │ +└──────────────────────┘ +``` + + ## lengthUTF8 -Returns the length of a string in Unicode code points (not: in bytes or characters). It assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. +Returns the length of a string in Unicode code points rather than in bytes or characters. It assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. -Alias: +Aliases: - `CHAR_LENGTH` - `CHARACTER_LENGTH` +**Syntax** + +```sql +lengthUTF8(s) +``` + +**Parameters** + +- `s`: String containing valid UTF-8 encoded text. [String](../data-types/string). + +**Returned value** + +- Length of the string `s` in Unicode code points. [UInt64](../data-types/int-uint.md). + +**Example** + +Query: + +```sql +SELECT lengthUTF8('Здравствуй, мир!'); +``` + +Result: + +```response +┌─lengthUTF8('Здравствуй, мир!')─┐ +│ 16 │ +└────────────────────────────────┘ +``` + ## left Returns a substring of string `s` with a specified `offset` starting from the left. From 30583d594c20c331619f329e91c8689ee6a7862c Mon Sep 17 00:00:00 2001 From: Shaun Struwig <41984034+Blargian@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:52:14 +0200 Subject: [PATCH 2/3] Update string-functions.md Add mention of array to parameter --- docs/en/sql-reference/functions/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/sql-reference/functions/string-functions.md b/docs/en/sql-reference/functions/string-functions.md index 14c52807d1e..950f77cc685 100644 --- a/docs/en/sql-reference/functions/string-functions.md +++ b/docs/en/sql-reference/functions/string-functions.md @@ -100,7 +100,7 @@ length(s) **Parameters** -- `s`: An input string. [String](../data-types/string)/[Array](../data-types/array). +- `s`: An input string or array. [String](../data-types/string)/[Array](../data-types/array). **Returned value** From 2d9a1d5259fa32c75676444a656ebf8ce87956cc Mon Sep 17 00:00:00 2001 From: Shaun Struwig <41984034+Blargian@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:54:00 +0200 Subject: [PATCH 3/3] Update string-functions.md --- docs/en/sql-reference/functions/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/sql-reference/functions/string-functions.md b/docs/en/sql-reference/functions/string-functions.md index 950f77cc685..7e68b11b71a 100644 --- a/docs/en/sql-reference/functions/string-functions.md +++ b/docs/en/sql-reference/functions/string-functions.md @@ -104,7 +104,7 @@ length(s) **Returned value** -- Length of the string `s` in bytes. [UInt64](../data-types/int-uint). +- Length of the string or array `s` in bytes. [UInt64](../data-types/int-uint). **Example**