AnalyticDB for PostgreSQL is compatible with the string functions and operators of PostgreSQL. This topic describes the string functions and operators that are supported by AnalyticDB for PostgreSQL and provides examples on how to use the string functions and operators.
For information about the string functions and operators of PostgreSQL, see String Functions and Operators.
SQL string functions and operators
Function | Data type of the return value | Description | Example | Sample result |
|
| Concatenates two strings. |
|
|
|
| Concatenates a string and a non-string. |
|
|
|
| Returns the number of bits in a string. |
|
|
|
| Returns the number of characters in a string. |
|
|
|
| Converts uppercase letters in a string into lowercase letters. |
|
|
|
| Returns the length of a string in bytes. |
|
|
|
| Replaces a substring at a specific position in a string. |
|
|
|
| Finds the start position of a substring in a string. |
|
|
|
| Extracts a substring from a string. |
|
|
|
| Extracts a substring from a string based on a Portable Operating System Interface (POSIX) regular expression. For example, you can specify the start position and length for the extraction. |
|
|
|
| Extracts a substring from a string based on an SQL regular expression. |
|
|
|
| Removes the longest substring or substrings that contain the specified characters from the start, the end, or both the start and the end of a string. |
|
|
|
| Removes the longest substring or substrings that contain spaces or the specified characters from the start, the end, or both the start and the end of a string. |
|
|
|
| Converts lowercase letters in a string into uppercase letters. |
|
|
Other string functions
Function | Data type of the return value | Description | Example | Sample result |
|
| Returns the ASCII code of the first character in a string. |
|
|
|
| Removes the longest substrings that contain characters in a specific character set from the start and the end of a string. If no character set is specified, whitespace characters such as spaces and tabs are removed by default. |
|
|
|
| Converts an integer that represents an ASCII or extended ASCII code value into the corresponding character. |
|
|
|
| Concatenates two or more strings into a string. |
|
|
|
| Concatenates multiple strings into a string and inserts a |
|
|
|
| Converts a string from the |
|
|
|
| Converts a binary string of the |
|
|
|
| Converts a string of the TEXT type into a binary string of the |
|
|
|
| Decodes a hexadecimal string of the TEXT type into the binary representation of the |
|
|
|
| Encodes a binary string of the |
|
|
|
| Outputs a formatted string. |
|
|
|
| Converts the first letter of each word in a string into the corresponding uppercase letter and the other letters into the corresponding lowercase letters. |
|
|
|
| Returns the first |
|
|
|
| Counts the number of characters in a string, including spaces and special characters. |
|
|
|
| Counts the number of characters in a |
|
|
|
| Pads a string on the left to a specific length with a sequence of specified characters. |
|
|
|
| Removes the characters in a specific character set from the left side of a string. If no character set is specified, whitespace characters such as spaces, tabs, and line feeds are removed by default. |
|
|
|
| Calculates the MD5 hash value of a string. |
|
|
|
| Parses a string that conforms to SQL identifier rules and splits the string into a schema and an object name. |
|
|
|
| Returns the client encoding name of the current session. |
|
|
|
| Converts a string into an identifier that can be safely used in an SQL statement. |
|
|
|
| Forcibly converts a string into the TEXT type and encloses the string in quotation marks. |
|
|
quote_literal(
|
| Forcibly converts a value into the TEXT type and encloses the value in quotation marks. |
|
|
|
| Forcibly converts a string into the TEXT type and encloses the string in quotation marks. If you specify NULL in the function, |
|
|
|
| Forcibly converts a value of any type into the TEXT type and encloses the value in quotation marks. |
|
|
|
| Performs a regular expression match. This function searches for substrings that match a specific pattern in a specific string and returns an array of the matches. If multiple matches exist, each match is returned as an element. If no matches exist, NULL is returned. |
|
|
|
| Performs a regular expression match. This function searches for substrings that match a specific pattern in a specific string and returns all matches. |
|
(2 rows) |
|
| Replaces substrings that match a POSIX regular expression. |
|
|
|
| Uses a POSIX regular expression as the delimiter to split a string. |
|
|
|
| Uses a POSIX regular expression as the delimiter to split a string. |
|
(2 rows) |
|
| Repeats a specific string a specific number of times. |
|
|
|
| Finds a specific substring in a specific string and replaces the substring with another specified substring. |
|
|
|
| Reverses the order of the characters in a specific string. |
|
|
|
| Extracts the rightmost n characters from a specific string. |
|
|
|
| Pads a string on the right to a specific length with a sequence of specified characters. |
|
|
|
| Removes specified characters or whitespace characters from the end of a string. |
|
|
|
| Splits a string by using a specific delimiter. |
|
|
|
| Finds the position of the first occurrence of a |
|
|
|
| Extracts a substring from a string. |
|
|
|
| Returns t, which indicates true, if a specific |
|
|
|
| Converts a |
|
|
|
| Converts a numeric value of the INTEGER or BIGINT type into the corresponding hexadecimal representation. |
|
|
|
| Replaces specific characters in a string with other characters. |
|
|