Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

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 quotes that surround the string "dog":

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