Tableau function String

Tableau RTRIM to SQL

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)

SELECT rtrim('  ' || Name || '  ') AS result
FROM input
ORDER BY id

The two leading spaces stay.

NameResult
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

SELECT trim('  ' || Name || '  ') AS result
FROM input
ORDER BY id

SQL that matches

SELECT rtrim('  ' || Name || '  ') AS result
FROM input
ORDER BY id
NameTableauTempting SQLSQL that matches
Ann Lee Ann LeeAnn Lee Ann Lee
bob ray bob raybob ray bob ray
Café Nord Café NordCafé Nord Café Nord
east easteast east
East EastEast East
mary-jo o'neil mary-jo o'neilmary-jo o'neil mary-jo o'neil
nullnullnull

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.

Snowflake

SELECT RTRIM(Name) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT RTRIM(Name) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own RTRIM formula return?

Edit the formula and run it on the 7 sample rows. Fields: [id], [Name], [Code], [Email], [Num].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about RTRIM?

Why are the spaces added inside the formula here?

The sample loader strips spaces around CSV cells, so the examples pad the name in the formula to show what RTRIM removes.

When do trailing spaces matter?

In equality tests and joins: 'East ' is not 'East'. RTRIM both sides before comparing fixed-width exports.

Where is this documented?