RTRIM(string) removes the spaces at the end of a string and keeps the ones at the start. DuckDB's rtrim() does the same; trim() would also eat the leading spaces.
Updated · Checked on the xmetric engine
What is the syntax?
RTRIM(string)
string
the text.
Returns the string without trailing spaces. Null if the string is null.
What does it return, and what is the SQL?
Each example runs on the same 7 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
What is left after removing trailing spaces?
Tableau
RTRIM(' '+[Name]+' ')
SQL (DuckDB)
SELECTrtrim(' '|| Name ||' ') AS result
FROM input
ORDERBY id
The two leading spaces stay.
Name
Result
Ann Lee
Ann Lee
bob ray
bob ray
Café Nord
Café Nord
east
east
East
East
mary-jo o'neil
mary-jo o'neil
null
✓ The Tableau formula and the SQL return the same 7 rows.
Where does a straight translation go wrong?
Common mistake
Why does trim() lose the leading spaces?
trim() strips both ends; RTRIM only the end.
Tableau
RTRIM(' '+[Name]+' ')
Tempting SQL
SELECTtrim(' '|| Name ||' ') AS result
FROM input
ORDERBY id
SQL that matches
SELECTrtrim(' '|| Name ||' ') AS result
FROM input
ORDERBY id
Name
Tableau
Tempting SQL
SQL that matches
Ann Lee
Ann Lee
Ann Lee
Ann Lee
bob ray
bob ray
bob ray
bob ray
Café Nord
Café Nord
Café Nord
Café Nord
east
east
east
east
East
East
East
East
mary-jo o'neil
mary-jo o'neil
mary-jo o'neil
mary-jo o'neil
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
How do I write it in Snowflake or BigQuery?
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.