TRIM function - Amazon Redshift

TRIM function

The TRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.


TRIM( [ BOTH ] ['characters' FROM ] string ] )



(Optional) The characters to be trimmed from the string. If this parameter is omitted, blanks are trimmed.


The string to be trimmed.

Return type

The TRIM function returns a VARCHAR or CHAR string. If you use the TRIM function with a SQL command, Amazon Redshift implicitly converts the results to VARCHAR. If you use the TRIM function in the SELECT list for a SQL function, Amazon Redshift does not implicitly convert the results, and you might need to perform an explicit conversion to avoid a data type mismatch error. See the CAST and CONVERT functions and CONVERT functions for information about explicit conversions.


The following example removes the double quotation marks that surround the string "dog":

select trim('"' FROM '"dog"'); btrim ------- dog (1 row)