Tableau function String

Tableau PROPER to SQL

PROPER(string) capitalises the first letter of each word and lower-cases the rest; any character that is not a letter or digit starts a new word, so mary-jo o'neil becomes Mary-Jo O'Neil. DuckDB has no initcap: upper-case each character that follows a non-alphanumeric one.

Updated · Checked on the xmetric engine

What is the syntax?

PROPER(string)
string
the text.

Returns the string with each word capitalised. 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 does each name look like in title case?

Tableau

PROPER([Name])

SQL (DuckDB)

SELECT
  array_to_string(list_transform(RANGE (1, length(Name) + 1), i - > CASE WHEN i = 1 OR NOT regexp_matches(substr(Name, i - 1, 1), '[\pL\pN]') THEN upper(substr(Name, i, 1)) ELSE lower(substr(Name, i, 1)) END), '') AS result
FROM input
ORDER BY id

bob ray becomes Bob Ray; the hyphen and apostrophe in row 6 start new words.

NameResult
Ann LeeAnn Lee
bob rayBob Ray
Café NordCafé Nord
eastEast
EastEast
mary-jo o'neilMary-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 splitting on spaces miss Jo and Neil?

PROPER treats every non-alphanumeric character as a word break. Capitalising after spaces only leaves Mary-jo O'neil.

Tableau

PROPER([Name])

Tempting SQL

SELECT
  array_to_string(list_transform(string_split(lower(Name), ' '), w - > upper(LEFT (w, 1)) || substr(w, 2)), ' ') AS result
FROM input
ORDER BY id

SQL that matches

SELECT
  array_to_string(list_transform(RANGE (1, length(Name) + 1), i - > CASE WHEN i = 1 OR NOT regexp_matches(substr(Name, i - 1, 1), '[\pL\pN]') THEN upper(substr(Name, i, 1)) ELSE lower(substr(Name, i, 1)) END), '') AS result
FROM input
ORDER BY id
NameTableauTempting SQLSQL that matches
Ann LeeAnn LeeAnn LeeAnn Lee
bob rayBob RayBob RayBob Ray
Café NordCafé NordCafé NordCafé Nord
eastEastEastEast
EastEastEastEast
mary-jo o'neilMary-Jo O'NeilMary-jo O'neilMary-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 INITCAP(Name) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

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

BigQuery documentation

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

Do digits start a new word?

No. Letters and digits belong to the same word, so x2y becomes X2y.

Does PROPER fix names like McDonald?

No. It gives Mcdonald; names with inner capitals need a lookup table.

Is there a one-word SQL version elsewhere?

Yes: INITCAP in Snowflake and BigQuery. Their default word separators differ slightly, so check names with apostrophes.

Where is this documented?