From c1da5dc37acbdecfd0df49732df3ddf5cd0032ce Mon Sep 17 00:00:00 2001 From: ana-uvarova Date: Mon, 22 Mar 2021 19:30:28 +0300 Subject: [PATCH] new examples --- .../functions/string-search-functions.md | 33 +++++++++++++++++-- .../functions/string-search-functions.md | 28 ++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/docs/en/sql-reference/functions/string-search-functions.md b/docs/en/sql-reference/functions/string-search-functions.md index 79dc2eace08..f757c47a012 100644 --- a/docs/en/sql-reference/functions/string-search-functions.md +++ b/docs/en/sql-reference/functions/string-search-functions.md @@ -12,6 +12,8 @@ The search is case-sensitive by default in all these functions. There are separa ## position(haystack, needle), locate(haystack, needle) {#position} +Searchs the substring `needle` in the string `haystack`. + Returns the position (in bytes) of the found substring in the string, starting from 1. For a case-insensitive search, use the function [positionCaseInsensitive](#positioncaseinsensitive). @@ -25,14 +27,13 @@ position((haystack, needle[, start_pos]) | (needle IN haystack)) Alias: `locate(haystack, needle[, start_pos])`. !!! note "Note" - Now it supports position(needle IN haystack) syntax for SQL-compatibility, which is same as position(haystack, needle). This new function POSITION(needle IN haystack) works exactly the same way as POSITION(haystack, needle). + Syntax of position(needle IN haystack) provides SQL-compatibility and works the same way as position(haystack, needle). **Arguments** - `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). -- `needle in haystack` — additional parameter **Returned values** @@ -87,6 +88,34 @@ Result: └───────────────────────────────┘ ``` +Query: + +```sql +select 3 = position('c' in 'abc'); +``` + +Result: + +```text +┌─equals(3, position('abc', 'c'))─┐ +│ 1 │ +└─────────────────────────────────┘ +``` + +Query: + +```sql +SELECT 6 = position('/' IN s) FROM (SELECT 'Hello/World' AS s); +``` + +Result: + +```text +┌─equals(6, position(s, '/'))─┐ +│ 1 │ +└─────────────────────────────┘ +``` + ## positionCaseInsensitive {#positioncaseinsensitive} The same as [position](#position) returns the position (in bytes) of the found substring in the string, starting from 1. Use the function for a case-insensitive search. diff --git a/docs/ru/sql-reference/functions/string-search-functions.md b/docs/ru/sql-reference/functions/string-search-functions.md index bf68a957e5a..a1dd67084e2 100644 --- a/docs/ru/sql-reference/functions/string-search-functions.md +++ b/docs/ru/sql-reference/functions/string-search-functions.md @@ -73,6 +73,34 @@ SELECT position('Привет, мир!', '!') └───────────────────────────────┘ ``` +Запрос: + +```sql +SELECT 1 = position('абв' in 'абв'); +``` + +Ответ: + +```text +┌─equals(1, position('абв', 'абв'))─┐ +│ 1 │ +└───────────────────────────────────┘ +``` + +Запрос: + +```sql +select 0 = position('абв' in ''); +``` + +Ответ: + +```text +┌─equals(0, position('', 'абв'))─┐ +│ 1 │ +└────────────────────────────────┘ +``` + ## positionCaseInsensitive {#positioncaseinsensitive} Такая же, как и [position](#position), но работает без учета регистра. Возвращает позицию в байтах найденной подстроки в строке, начиная с 1.