STARTSWITH(string, substring) is true when the string begins with the substring, matched literally and case sensitively. DuckDB's starts_with() gives the same answer. ILIKE 'x%' ignores case and LIKE reads _ as a wildcard.
Updated · Checked on the xmetric engine
What is the syntax?
STARTSWITH(string, substring)
string
the text to test.
substring
the beginning to look for.
Returns true if string starts with substring, false if not, null if either 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.
Which names start with a capital E?
Tableau
STARTSWITH([Name], 'E')
SQL (DuckDB)
SELECTstarts_with(Name, 'E') AS result
FROM input
ORDERBY id
Only row 5, East.
Name
Result
Ann Lee
false
bob ray
false
Café Nord
false
east
false
East
true
mary-jo o'neil
false
null
✓ The Tableau formula and the SQL return the same 7 rows.
Where does a straight translation go wrong?
Common mistake
Why does ILIKE 'E%' also match east?
ILIKE ignores case; STARTSWITH does not. Row 4 is east.
Tableau
STARTSWITH([Name], 'E')
Tempting SQL
SELECT Name ILIKE'E%'AS result
FROM input
ORDERBY id
SQL that matches
SELECTstarts_with(Name, 'E') AS result
FROM input
ORDERBY id
Name
Tableau
Tempting SQL
SQL that matches
Ann Lee
false
false
false
bob ray
false
false
false
Café Nord
false
false
false
east
false
true
false
East
true
true
true
mary-jo o'neil
false
false
false
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
Common mistake
Why does LIKE 'C_%' match code C-301?
_ in LIKE matches any character, so the hyphen passes. STARTSWITH looks for a literal underscore.
Tableau
STARTSWITH([Code], 'C_')
Tempting SQL
SELECT Code LIKE'C_%'AS result
FROM input
ORDERBY id
SQL that matches
SELECTstarts_with(Code, 'C_') AS result
FROM input
ORDERBY id
Code
Tableau
Tempting SQL
SQL that matches
A-12-x
false
false
false
B-71
false
false
false
C-301-yz-9
false
true
false
a_1
false
false
false
X
false
false
false
D-4-y
false
false
false
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
SELECTSTARTSWITH(Name, 'E') AS result
FROM input
ORDERBY id