Presto 0.100 Documentation

5.6. 字符串函数和运算符

5.6. 字符串函数和运算符

字符串运算符

使用运算符: || 完成字符串连接

字符串函数

Warning

目前所有的字符串函数都不能对Unicode(non-ASCII)字符串进行正确处理。例如,方法length()会返回UTF-8格式的字符串中的byte的数目,但是对于UniCode编码的字符串中的byte的个数却不能返回。

chr(n) → varchar

返回在下标为n的位置的char字符的字符串格式表示

concat(string1, string2) → varchar

Returns the concatenation of string1 and string2. This function provides the same functionality as the SQL-standard concatenation operator (||).

length(string) → bigint

Returns the length of string in characters.

lower(string) → varchar

Converts string to lowercase.

ltrim(string) → varchar

Removes leading spaces from string.

replace(string, search) → varchar

Removes all instances of search from string.

replace(string, search, replace) → varchar

Replaces all instances of search with replace in string.

reverse(string) → varchar

Returns string with the characters in reverse order.

rtrim(string) → varchar

Removes trailing spaces from string.

split(string, delimiter) → array<varchar>

Splits string on delimiter and returns an array.

split(string, delimiter, limit) → array<varchar>

Splits string on delimiter and returns an array of size at most limit. The last element in the array always contain everything left in the string. limit must be a positive number.

split_part(string, delimiter, index) → varchar

Splits string on delimiter and returns the field index. Field indexes start with 1. If the index is larger than than the number of fields, then null is returned.

strpos(string, substring) → bigint

Returns the starting position of the first instance of substring in string. Positions start with 1. If not found, 0 is returned.

substr(string, start) → varchar

Returns the rest of string from the starting position start. Positions start with 1. A negative starting position is interpreted as being relative to the end of the string.

substr(string, start, length) → varchar

Returns a substring from string of length length from the starting position start. Positions start with 1. A negative starting position is interpreted as being relative to the end of the string.

trim(string) → varchar

Removes leading and trailing spaces from string.

upper(string) → varchar

Converts string to uppercase.