From 32f26bcde77b17f595b7e59785b31345abd24e2a Mon Sep 17 00:00:00 2001 From: vdimir Date: Sun, 2 Aug 2020 13:29:10 +0000 Subject: [PATCH] Add start_pos argument for position to documentation, case insensitive tests --- .../functions/string-search-functions.md | 26 +++++++++--- .../functions/string-search-functions.md | 14 ++++--- .../functions/string-search-functions.md | 14 ++++--- .../functions/string-search-functions.md | 14 ++++--- .../functions/string-search-functions.md | 14 ++++--- .../functions/string-search-functions.md | 14 ++++--- .../00233_position_function_family.reference | 42 +++++++++++++++++++ .../00233_position_function_family.sql | 8 ++++ 8 files changed, 116 insertions(+), 30 deletions(-) diff --git a/docs/en/sql-reference/functions/string-search-functions.md b/docs/en/sql-reference/functions/string-search-functions.md index 067644c30b2..a625af14505 100644 --- a/docs/en/sql-reference/functions/string-search-functions.md +++ b/docs/en/sql-reference/functions/string-search-functions.md @@ -21,15 +21,16 @@ For a case-insensitive search, use the function [positionCaseInsensitive](#posit **Syntax** ``` sql -position(haystack, needle) +position(haystack, needle[, start_pos]) ``` -Alias: `locate(haystack, needle)`. +Alias: `locate(haystack, needle[, start_pos])`. **Parameters** - `haystack` — string, in which substring will to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). - `needle` — substring to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Returned values** @@ -56,6 +57,18 @@ Result: └────────────────────────────────┘ ``` +``` sql +SELECT + position('Hello, world!', 'o', 1), + position('Hello, world!', 'o', 7) +``` + +``` text +┌─position('Hello, world!', 'o', 1)─┬─position('Hello, world!', 'o', 7)─┐ +│ 5 │ 9 │ +└───────────────────────────────────┴───────────────────────────────────┘ +``` + The same phrase in Russian contains characters which can’t be represented using a single byte. The function returns some unexpected result (use [positionUTF8](#positionutf8) function for multi-byte encoded text): Query: @@ -81,13 +94,14 @@ Works under the assumption that the string contains a set of bytes representing **Syntax** ``` sql -positionCaseInsensitive(haystack, needle) +positionCaseInsensitive(haystack, needle[, start_pos]) ``` **Parameters** - `haystack` — string, in which substring will to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). - `needle` — substring to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Returned values** @@ -123,13 +137,14 @@ For a case-insensitive search, use the function [positionCaseInsensitiveUTF8](#p **Syntax** ``` sql -positionUTF8(haystack, needle) +positionUTF8(haystack, needle[, start_pos]) ``` **Parameters** - `haystack` — string, in which substring will to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). - `needle` — substring to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Returned values** @@ -195,13 +210,14 @@ Works under the assumption that the string contains a set of bytes representing **Syntax** ``` sql -positionCaseInsensitiveUTF8(haystack, needle) +positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) ``` **Parameters** - `haystack` — string, in which substring will to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). - `needle` — substring to be searched. [String](../../sql-reference/syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Returned value** diff --git a/docs/es/sql-reference/functions/string-search-functions.md b/docs/es/sql-reference/functions/string-search-functions.md index 3236745b22c..c448872a186 100644 --- a/docs/es/sql-reference/functions/string-search-functions.md +++ b/docs/es/sql-reference/functions/string-search-functions.md @@ -20,15 +20,16 @@ Para una búsqueda sin distinción de mayúsculas y minúsculas, utilice la func **Sintaxis** ``` sql -position(haystack, needle) +position(haystack, needle[, start_pos]) ``` -Apodo: `locate(haystack, needle)`. +Apodo: `locate(haystack, needle[, start_pos])`. **Parámetros** - `haystack` — string, in which substring will to be searched. [Cadena](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Cadena](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Valores devueltos** @@ -80,13 +81,14 @@ Funciona bajo el supuesto de que la cadena contiene un conjunto de bytes que rep **Sintaxis** ``` sql -positionCaseInsensitive(haystack, needle) +positionCaseInsensitive(haystack, needle[, start_pos]) ``` **Parámetros** - `haystack` — string, in which substring will to be searched. [Cadena](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Cadena](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Valores devueltos** @@ -122,13 +124,14 @@ Para una búsqueda sin distinción de mayúsculas y minúsculas, utilice la func **Sintaxis** ``` sql -positionUTF8(haystack, needle) +positionUTF8(haystack, needle[, start_pos]) ``` **Parámetros** - `haystack` — string, in which substring will to be searched. [Cadena](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Cadena](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Valores devueltos** @@ -194,13 +197,14 @@ Funciona bajo el supuesto de que la cadena contiene un conjunto de bytes que rep **Sintaxis** ``` sql -positionCaseInsensitiveUTF8(haystack, needle) +positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) ``` **Parámetros** - `haystack` — string, in which substring will to be searched. [Cadena](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Cadena](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Valor devuelto** diff --git a/docs/fa/sql-reference/functions/string-search-functions.md b/docs/fa/sql-reference/functions/string-search-functions.md index af68dee0afa..cce6f8f5a4e 100644 --- a/docs/fa/sql-reference/functions/string-search-functions.md +++ b/docs/fa/sql-reference/functions/string-search-functions.md @@ -21,15 +21,16 @@ toc_title: "\u0628\u0631\u0627\u06CC \u062C\u0633\u062A\u062C\u0648\u06CC \u0631 **نحو** ``` sql -position(haystack, needle) +position(haystack, needle[, start_pos]) ``` -نام مستعار: `locate(haystack, needle)`. +نام مستعار: `locate(haystack, needle[, start_pos])`. **پارامترها** - `haystack` — string, in which substring will to be searched. [رشته](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [رشته](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **مقادیر بازگشتی** @@ -81,13 +82,14 @@ SELECT position('Привет, мир!', '!') **نحو** ``` sql -positionCaseInsensitive(haystack, needle) +positionCaseInsensitive(haystack, needle[, start_pos]) ``` **پارامترها** - `haystack` — string, in which substring will to be searched. [رشته](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [رشته](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **مقادیر بازگشتی** @@ -123,13 +125,14 @@ SELECT positionCaseInsensitive('Hello, world!', 'hello') **نحو** ``` sql -positionUTF8(haystack, needle) +positionUTF8(haystack, needle[, start_pos]) ``` **پارامترها** - `haystack` — string, in which substring will to be searched. [رشته](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [رشته](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **مقادیر بازگشتی** @@ -195,13 +198,14 @@ SELECT positionUTF8('Salut, étudiante!', '!') **نحو** ``` sql -positionCaseInsensitiveUTF8(haystack, needle) +positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) ``` **پارامترها** - `haystack` — string, in which substring will to be searched. [رشته](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [رشته](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **مقدار بازگشتی** diff --git a/docs/ja/sql-reference/functions/string-search-functions.md b/docs/ja/sql-reference/functions/string-search-functions.md index 00f68c061dd..e5858ba4941 100644 --- a/docs/ja/sql-reference/functions/string-search-functions.md +++ b/docs/ja/sql-reference/functions/string-search-functions.md @@ -20,15 +20,16 @@ toc_title: "\u6587\u5B57\u5217\u3092\u691C\u7D22\u3059\u308B\u5834\u5408" **構文** ``` sql -position(haystack, needle) +position(haystack, needle[, start_pos]) ``` -別名: `locate(haystack, needle)`. +別名: `locate(haystack, needle[, start_pos])`. **パラメータ** - `haystack` — string, in which substring will to be searched. [文字列](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [文字列](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **戻り値** @@ -80,13 +81,14 @@ SELECT position('Привет, мир!', '!') **構文** ``` sql -positionCaseInsensitive(haystack, needle) +positionCaseInsensitive(haystack, needle[, start_pos]) ``` **パラメータ** - `haystack` — string, in which substring will to be searched. [文字列](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [文字列](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **戻り値** @@ -122,13 +124,14 @@ SELECT positionCaseInsensitive('Hello, world!', 'hello') **構文** ``` sql -positionUTF8(haystack, needle) +positionUTF8(haystack, needle[, start_pos]) ``` **パラメータ** - `haystack` — string, in which substring will to be searched. [文字列](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [文字列](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **戻り値** @@ -194,13 +197,14 @@ SELECT positionUTF8('Salut, étudiante!', '!') **構文** ``` sql -positionCaseInsensitiveUTF8(haystack, needle) +positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) ``` **パラメータ** - `haystack` — string, in which substring will to be searched. [文字列](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [文字列](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **戻り値** diff --git a/docs/ru/sql-reference/functions/string-search-functions.md b/docs/ru/sql-reference/functions/string-search-functions.md index b363211d6d0..de713031046 100644 --- a/docs/ru/sql-reference/functions/string-search-functions.md +++ b/docs/ru/sql-reference/functions/string-search-functions.md @@ -15,15 +15,16 @@ **Синтаксис** ``` sql -position(haystack, needle) +position(haystack, needle[, start_pos]) ``` -Алиас: `locate(haystack, needle)`. +Алиас: `locate(haystack, needle[, start_pos])`. **Параметры** - `haystack` — строка, по которой выполняется поиск. [Строка](../syntax.md#syntax-string-literal). - `needle` — подстрока, которую необходимо найти. [Строка](../syntax.md#syntax-string-literal). +- `start_pos` – Опциональный параметр, позиция символа в строке, с которого начинается поиск. [UInt](../../sql-reference/data-types/int-uint.md) **Возвращаемые значения** @@ -75,13 +76,14 @@ SELECT position('Привет, мир!', '!') **Синтаксис** ``` sql -positionCaseInsensitive(haystack, needle) +positionCaseInsensitive(haystack, needle[, start_pos]) ``` **Параметры** - `haystack` — строка, по которой выполняется поиск. [Строка](../syntax.md#syntax-string-literal). - `needle` — подстрока, которую необходимо найти. [Строка](../syntax.md#syntax-string-literal). +- `start_pos` – Опциональный параметр, позиция символа в строке, с которого начинается поиск. [UInt](../../sql-reference/data-types/int-uint.md) **Возвращаемые значения** @@ -117,13 +119,14 @@ SELECT positionCaseInsensitive('Hello, world!', 'hello') **Синтаксис** ``` sql -positionUTF8(haystack, needle) +positionUTF8(haystack, needle[, start_pos]) ``` **Параметры** - `haystack` — строка, по которой выполняется поиск. [Строка](../syntax.md#syntax-string-literal). - `needle` — подстрока, которую необходимо найти. [Строка](../syntax.md#syntax-string-literal). +- `start_pos` – Опциональный параметр, позиция символа в строке, с которого начинается поиск. [UInt](../../sql-reference/data-types/int-uint.md) **Возвращаемые значения** @@ -189,13 +192,14 @@ SELECT positionUTF8('Salut, étudiante!', '!') **Синтаксис** ``` sql -positionCaseInsensitiveUTF8(haystack, needle) +positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) ``` **Параметры** - `haystack` — строка, по которой выполняется поиск. [Строка](../syntax.md#syntax-string-literal). - `needle` — подстрока, которую необходимо найти. [Строка](../syntax.md#syntax-string-literal). +- `start_pos` – Опциональный параметр, позиция символа в строке, с которого начинается поиск. [UInt](../../sql-reference/data-types/int-uint.md) **Возвращаемые значения** diff --git a/docs/tr/sql-reference/functions/string-search-functions.md b/docs/tr/sql-reference/functions/string-search-functions.md index be30510ef2a..b80df910972 100644 --- a/docs/tr/sql-reference/functions/string-search-functions.md +++ b/docs/tr/sql-reference/functions/string-search-functions.md @@ -20,15 +20,16 @@ Büyük / küçük harf duyarsız arama için işlevi kullanın [positionCaseİn **Sözdizimi** ``` sql -position(haystack, needle) +position(haystack, needle[, start_pos]) ``` -Takma ad: `locate(haystack, needle)`. +Takma ad: `locate(haystack, needle[, start_pos])`. **Parametre** - `haystack` — string, in which substring will to be searched. [Dize](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Dize](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Döndürülen değerler** @@ -80,13 +81,14 @@ Dize, tek baytlık kodlanmış bir metni temsil eden bir bayt kümesi içerdiği **Sözdizimi** ``` sql -positionCaseInsensitive(haystack, needle) +positionCaseInsensitive(haystack, needle[, start_pos]) ``` **Parametre** - `haystack` — string, in which substring will to be searched. [Dize](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Dize](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Döndürülen değerler** @@ -122,13 +124,14 @@ Büyük / küçük harf duyarsız arama için işlevi kullanın [positionCaseİn **Sözdizimi** ``` sql -positionUTF8(haystack, needle) +positionUTF8(haystack, needle[, start_pos]) ``` **Parametre** - `haystack` — string, in which substring will to be searched. [Dize](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Dize](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Döndürülen değerler** @@ -194,13 +197,14 @@ Dizenin UTF-8 kodlanmış bir metni temsil eden bir bayt kümesi içerdiği vars **Sözdizimi** ``` sql -positionCaseInsensitiveUTF8(haystack, needle) +positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) ``` **Parametre** - `haystack` — string, in which substring will to be searched. [Dize](../syntax.md#syntax-string-literal). - `needle` — substring to be searched. [Dize](../syntax.md#syntax-string-literal). +- `start_pos` – Optional parameter, position of the first character in the string to start search. [UInt](../../sql-reference/data-types/int-uint.md) **Döndürülen değer** diff --git a/tests/queries/0_stateless/00233_position_function_family.reference b/tests/queries/0_stateless/00233_position_function_family.reference index e1b22676c5e..1523094261f 100644 --- a/tests/queries/0_stateless/00233_position_function_family.reference +++ b/tests/queries/0_stateless/00233_position_function_family.reference @@ -23754,3 +23754,45 @@ 1 1 1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 diff --git a/tests/queries/0_stateless/00233_position_function_family.sql b/tests/queries/0_stateless/00233_position_function_family.sql index 94f25e16e83..8e443f5cd10 100644 --- a/tests/queries/0_stateless/00233_position_function_family.sql +++ b/tests/queries/0_stateless/00233_position_function_family.sql @@ -163,6 +163,10 @@ select 1 = positionCaseInsensitive(materialize('abc'), 'aBc') from system.number select 2 = positionCaseInsensitive(materialize('abc'), 'Bc') from system.numbers limit 10; select 3 = positionCaseInsensitive(materialize('abc'), 'C') from system.numbers limit 10; +select 6 = positionCaseInsensitive(materialize('abcabc'), 'C', 4); +select 6 = positionCaseInsensitive(materialize('abcabc'), 'C', 4) from system.numbers limit 10; +select 6 = positionCaseInsensitive(materialize('abcabc'), 'C', materialize(4)) from system.numbers limit 10; + select 1 = positionCaseInsensitive('', ''); select 1 = positionCaseInsensitive('абв', ''); select 0 = positionCaseInsensitive('', 'аБв'); @@ -205,6 +209,10 @@ select 1 = positionCaseInsensitiveUTF8(materialize('абв'), 'аБв') from sys select 2 = positionCaseInsensitiveUTF8(materialize('абв'), 'Бв') from system.numbers limit 10; select 3 = positionCaseInsensitiveUTF8(materialize('абв'), 'В') from system.numbers limit 10; +select 6 = positionCaseInsensitiveUTF8(materialize('абвабв'), 'В', 4); +select 6 = positionCaseInsensitiveUTF8(materialize('абвабв'), 'В', 4) from system.numbers limit 10; +select 6 = positionCaseInsensitiveUTF8(materialize('абвабв'), 'В', materialize(4)) from system.numbers limit 10; + select position('' as h, '' as n) = positionCaseInsensitive(h, n); select position('abc' as h, '' as n) = positionCaseInsensitive(n, n); select 0 = positionCaseInsensitive('', 'aBc');