Add start_pos argument for position to documentation, case insensitive tests

This commit is contained in:
vdimir 2020-08-02 13:29:10 +00:00
parent 9ed7df64cd
commit 32f26bcde7
8 changed files with 116 additions and 30 deletions

View File

@ -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 cant 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**

View File

@ -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**

View File

@ -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)
**مقدار بازگشتی**

View File

@ -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)
**戻り値**

View File

@ -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)
**Возвращаемые значения**

View File

@ -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**

View File

@ -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

View File

@ -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');