String Functions¶
Note
These functions assume that the input strings contain valid UTF-8 encoded Unicode code points. There are no explicit checks for valid UTF-8 and the functions may return incorrect results on invalid UTF-8.
Additionally, the functions operate on Unicode code points and not user visible characters (or grapheme clusters). Some languages combine multiple code points into a single user-perceived character, the basic unit of a writing system for a language, but the functions will treat each code point as a separate unit.
The lower() and upper() functions do not perform
locale-sensitive, context-sensitive, or one-to-many mappings required for
some languages. Specifically, this will return incorrect results for
Lithuanian, Turkish and Azeri.
- chr(n) varchar¶
Returns the Unicode code point
nas a single character string.
- codepoint(string) integer¶
Returns the Unicode code point of the only character of
string.
- concat(string1, ..., stringN) varchar¶
Returns the concatenation of
string1,string2,...,stringN. This function provides the same functionality as the SQL-standard concatenation operator (||).
- length(string) bigint¶
Returns the length of
stringin characters.
- lower(string) varchar¶
Converts
stringto lowercase.
- lpad(string, size, padstring) varchar¶
Left pads
stringtosizecharacters withpadstring. Ifsizeis less than the length ofstring, the result is truncated tosizecharacters.sizemust not be negative andpadstringmust be non-empty.
- ltrim(string) varchar¶
Removes leading whitespace from string.
- replace(string, search) varchar¶
Removes all instances of
searchfromstring.
- replace(string, search, replace) varchar¶
Replaces all instances of
searchwithreplaceinstring.If
searchis an empty string, insertsreplacein front of every character and at the end of thestring.
- reverse(string) varchar¶
Reverses
string.
- rpad(string, size, padstring) varchar¶
Right pads
stringtosizecharacters withpadstring. Ifsizeis less than the length ofstring, the result is truncated tosizecharacters.sizemust not be negative andpadstringmust be non-empty.
- rtrim(string) varchar¶
Removes trailing whitespace from string.
- split(string, delimiter)¶
Splits
stringondelimiterand returns an array.
- split(string, delimiter, limit)¶
Splits
stringondelimiterand returns an array of size at mostlimit.The last element in the array always contains everything left in the string.
limitmust be a positive number.
- split_part(string, delimiter, index) string¶
Splits
stringondelimiterand returns the part at indexindex.Field indexes start with 1. If the index is larger than the number of fields, then null is returned.
- strpos(string, substring) bigint¶
Returns the starting position of the first instance of
substringinstring. Positions start with1. If not found,0is returned.
- strpos(string, substring, instance) bigint¶
Returns the position of the N-th
instanceofsubstringinstring.instancemust be a positive number. Positions start with1. If not found,0is returned.
- strrpos(string, substring) bigint¶
Returns the starting position of the last instance of
substringinstring. Positions start with1. If not found,0is returned.
- strrpos(string, substring, instance) bigint¶
Returns the position of the N-th
instanceofsubstringinstringstarting from the end of the string.instancemust be a positive number. Positions start with1. If not found,0is returned.
- substr(string, start) varchar¶
Returns the rest of
stringfrom the starting positionstart. Positions start with1. A negative starting position is interpreted as being relative to the end of the string.
- substr(string, start, length) varchar¶
Returns a substring from
stringof lengthlengthfrom the starting positionstart. Positions start with1. A negative starting position is interpreted as being relative to the end of the string.
- trim(string) varchar¶
Removes starting and ending whitespaces from
string.
- upper(string) varchar¶
Converts
stringto uppercase.
Unicode Functions¶
- to_utf8(string) varbinary¶
Encodes
stringinto a UTF-8 varbinary representation.