REPLACE(string, substring, replacement) replaces every occurrence of the substring, read literally and case sensitively. DuckDB's replace() matches. regexp_replace is not a drop-in: there . means any character.
Updated · Checked on the xmetric engine
What is the syntax?
REPLACE(string, substring, replacement)
string
the text.
substring
the literal text to find.
replacement
the text to put in its place.
Returns the string with every substring replaced. Null if an input 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.
How do I remove the dots from each email?
Tableau
REPLACE([Email], '.', '')
SQL (DuckDB)
SELECTreplace(Email, '.', '') AS result
FROM input
ORDERBY id
ann@shop.com becomes ann@shopcom.
Email
Result
ann@shop.com
ann@shopcom
Bob.Ray@Mail.org
BobRay@Mailorg
cafe.nord@shop.fr
cafenord@shopfr
null
no email
no email
mj_2@shop.com
mj_2@shopcom
null
✓ The Tableau formula and the SQL return the same 7 rows.
Where does a straight translation go wrong?
Common mistake
Why does regexp_replace empty the whole email?
In a regex, . matches any character, so every character goes. REPLACE takes the dot literally. Use replace(), or escape it as '\.'.
Tableau
REPLACE([Email], '.', '')
Tempting SQL
SELECTregexp_replace(Email, '.', '', 'g') AS result
FROM input
ORDERBY id
SQL that matches
SELECTreplace(Email, '.', '') AS result
FROM input
ORDERBY id
Email
Tableau
Tempting SQL
SQL that matches
ann@shop.com
ann@shopcom
ann@shopcom
Bob.Ray@Mail.org
BobRay@Mailorg
BobRay@Mailorg
cafe.nord@shop.fr
cafenord@shopfr
cafenord@shopfr
null
null
null
no email
no email
no email
mj_2@shop.com
mj_2@shopcom
mj_2@shopcom
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.
Snowflake
SELECTREPLACE(Email, '.', '') AS result
FROM input
ORDERBY id