String functions - Amazon OpenSearch Service

String functions

Note

To see which AWS data source integrations support this SQL command, see Supported OpenSearch SQL commands and functions.

Function Description
ascii(str) Returns the numeric value of the first character of str.
base64(bin) Converts the argument from a binary bin to a base 64 string.
bit_length(expr) Returns the bit length of string data or number of bits of binary data.
btrim(str) Removes the leading and trailing space characters from str.
btrim(str, trimStr) Remove the leading and trailing trimStr characters from str.
char(expr) Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256)
char_length(expr) Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.
character_length(expr) Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.
chr(expr) Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256)
concat_ws(sep[, str | array(str)]+) Returns the concatenation of the strings separated by sep, skipping null values.
contains(left, right) Returns a boolean. The value is True if right is found inside left. Returns NULL if either input expression is NULL. Otherwise, returns False. Both left or right must be of STRING or BINARY type.
decode(bin, charset) Decodes the first argument using the second argument character set.
decode(expr, search, result [, search, result ] ... [, default]) Compares expr to each search value in order. If expr is equal to a search value, decode returns the corresponding result. If no match is found, then it returns default. If default is omitted, it returns null.
elt(n, input1, input2, ...) Returns the n-th input, e.g., returns input2 when n is 2.
encode(str, charset) Encodes the first argument using the second argument character set.
endswith(left, right) Returns a boolean. The value is True if left ends with right. Returns NULL if either input expression is NULL. Otherwise, returns False. Both left or right must be of STRING or BINARY type.
find_in_set(str, str_array) Returns the index (1-based) of the given string (str) in the comma-delimited list (str_array). Returns 0, if the string was not found or if the given string (str) contains a comma.
format_number(expr1, expr2) Formats the number expr1 like '#,###,###.##', rounded to expr2 decimal places. If expr2 is 0, the result has no decimal point or fractional part. expr2 also accept a user specified format. This is supposed to function like MySQL's FORMAT.
format_string(strfmt, obj, ...) Returns a formatted string from printf-style format strings.
initcap(str) Returns str with the first letter of each word in uppercase. All other letters are in lowercase. Words are delimited by white space.
instr(str, substr) Returns the (1-based) index of the first occurrence of substr in str.
lcase(str) Returns str with all characters changed to lowercase.
left(str, len) Returns the leftmost len(len can be string type) characters from the string str,if len is less or equal than 0 the result is an empty string.
len(expr) Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.
length(expr) Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.
levenshtein(str1, str2[, threshold]) Returns the Levenshtein distance between the two given strings. If threshold is set and distance more than it, return -1.
locate(substr, str[, pos]) Returns the position of the first occurrence of substr in str after position pos. The given pos and return value are 1-based.
lower(str) Returns str with all characters changed to lowercase.
lpad(str, len[, pad]) Returns str, left-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters or bytes. If pad is not specified, str will be padded to the left with space characters if it is a character string, and with zeros if it is a byte sequence.
ltrim(str) Removes the leading space characters from str.
luhn_check(str ) Checks that a string of digits is valid according to the Luhn algorithm. This checksum function is widely applied on credit card numbers and government identification numbers to distinguish valid numbers from mistyped, incorrect numbers.
mask(input[, upperChar, lowerChar, digitChar, otherChar]) masks the given string value. The function replaces characters with 'X' or 'x', and numbers with 'n'. This can be useful for creating copies of tables with sensitive information removed.
octet_length(expr) Returns the byte length of string data or number of bytes of binary data.
overlay(input, replace, pos[, len]) Replace input with replace that starts at pos and is of length len.
position(substr, str[, pos]) Returns the position of the first occurrence of substr in str after position pos. The given pos and return value are 1-based.
printf(strfmt, obj, ...) Returns a formatted string from printf-style format strings.
regexp_count(str, regexp) Returns a count of the number of times that the regular expression pattern regexp is matched in the string str.
regexp_extract(str, regexp[, idx]) Extract the first string in the str that match the regexp expression and corresponding to the regex group index.
regexp_extract_all(str, regexp[, idx]) Extract all strings in the str that match the regexp expression and corresponding to the regex group index.
regexp_instr(str, regexp) Searches a string for a regular expression and returns an integer that indicates the beginning position of the matched substring. Positions are 1-based, not 0-based. If no match is found, returns 0.
regexp_replace(str, regexp, rep[, position]) Replaces all substrings of str that match regexp with rep.
regexp_substr(str, regexp) Returns the substring that matches the regular expression regexp within the string str. If the regular expression is not found, the result is null.
repeat(str, n) Returns the string which repeats the given string value n times.
replace(str, search[, replace]) Replaces all occurrences of search with replace.
right(str, len) Returns the rightmost len(len can be string type) characters from the string str,if len is less or equal than 0 the result is an empty string.
rpad(str, len[, pad]) Returns str, right-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters. If pad is not specified, str will be padded to the right with space characters if it is a character string, and with zeros if it is a binary string.
rtrim(str) Removes the trailing space characters from str.
sentences(str[, lang, country]) Splits str into an array of array of words.
soundex(str) Returns Soundex code of the string.
space(n) Returns a string consisting of n spaces.
split(str, regex, limit) Splits str around occurrences that match regex and returns an array with a length of at most limit
split_part(str, delimiter, partNum) Splits str by delimiter and return requested part of the split (1-based). If any input is null, returns null. if partNum is out of range of split parts, returns empty string. If partNum is 0, throws an error. If partNum is negative, the parts are counted backward from the end of the string. If the delimiter is an empty string, the str is not split.
startswith(left, right) Returns a boolean. The value is True if left starts with right. Returns NULL if either input expression is NULL. Otherwise, returns False. Both left or right must be of STRING or BINARY type.
substr(str, pos[, len]) Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.
substr(str FROM pos[ FOR len]]) Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.
substring(str, pos[, len]) Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.
substring(str FROM pos[ FOR len]]) Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.
substring_index(str, delim, count) Returns the substring from str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. The function substring_index performs a case-sensitive match when searching for delim.
to_binary(str[, fmt]) Converts the input str to a binary value based on the supplied fmt. fmt can be a case-insensitive string literal of "hex", "utf-8", "utf8", or "base64". By default, the binary format for conversion is "hex" if fmt is omitted. The function returns NULL if at least one of the input parameters is NULL.
to_char(numberExpr, formatExpr) Convert numberExpr to a string based on the formatExpr. Throws an exception if the conversion fails. The format can consist of the following characters, case insensitive: '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format string matches a sequence of digits in the input value, generating a result string of the same length as the corresponding sequence in the format string. The result string is left-padded with zeros if the 0/9 sequence comprises more digits than the matching part of the decimal value, starts with 0, and is before the decimal point. Otherwise, it is padded with spaces. '.' or 'D': Specifies the position of the decimal point (optional, only allowed once). ',' or 'G': Specifies the position of the grouping (thousands) separator (,). There must be a 0 or 9 to the left and right of each grouping separator. '
to_number(expr, fmt) Convert string 'expr' to a number based on the string format 'fmt'. Throws an exception if the conversion fails. The format can consist of the following characters, case insensitive: '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format string matches a sequence of digits in the input string. If the 0/9 sequence starts with 0 and is before the decimal point, it can only match a digit sequence of the same size. Otherwise, if the sequence starts with 9 or is after the decimal point, it can match a digit sequence that has the same or smaller size. '.' or 'D': Specifies the position of the decimal point (optional, only allowed once). ',' or 'G': Specifies the position of the grouping (thousands) separator (,). There must be a 0 or 9 to the left and right of each grouping separator. 'expr' must match the grouping separator relevant for the size of the number. '
to_varchar(numberExpr, formatExpr) Convert numberExpr to a string based on the formatExpr. Throws an exception if the conversion fails. The format can consist of the following characters, case insensitive: '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format string matches a sequence of digits in the input value, generating a result string of the same length as the corresponding sequence in the format string. The result string is left-padded with zeros if the 0/9 sequence comprises more digits than the matching part of the decimal value, starts with 0, and is before the decimal point. Otherwise, it is padded with spaces. '.' or 'D': Specifies the position of the decimal point (optional, only allowed once). ',' or 'G': Specifies the position of the grouping (thousands) separator (,). There must be a 0 or 9 to the left and right of each grouping separator. '
translate(input, from, to) Translates the input string by replacing the characters present in the from string with the corresponding characters in the to string.
trim(str) Removes the leading and trailing space characters from str.
trim(BOTH FROM str) Removes the leading and trailing space characters from str.
trim(LEADING FROM str) Removes the leading space characters from str.
trim(TRAILING FROM str) Removes the trailing space characters from str.
trim(trimStr FROM str) Remove the leading and trailing trimStr characters from str.
trim(BOTH trimStr FROM str) Remove the leading and trailing trimStr characters from str.
trim(LEADING trimStr FROM str) Remove the leading trimStr characters from str.
trim(TRAILING trimStr FROM str) Remove the trailing trimStr characters from str.
try_to_binary(str[, fmt]) This is a special version of to_binary that performs the same operation, but returns a NULL value instead of raising an error if the conversion cannot be performed.
try_to_number(expr, fmt) Convert string 'expr' to a number based on the string format fmt. Returns NULL if the string 'expr' does not match the expected format. The format follows the same semantics as the to_number function.
ucase(str) Returns str with all characters changed to uppercase.
unbase64(str) Converts the argument from a base 64 string str to a binary.
upper(str) Returns str with all characters changed to uppercase.

Examples

-- ascii SELECT ascii('222'); +----------+ |ascii(222)| +----------+ | 50| +----------+ SELECT ascii(2); +--------+ |ascii(2)| +--------+ | 50| +--------+ -- base64 SELECT base64('Feathers'); +-----------------+ |base64(Feathers)| +-----------------+ | RmVhdGhlcnM=| +-----------------+ SELECT base64(x'537061726b2053514c'); +-----------------------------+ |base64(X'537061726B2053514C')| +-----------------------------+ | U3BhcmsgU1FM| +-----------------------------+ -- bit_length SELECT bit_length('Feathers'); +---------------------+ |bit_length(Feathers)| +---------------------+ | 64| +---------------------+ SELECT bit_length(x'537061726b2053514c'); +---------------------------------+ |bit_length(X'537061726B2053514C')| +---------------------------------+ | 72| +---------------------------------+ -- btrim SELECT btrim(' Feathers '); +----------------------+ |btrim( Feathers )| +----------------------+ | Feathers| +----------------------+ SELECT btrim(encode(' Feathers ', 'utf-8')); +-------------------------------------+ |btrim(encode( Feathers , utf-8))| +-------------------------------------+ | Feathers| +-------------------------------------+ SELECT btrim('Feathers', 'Fe'); +---------------------+ |btrim(Alphabet, Al)| +---------------------+ | athers| +---------------------+ SELECT btrim(encode('Feathers', 'utf-8'), encode('Al', 'utf-8')); +---------------------------------------------------+ |btrim(encode(Feathers, utf-8), encode(Al, utf-8))| +---------------------------------------------------+ | athers| +---------------------------------------------------+ -- char SELECT char(65); +--------+ |char(65)| +--------+ | A| +--------+ -- char_length SELECT char_length('Feathers '); +-----------------------+ |char_length(Feathers )| +-----------------------+ | 9 | +-----------------------+ SELECT char_length(x'537061726b2053514c'); +----------------------------------+ |char_length(X'537061726B2053514C')| +----------------------------------+ | 9| +----------------------------------+ SELECT CHAR_LENGTH('Feathers '); +-----------------------+ |char_length(Feathers )| +-----------------------+ | 9| +-----------------------+ SELECT CHARACTER_LENGTH('Feathers '); +----------------------------+ |character_length(Feathers )| +----------------------------+ | 9| +----------------------------+ -- character_length SELECT character_length('Feathers '); +----------------------------+ |character_length(Feathers )| +----------------------------+ | 9| +----------------------------+ SELECT character_length(x'537061726b2053514c'); +---------------------------------------+ |character_length(X'537061726B2053514C')| +---------------------------------------+ | 9| +---------------------------------------+ SELECT CHAR_LENGTH('Feathers '); +-----------------------+ |char_length(Feathers )| +-----------------------+ | 9| +-----------------------+ SELECT CHARACTER_LENGTH('Feathers '); +----------------------------+ |character_length(Feathers )| +----------------------------+ | 9| +----------------------------+ -- chr SELECT chr(65); +-------+ |chr(65)| +-------+ | A| +-------+ -- concat_ws SELECT concat_ws(' ', 'Fea', 'thers'); +------------------------+ |concat_ws( , Fea, thers)| +------------------------+ | Feathers| +------------------------+ SELECT concat_ws('s'); +------------+ |concat_ws(s)| +------------+ | | +------------+ SELECT concat_ws('/', 'foo', null, 'bar'); +----------------------------+ |concat_ws(/, foo, NULL, bar)| +----------------------------+ | foo/bar| +----------------------------+ SELECT concat_ws(null, 'Fea', 'thers'); +---------------------------+ |concat_ws(NULL, Fea, thers)| +---------------------------+ | NULL| +---------------------------+ -- contains SELECT contains('Feathers', 'Fea'); +--------------------------+ |contains(Feathers, Fea)| +--------------------------+ | true| +--------------------------+ SELECT contains('Feathers', 'SQL'); +--------------------------+ |contains(Feathers, SQL)| +--------------------------+ | false| +--------------------------+ SELECT contains('Feathers', null); +-------------------------+ |contains(Feathers, NULL)| +-------------------------+ | NULL| +-------------------------+ SELECT contains(x'537061726b2053514c', x'537061726b'); +----------------------------------------------+ |contains(X'537061726B2053514C', X'537061726B')| +----------------------------------------------+ | true| +----------------------------------------------+ -- decode SELECT decode(encode('abc', 'utf-8'), 'utf-8'); +---------------------------------+ |decode(encode(abc, utf-8), utf-8)| +---------------------------------+ | abc| +---------------------------------+ SELECT decode(2, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic'); +----------------------------------------------------------------------------------+ |decode(2, 1, Southlake, 2, San Francisco, 3, New Jersey, 4, Seattle, Non domestic)| +----------------------------------------------------------------------------------+ | San Francisco| +----------------------------------------------------------------------------------+ SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic'); +----------------------------------------------------------------------------------+ |decode(6, 1, Southlake, 2, San Francisco, 3, New Jersey, 4, Seattle, Non domestic)| +----------------------------------------------------------------------------------+ | Non domestic| +----------------------------------------------------------------------------------+ SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle'); +--------------------------------------------------------------------+ |decode(6, 1, Southlake, 2, San Francisco, 3, New Jersey, 4, Seattle)| +--------------------------------------------------------------------+ | NULL| +--------------------------------------------------------------------+ SELECT decode(null, 6, 'Fea', NULL, 'thers', 4, 'rock'); +-------------------------------------------+ |decode(NULL, 6, Fea, NULL, thers, 4, rock)| +-------------------------------------------+ | thers| +-------------------------------------------+ -- elt SELECT elt(1, 'scala', 'java'); +-------------------+ |elt(1, scala, java)| +-------------------+ | scala| +-------------------+ SELECT elt(2, 'a', 1); +------------+ |elt(2, a, 1)| +------------+ | 1| +------------+ -- encode SELECT encode('abc', 'utf-8'); +------------------+ |encode(abc, utf-8)| +------------------+ | [61 62 63]| +------------------+ -- endswith SELECT endswith('Feathers', 'ers'); +------------------------+ |endswith(Feathers, ers)| +------------------------+ | true| +------------------------+ SELECT endswith('Feathers', 'SQL'); +--------------------------+ |endswith(Feathers, SQL)| +--------------------------+ | false| +--------------------------+ SELECT endswith('Feathers', null); +-------------------------+ |endswith(Feathers, NULL)| +-------------------------+ | NULL| +-------------------------+ SELECT endswith(x'537061726b2053514c', x'537061726b'); +----------------------------------------------+ |endswith(X'537061726B2053514C', X'537061726B')| +----------------------------------------------+ | false| +----------------------------------------------+ SELECT endswith(x'537061726b2053514c', x'53514c'); +------------------------------------------+ |endswith(X'537061726B2053514C', X'53514C')| +------------------------------------------+ | true| +------------------------------------------+ -- find_in_set SELECT find_in_set('ab','abc,b,ab,c,def'); +-------------------------------+ |find_in_set(ab, abc,b,ab,c,def)| +-------------------------------+ | 3| +-------------------------------+ -- format_number SELECT format_number(12332.123456, 4); +------------------------------+ |format_number(12332.123456, 4)| +------------------------------+ | 12,332.1235| +------------------------------+ SELECT format_number(12332.123456, '##################.###'); +---------------------------------------------------+ |format_number(12332.123456, ##################.###)| +---------------------------------------------------+ | 12332.123| +---------------------------------------------------+ -- format_string SELECT format_string("Hello World %d %s", 100, "days"); +-------------------------------------------+ |format_string(Hello World %d %s, 100, days)| +-------------------------------------------+ | Hello World 100 days| +-------------------------------------------+ -- initcap SELECT initcap('Feathers'); +------------------+ |initcap(Feathers)| +------------------+ | Feathers| +------------------+ -- instr SELECT instr('Feathers', 'ers'); +--------------------+ |instr(Feathers, ers)| +--------------------+ | 6| +--------------------+ -- lcase SELECT lcase('Feathers'); +---------------+ |lcase(Feathers)| +---------------+ | feathers| +---------------+ -- left SELECT left('Feathers', 3); +------------------+ |left(Feathers, 3)| +------------------+ | Fea| +------------------+ SELECT left(encode('Feathers', 'utf-8'), 3); +---------------------------------+ |left(encode(Feathers, utf-8), 3)| +---------------------------------+ | [RmVh]| +---------------------------------+ -- len SELECT len('Feathers '); +---------------+ |len(Feathers )| +---------------+ | 9| +---------------+ SELECT len(x'537061726b2053514c'); +--------------------------+ |len(X'537061726B2053514C')| +--------------------------+ | 9| +--------------------------+ SELECT CHAR_LENGTH('Feathers '); +-----------------------+ |char_length(Feathers )| +-----------------------+ | 9| +-----------------------+ SELECT CHARACTER_LENGTH('Feathers '); +----------------------------+ |character_length(Feathers )| +----------------------------+ | 9| +----------------------------+ -- length SELECT length('Feathers '); +------------------+ |length(Feathers )| +------------------+ | 9| +------------------+ SELECT length(x'537061726b2053514c'); +-----------------------------+ |length(X'537061726B2053514C')| +-----------------------------+ | 9| +-----------------------------+ SELECT CHAR_LENGTH('Feathers '); +-----------------------+ |char_length(Feathers )| +-----------------------+ | 9| +-----------------------+ SELECT CHARACTER_LENGTH('Feathers '); +----------------------------+ |character_length(Feathers )| +----------------------------+ | 9| +----------------------------+ -- levenshtein SELECT levenshtein('kitten', 'sitting'); +----------------------------+ |levenshtein(kitten, sitting)| +----------------------------+ | 3| +----------------------------+ SELECT levenshtein('kitten', 'sitting', 2); +-------------------------------+ |levenshtein(kitten, sitting, 2)| +-------------------------------+ | -1| +-------------------------------+ -- locate SELECT locate('bar', 'foobarbar'); +-------------------------+ |locate(bar, foobarbar, 1)| +-------------------------+ | 4| +-------------------------+ SELECT locate('bar', 'foobarbar', 5); +-------------------------+ |locate(bar, foobarbar, 5)| +-------------------------+ | 7| +-------------------------+ SELECT POSITION('bar' IN 'foobarbar'); +-------------------------+ |locate(bar, foobarbar, 1)| +-------------------------+ | 4| +-------------------------+ -- lower SELECT lower('Feathers'); +---------------+ |lower(Feathers)| +---------------+ | feathers| +---------------+ -- lpad SELECT lpad('hi', 5, '??'); +---------------+ |lpad(hi, 5, ??)| +---------------+ | ???hi| +---------------+ SELECT lpad('hi', 1, '??'); +---------------+ |lpad(hi, 1, ??)| +---------------+ | h| +---------------+ SELECT lpad('hi', 5); +--------------+ |lpad(hi, 5, )| +--------------+ | hi| +--------------+ SELECT hex(lpad(unhex('aabb'), 5)); +--------------------------------+ |hex(lpad(unhex(aabb), 5, X'00'))| +--------------------------------+ | 000000AABB| +--------------------------------+ SELECT hex(lpad(unhex('aabb'), 5, unhex('1122'))); +--------------------------------------+ |hex(lpad(unhex(aabb), 5, unhex(1122)))| +--------------------------------------+ | 112211AABB| +--------------------------------------+ -- ltrim SELECT ltrim(' Feathers '); +----------------------+ |ltrim( Feathers )| +----------------------+ | Feathers | +----------------------+ -- luhn_check SELECT luhn_check('8112189876'); +----------------------+ |luhn_check(8112189876)| +----------------------+ | true| +----------------------+ SELECT luhn_check('79927398713'); +-----------------------+ |luhn_check(79927398713)| +-----------------------+ | true| +-----------------------+ SELECT luhn_check('79927398714'); +-----------------------+ |luhn_check(79927398714)| +-----------------------+ | false| +-----------------------+ -- mask SELECT mask('abcd-EFGH-8765-4321'); +----------------------------------------+ |mask(abcd-EFGH-8765-4321, X, x, n, NULL)| +----------------------------------------+ | xxxx-XXXX-nnnn-nnnn| +----------------------------------------+ SELECT mask('abcd-EFGH-8765-4321', 'Q'); +----------------------------------------+ |mask(abcd-EFGH-8765-4321, Q, x, n, NULL)| +----------------------------------------+ | xxxx-QQQQ-nnnn-nnnn| +----------------------------------------+ SELECT mask('AbCD123-@$#', 'Q', 'q'); +--------------------------------+ |mask(AbCD123-@$#, Q, q, n, NULL)| +--------------------------------+ | QqQQnnn-@$#| +--------------------------------+ SELECT mask('AbCD123-@$#'); +--------------------------------+ |mask(AbCD123-@$#, X, x, n, NULL)| +--------------------------------+ | XxXXnnn-@$#| +--------------------------------+ SELECT mask('AbCD123-@$#', 'Q'); +--------------------------------+ |mask(AbCD123-@$#, Q, x, n, NULL)| +--------------------------------+ | QxQQnnn-@$#| +--------------------------------+ SELECT mask('AbCD123-@$#', 'Q', 'q'); +--------------------------------+ |mask(AbCD123-@$#, Q, q, n, NULL)| +--------------------------------+ | QqQQnnn-@$#| +--------------------------------+ SELECT mask('AbCD123-@$#', 'Q', 'q', 'd'); +--------------------------------+ |mask(AbCD123-@$#, Q, q, d, NULL)| +--------------------------------+ | QqQQddd-@$#| +--------------------------------+ SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o'); +-----------------------------+ |mask(AbCD123-@$#, Q, q, d, o)| +-----------------------------+ | QqQQdddoooo| +-----------------------------+ SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o'); +--------------------------------+ |mask(AbCD123-@$#, NULL, q, d, o)| +--------------------------------+ | AqCDdddoooo| +--------------------------------+ SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o'); +-----------------------------------+ |mask(AbCD123-@$#, NULL, NULL, d, o)| +-----------------------------------+ | AbCDdddoooo| +-----------------------------------+ SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o'); +--------------------------------------+ |mask(AbCD123-@$#, NULL, NULL, NULL, o)| +--------------------------------------+ | AbCD123oooo| +--------------------------------------+ SELECT mask(NULL, NULL, NULL, NULL, 'o'); +-------------------------------+ |mask(NULL, NULL, NULL, NULL, o)| +-------------------------------+ | NULL| +-------------------------------+ SELECT mask(NULL); +-------------------------+ |mask(NULL, X, x, n, NULL)| +-------------------------+ | NULL| +-------------------------+ SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL); +-----------------------------------------+ |mask(AbCD123-@$#, NULL, NULL, NULL, NULL)| +-----------------------------------------+ | AbCD123-@$#| +-----------------------------------------+ -- octet_length SELECT octet_length('Feathers'); +-----------------------+ |octet_length(Feathers)| +-----------------------+ | 8| +-----------------------+ SELECT octet_length(x'537061726b2053514c'); +-----------------------------------+ |octet_length(X'537061726B2053514C')| +-----------------------------------+ | 9| +-----------------------------------+ -- overlay SELECT overlay('Feathers' PLACING '_' FROM 6); +----------------------------+ |overlay(Feathers, _, 6, -1)| +----------------------------+ | Feathe_ers| +----------------------------+ SELECT overlay('Feathers' PLACING 'ures' FROM 5); +-------------------------------+ |overlay(Feathers, ures, 5, -1)| +-------------------------------+ | Features | +-------------------------------+ -- position SELECT position('bar', 'foobarbar'); +---------------------------+ |position(bar, foobarbar, 1)| +---------------------------+ | 4| +---------------------------+ SELECT position('bar', 'foobarbar', 5); +---------------------------+ |position(bar, foobarbar, 5)| +---------------------------+ | 7| +---------------------------+ SELECT POSITION('bar' IN 'foobarbar'); +-------------------------+ |locate(bar, foobarbar, 1)| +-------------------------+ | 4| +-------------------------+ -- printf SELECT printf("Hello World %d %s", 100, "days"); +------------------------------------+ |printf(Hello World %d %s, 100, days)| +------------------------------------+ | Hello World 100 days| +------------------------------------+ -- regexp_count SELECT regexp_count('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en'); +------------------------------------------------------------------------------+ |regexp_count(Steven Jones and Stephen Smith are the best players, Ste(v|ph)en)| +------------------------------------------------------------------------------+ | 2| +------------------------------------------------------------------------------+ SELECT regexp_count('abcdefghijklmnopqrstuvwxyz', '[a-z]{3}'); +--------------------------------------------------+ |regexp_count(abcdefghijklmnopqrstuvwxyz, [a-z]{3})| +--------------------------------------------------+ | 8| +--------------------------------------------------+ -- regexp_extract SELECT regexp_extract('100-200', '(\\d+)-(\\d+)', 1); +---------------------------------------+ |regexp_extract(100-200, (\d+)-(\d+), 1)| +---------------------------------------+ | 100| +---------------------------------------+ -- regexp_extract_all SELECT regexp_extract_all('100-200, 300-400', '(\\d+)-(\\d+)', 1); +----------------------------------------------------+ |regexp_extract_all(100-200, 300-400, (\d+)-(\d+), 1)| +----------------------------------------------------+ | [100, 300]| +----------------------------------------------------+ -- regexp_instr SELECT regexp_instr('user@opensearch.org', '@[^.]*'); +----------------------------------------------+ |regexp_instr(user@opensearch.org, @[^.]*, 0)| +----------------------------------------------+ | 5| +----------------------------------------------+ -- regexp_replace SELECT regexp_replace('100-200', '(\\d+)', 'num'); +--------------------------------------+ |regexp_replace(100-200, (\d+), num, 1)| +--------------------------------------+ | num-num| +--------------------------------------+ -- regexp_substr SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en'); +-------------------------------------------------------------------------------+ |regexp_substr(Steven Jones and Stephen Smith are the best players, Ste(v|ph)en)| +-------------------------------------------------------------------------------+ | Steven| +-------------------------------------------------------------------------------+ SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Jeck'); +------------------------------------------------------------------------+ |regexp_substr(Steven Jones and Stephen Smith are the best players, Jeck)| +------------------------------------------------------------------------+ | NULL| +------------------------------------------------------------------------+ -- repeat SELECT repeat('123', 2); +--------------+ |repeat(123, 2)| +--------------+ | 123123| +--------------+ -- replace SELECT replace('ABCabc', 'abc', 'DEF'); +-------------------------+ |replace(ABCabc, abc, DEF)| +-------------------------+ | ABCDEF| +-------------------------+ -- right SELECT right('Feathers', 3); +-------------------+ |right(Feathers, 3)| +-------------------+ | ers| +-------------------+ -- rpad SELECT rpad('hi', 5, '??'); +---------------+ |rpad(hi, 5, ??)| +---------------+ | hi???| +---------------+ SELECT rpad('hi', 1, '??'); +---------------+ |rpad(hi, 1, ??)| +---------------+ | h| +---------------+ SELECT rpad('hi', 5); +--------------+ |rpad(hi, 5, )| +--------------+ | hi | +--------------+ SELECT hex(rpad(unhex('aabb'), 5)); +--------------------------------+ |hex(rpad(unhex(aabb), 5, X'00'))| +--------------------------------+ | AABB000000| +--------------------------------+ SELECT hex(rpad(unhex('aabb'), 5, unhex('1122'))); +--------------------------------------+ |hex(rpad(unhex(aabb), 5, unhex(1122)))| +--------------------------------------+ | AABB112211| +--------------------------------------+ -- rtrim SELECT rtrim(' Feathers '); +----------------------+ |rtrim( Feathers )| +----------------------+ | Feathers| +----------------------+ -- sentences SELECT sentences('Hi there! Good morning.'); +--------------------------------------+ |sentences(Hi there! Good morning., , )| +--------------------------------------+ | [[Hi, there], [Go...| +--------------------------------------+ -- soundex SELECT soundex('Miller'); +---------------+ |soundex(Miller)| +---------------+ | M460| +---------------+ -- space SELECT concat(space(2), '1'); +-------------------+ |concat(space(2), 1)| +-------------------+ | 1| +-------------------+ -- split SELECT split('oneAtwoBthreeC', '[ABC]'); +--------------------------------+ |split(oneAtwoBthreeC, [ABC], -1)| +--------------------------------+ | [one, two, three, ]| +--------------------------------+ SELECT split('oneAtwoBthreeC', '[ABC]', -1); +--------------------------------+ |split(oneAtwoBthreeC, [ABC], -1)| +--------------------------------+ | [one, two, three, ]| +--------------------------------+ SELECT split('oneAtwoBthreeC', '[ABC]', 2); +-------------------------------+ |split(oneAtwoBthreeC, [ABC], 2)| +-------------------------------+ | [one, twoBthreeC]| +-------------------------------+ -- split_part SELECT split_part('11.12.13', '.', 3); +--------------------------+ |split_part(11.12.13, ., 3)| +--------------------------+ | 13| +--------------------------+ -- startswith SELECT startswith('Feathers', 'Fea'); +----------------------------+ |startswith(Feathers, Fea)| +----------------------------+ | true| +----------------------------+ SELECT startswith('Feathers', 'SQL'); +--------------------------+ |startswith(Feathers, SQL)| +--------------------------+ | false| +--------------------------+ SELECT startswith('Feathers', null); +---------------------------+ |startswith(Feathers, NULL)| +---------------------------+ | NULL| +---------------------------+ SELECT startswith(x'537061726b2053514c', x'537061726b'); +------------------------------------------------+ |startswith(X'537061726B2053514C', X'537061726B')| +------------------------------------------------+ | true| +------------------------------------------------+ SELECT startswith(x'537061726b2053514c', x'53514c'); +--------------------------------------------+ |startswith(X'537061726B2053514C', X'53514C')| +--------------------------------------------+ | false| +--------------------------------------------+ -- substr SELECT substr('Feathers', 5); +--------------------------------+ |substr(Feathers, 5, 2147483647)| +--------------------------------+ | hers | +--------------------------------+ SELECT substr('Feathers', -3); +---------------------------------+ |substr(Feathers, -3, 2147483647)| +---------------------------------+ | ers| +---------------------------------+ SELECT substr('Feathers', 5, 1); +-----------------------+ |substr(Feathers, 5, 1)| +-----------------------+ | h| +-----------------------+ SELECT substr('Feathers' FROM 5); +-----------------------------------+ |substring(Feathers, 5, 2147483647)| +-----------------------------------+ | hers | +-----------------------------------+ SELECT substr('Feathers' FROM -3); +------------------------------------+ |substring(Feathers, -3, 2147483647)| +------------------------------------+ | ers| +------------------------------------+ SELECT substr('Feathers' FROM 5 FOR 1); +--------------------------+ |substring(Feathers, 5, 1)| +--------------------------+ | h| +--------------------------+ -- substring SELECT substring('Feathers', 5); +-----------------------------------+ |substring(Feathers, 5, 2147483647)| +-----------------------------------+ | hers | +-----------------------------------+ SELECT substring('Feathers', -3); +------------------------------------+ |substring(Feathers, -3, 2147483647)| +------------------------------------+ | ers| +------------------------------------+ SELECT substring('Feathers', 5, 1); +--------------------------+ |substring(Feathers, 5, 1)| +--------------------------+ | h| +--------------------------+ SELECT substring('Feathers' FROM 5); +-----------------------------------+ |substring(Feathers, 5, 2147483647)| +-----------------------------------+ | hers | +-----------------------------------+ SELECT substring('Feathers' FROM -3); +------------------------------------+ |substring(Feathers, -3, 2147483647)| +------------------------------------+ | ers| +------------------------------------+ SELECT substring('Feathers' FROM 5 FOR 1); +--------------------------+ |substring(Feathers, 5, 1)| +--------------------------+ | h| +--------------------------+ -- substring_index SELECT substring_index('www.apache.org', '.', 2); +-------------------------------------+ |substring_index(www.apache.org, ., 2)| +-------------------------------------+ | www.apache| +-------------------------------------+ -- to_binary SELECT to_binary('abc', 'utf-8'); +---------------------+ |to_binary(abc, utf-8)| +---------------------+ | [61 62 63]| +---------------------+ -- to_char SELECT to_char(454, '999'); +-----------------+ |to_char(454, 999)| +-----------------+ | 454| +-----------------+ SELECT to_char(454.00, '000D00'); +-----------------------+ |to_char(454.00, 000D00)| +-----------------------+ | 454.00| +-----------------------+ SELECT to_char(12454, '99G999'); +----------------------+ |to_char(12454, 99G999)| +----------------------+ | 12,454| +----------------------+ SELECT to_char(78.12, '$99.99'); +----------------------+ |to_char(78.12, $99.99)| +----------------------+ | $78.12| +----------------------+ SELECT to_char(-12454.8, '99G999D9S'); +----------------------------+ |to_char(-12454.8, 99G999D9S)| +----------------------------+ | 12,454.8-| +----------------------------+ -- to_number SELECT to_number('454', '999'); +-------------------+ |to_number(454, 999)| +-------------------+ | 454| +-------------------+ SELECT to_number('454.00', '000.00'); +-------------------------+ |to_number(454.00, 000.00)| +-------------------------+ | 454.00| +-------------------------+ SELECT to_number('12,454', '99,999'); +-------------------------+ |to_number(12,454, 99,999)| +-------------------------+ | 12454| +-------------------------+ SELECT to_number('$78.12', '$99.99'); +-------------------------+ |to_number($78.12, $99.99)| +-------------------------+ | 78.12| +-------------------------+ SELECT to_number('12,454.8-', '99,999.9S'); +-------------------------------+ |to_number(12,454.8-, 99,999.9S)| +-------------------------------+ | -12454.8| +-------------------------------+ -- to_varchar SELECT to_varchar(454, '999'); +-----------------+ |to_char(454, 999)| +-----------------+ | 454| +-----------------+ SELECT to_varchar(454.00, '000D00'); +-----------------------+ |to_char(454.00, 000D00)| +-----------------------+ | 454.00| +-----------------------+ SELECT to_varchar(12454, '99G999'); +----------------------+ |to_char(12454, 99G999)| +----------------------+ | 12,454| +----------------------+ SELECT to_varchar(78.12, '$99.99'); +----------------------+ |to_char(78.12, $99.99)| +----------------------+ | $78.12| +----------------------+ SELECT to_varchar(-12454.8, '99G999D9S'); +----------------------------+ |to_char(-12454.8, 99G999D9S)| +----------------------------+ | 12,454.8-| +----------------------------+ -- translate SELECT translate('AaBbCc', 'abc', '123'); +---------------------------+ |translate(AaBbCc, abc, 123)| +---------------------------+ | A1B2C3| +---------------------------+ -- try_to_binary SELECT try_to_binary('abc', 'utf-8'); +-------------------------+ |try_to_binary(abc, utf-8)| +-------------------------+ | [61 62 63]| +-------------------------+ select try_to_binary('a!', 'base64'); +-------------------------+ |try_to_binary(a!, base64)| +-------------------------+ | NULL| +-------------------------+ select try_to_binary('abc', 'invalidFormat'); +---------------------------------+ |try_to_binary(abc, invalidFormat)| +---------------------------------+ | NULL| +---------------------------------+ -- try_to_number SELECT try_to_number('454', '999'); +-----------------------+ |try_to_number(454, 999)| +-----------------------+ | 454| +-----------------------+ SELECT try_to_number('454.00', '000.00'); +-----------------------------+ |try_to_number(454.00, 000.00)| +-----------------------------+ | 454.00| +-----------------------------+ SELECT try_to_number('12,454', '99,999'); +-----------------------------+ |try_to_number(12,454, 99,999)| +-----------------------------+ | 12454| +-----------------------------+ SELECT try_to_number('$78.12', '$99.99'); +-----------------------------+ |try_to_number($78.12, $99.99)| +-----------------------------+ | 78.12| +-----------------------------+ SELECT try_to_number('12,454.8-', '99,999.9S'); +-----------------------------------+ |try_to_number(12,454.8-, 99,999.9S)| +-----------------------------------+ | -12454.8| +-----------------------------------+ -- ucase SELECT ucase('Feathers'); +---------------+ |ucase(Feathers)| +---------------+ | FEATHERS| +---------------+ -- unbase64 SELECT unbase64('U3BhcmsgU1FM'); +----------------------+ |unbase64(U3BhcmsgU1FM)| +----------------------+ | [53 70 61 72 6B 2...| +----------------------+ -- upper SELECT upper('Feathers'); +---------------+ |upper(Feathers)| +---------------+ | FEATHERS| +---------------+