TRIM

String Function

Description

The TRIM function Trims a string by blanks or specified characters.

(RedShift SQL Language Reference TRIM function)

In Redshift, it is possible to specify where to perform a trim operation using keywords (BOTH, LEADING, or TRAILING). This functionality can be replicated in Snowflake by using the TRIM, LTRIM, and RTRIM functions, respectively.

Grammar Syntax

TRIM( [ BOTH | LEADING | TRAILING ] [trim_chars FROM ] string )

This function is fully supported by Snowflake.

Sample Source Patterns

Input Code:

IN -> Redshift_01.sql
SELECT TRIM('    dog    ') AS SimpleTrim;

SELECT TRIM(LEADING '"' FROM'"dog"') AS LeadingTrim;

SELECT TRIM(TRAILING '"' FROM'"dog"') AS TrailingTrim;

SELECT TRIM('x' FROM 'xxxHello Worldxxx') AS FromTrim;

Output Code:

OUT -> Redshift_01.sql
SELECT TRIM('    dog    ') AS SimpleTrim;

SELECT
LTRIM('"dog"', '"') AS LeadingTrim;

SELECT
RTRIM('"dog"', '"') AS TrailingTrim;

SELECT
TRIM('xxxHello Worldxxx', 'x') AS FromTrim;

Know Issues

No issues were found.

There are no known issues.

Last updated