Add convenience alias byteSlice for substring

This commit is contained in:
Robert Schulze 2024-02-28 13:32:56 +00:00
parent fe50b5871b
commit e02c083e60
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
5 changed files with 13 additions and 2 deletions

View File

@ -167,6 +167,10 @@ Result:
└──────────────────────────────────────────┴───────────────────────────────┘
```
## byteSlice(s, offset, length)
See function [substring](string-functions.md#substring).
## bitTest
Takes any integer and converts it into [binary form](https://en.wikipedia.org/wiki/Binary_number), returns the value of a bit at specified position. The countdown starts from 0 from the right to the left.

View File

@ -558,6 +558,7 @@ substring(s, offset[, length])
Alias:
- `substr`
- `mid`
- `byteSlice`
**Arguments**

View File

@ -189,6 +189,7 @@ REGISTER_FUNCTION(Substring)
factory.registerFunction<FunctionSubstring<false>>({}, FunctionFactory::CaseInsensitive);
factory.registerAlias("substr", "substring", FunctionFactory::CaseInsensitive); // MySQL alias
factory.registerAlias("mid", "substring", FunctionFactory::CaseInsensitive); /// MySQL alias
factory.registerAlias("byteSlice", "substring", FunctionFactory::CaseInsensitive); /// resembles PostgreSQL's get_byte function, similar to ClickHouse's bitSlice
factory.registerFunction<FunctionSubstring<true>>({}, FunctionFactory::CaseSensitive);
}

View File

@ -170,4 +170,6 @@ g
UBSAN bug
-- UBSAN bug
-- Alias
el

View File

@ -132,7 +132,7 @@ SELECT substring(s, l, r) FROM t;
DROP table if exists t;
SELECT 'UBSAN bug';
SELECT '-- UBSAN bug';l
/** NOTE: The behaviour of substring and substringUTF8 is inconsistent when negative offset is greater than string size:
* substring:
@ -144,3 +144,6 @@ SELECT 'UBSAN bug';
* This may be subject for change.
*/
SELECT substringUTF8('hello, пÑ<C2BF>ивеÑ<C2B5>', -9223372036854775808, number) FROM numbers(16) FORMAT Null;
SELECT '-- Alias';
SELECT byteSlice('hello', 2, 2);