Tableau function String

Tableau CHAR to SQL

CHAR(number) returns the character with that code: CHAR(65) is A, CHAR(233) is é. In DuckDB it's chr(), which wants an INTEGER, so cast a BIGINT column first. Don't reach for CAST(... AS CHAR): in SQL that turns 65 into the text '65'.

Updated · Checked on the xmetric engine

What is the syntax?

CHAR(number)
number
an integer code point, such as 65 for A.

Returns a one-character string for the code point. Null if the number 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 character does each code stand for?

Tableau

CHAR([Num])

SQL (DuckDB)

SELECT chr(CAST (Num AS INTEGER)) AS result
FROM input
ORDER BY id

65 is A, 97 is a, 233 is é, 32 is a space.

NumResult
65A
97a
233é
480
32
122z
null

The Tableau formula and the SQL return the same 7 rows.

Where does a straight translation go wrong?

Common mistake

Why does CAST(Num AS CHAR) return digits?

In SQL, CHAR is a type name, so CAST(65 AS CHAR) is the text '65'. Tableau's CHAR is a function that looks up the character. Use chr().

Tableau

CHAR([Num])

Tempting SQL

SELECT CAST (Num AS CHAR) AS result
FROM input
ORDER BY id

SQL that matches

SELECT chr(CAST (Num AS INTEGER)) AS result
FROM input
ORDER BY id
NumTableauTempting SQLSQL that matches
65A65A
97a97a
233é233é
480480
32 32
122z122z
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 CHR(Num) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT CODE_POINTS_TO_STRING([Num]) AS result
FROM input
ORDER BY id

BigQuery documentation

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

Does CHAR go beyond ASCII?

Yes. It takes Unicode code points: 233 is é. DuckDB chr(), Snowflake CHR and BigQuery CODE_POINTS_TO_STRING do the same.

What does CHAR return for a null?

Null. Row 7 of the sample has no number and returns null.

How do I add a line break in a label?

[Name] + CHAR(10) + [Code]. In DuckDB, Name || chr(10) || Code.

Where is this documented?