Skip to main content

CHAR

The CHAR() function returns a string made of the characters for one or more character codes.

See also:
[SELECT]


note

When using StackQL with a PostgreSQL backend, the equivalent function is CHR(), which takes a single code.

Syntax​

SELECT CHAR(ascii_code [, ascii_code, ...]) FROM <multipartIdentifier>;

Each argument adds one character to the result, so CHAR(72, 105) returns Hi.

Arguments​

ascii_code
One or more integers, each the code of a character: an ASCII code, or any Unicode code point.

Return Value(s)​

Returns a string with one character for each ascii_code argument.


Common ASCII Codes​

CharacterDescriptionASCII CodeUsage Example
\nNewline10CHAR(10)
'Single Quote39CHAR(39)
"Double Quote34CHAR(34)
(space)Space32CHAR(32)
:Colon58CHAR(58)
;Semicolon59CHAR(59)
\tHorizontal Tab9CHAR(9)
\rCarriage Return13CHAR(13)
\bBackspace8CHAR(8)
\fForm Feed12CHAR(12)

Examples​

Concatenate Strings with Special Characters​

To concatenate strings with a newline character between them:

SELECT
'/* ' || displayName || ' */' || CHAR(10) || 'DELETE FROM databricks_account.iam.account_users WHERE account_id = ' || CHAR(39) || account_id || CHAR(39) || ' AND id = ' || CHAR(39) || id || CHAR(39)
FROM
databricks_account.iam.account_users
where account_id = 'abcd1234-1234-5678-90ab-abcdef123456'
AND active = false;

Result (for a user with the display name Jane Doe and the id 1234567890123456):

/* Jane Doe */
DELETE FROM databricks_account.iam.account_users WHERE account_id = 'abcd1234-1234-5678-90ab-abcdef123456' AND id = '1234567890123456'