str argument. Removing specified characters are supported from StarRocks 2.5.0.
Syntax
Parameters
str: required, the string to trim, which must evaluate to a VARCHAR value.
characters: optional, the characters to remove, which must be a VARCHAR value. If this parameter is not specified, spaces are removed from the string by default. If this parameter is set to an empty string, an error is returned.
Return value
Returns a VARCHAR value.Examples
Example 1: Remove the five spaces from the beginning and end of the string.Text
Text
MySQL-compatible TRIM(... FROM ...) syntax
In addition to trim(str) and trim(str, characters), the database supports the MySQL/SQL-standard form:
BOTH(assumed when the specifier is omitted) trims both ends;LEADINGtrims only the start;TRAILINGtrims only the end.remstris an optional string literal. If omitted, spaces are trimmed.remstris removed as a whole substring, repeatedly — it is NOT treated as a set of characters. This differs fromtrim(str, characters), where the second argument is a character set.
Text
FROM) form and the character-set (comma) form:
Text
FROM form is backed by the builtins trim_string(str, remstr), ltrim_string(str, remstr), and rtrim_string(str, remstr), which can also be called directly. remstr must be a constant string literal.
NOTEremstrmust not be NULL. Passing a NULLremstrto these builtins (for exampletrim_string('abc', CAST(NULL AS STRING))) returns an error rather than NULL. This is consistent with the comma formtrim(str, characters)and differs from MySQL, which returns NULL. A NULLstrstill propagates to NULL (for exampleTRIM('x' FROM NULL)returns NULL).