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)returnsHi.
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
| Character | Description | ASCII Code | Usage Example |
|---|---|---|---|
\n | Newline | 10 | CHAR(10) |
' | Single Quote | 39 | CHAR(39) |
" | Double Quote | 34 | CHAR(34) |
| (space) | Space | 32 | CHAR(32) |
: | Colon | 58 | CHAR(58) |
; | Semicolon | 59 | CHAR(59) |
\t | Horizontal Tab | 9 | CHAR(9) |
\r | Carriage Return | 13 | CHAR(13) |
\b | Backspace | 8 | CHAR(8) |
\f | Form Feed | 12 | CHAR(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'