Tableau function String

Tableau STARTSWITH to SQL

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)

SELECT starts_with(Name, 'E') AS result
FROM input
ORDER BY id

Only row 5, East.

NameResult
Ann Leefalse
bob rayfalse
Café Nordfalse
eastfalse
Easttrue
mary-jo o'neilfalse
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
ORDER BY id

SQL that matches

SELECT starts_with(Name, 'E') AS result
FROM input
ORDER BY id
NameTableauTempting SQLSQL that matches
Ann Leefalsefalsefalse
bob rayfalsefalsefalse
Café Nordfalsefalsefalse
eastfalsetruefalse
Easttruetruetrue
mary-jo o'neilfalsefalsefalse
nullnullnull

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
ORDER BY id

SQL that matches

SELECT starts_with(Code, 'C_') AS result
FROM input
ORDER BY id
CodeTableauTempting SQLSQL that matches
A-12-xfalsefalsefalse
B-71falsefalsefalse
C-301-yz-9falsetruefalse
a_1falsefalsefalse
Xfalsefalsefalse
D-4-yfalsefalsefalse
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 STARTSWITH(Name, 'E') AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT STARTS_WITH(Name, 'E') AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own STARTSWITH 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 STARTSWITH?

Is STARTSWITH case sensitive?

Yes. STARTSWITH([Name], 'E') matches East but not east.

What does STARTSWITH return for a null?

Null, so a filter on it drops row 7.

Where is this documented?