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)
SELECTchr(CAST (Num AS INTEGER)) AS result
FROM input
ORDERBY id
65 is A, 97 is a, 233 is é, 32 is a space.
Num
Result
65
A
97
a
233
é
48
0
32
122
z
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
SELECTCAST (Num AS CHAR) AS result
FROM input
ORDERBY id
SQL that matches
SELECTchr(CAST (Num AS INTEGER)) AS result
FROM input
ORDERBY id
Num
Tableau
Tempting SQL
SQL that matches
65
A
65
A
97
a
97
a
233
é
233
é
48
0
48
0
32
32
122
z
122
z
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.