CHAR

Return the character corresponding to the given Unicode code point.

Category: stringReturns: VARCHARDialect: PostgreSql

Syntax

CHAR(code)

Description

## Overview Returns the single-character string whose Unicode code point equals the given integer. CHAR is the inverse of ASCII: ASCII(CHAR(65)) is 65. Use CHAR to emit control characters such as tab (9), line feed (10), and carriage return (13), and to generate arbitrary Unicode characters at runtime by code point. CHR is an alias of CHAR with identical semantics. ## Behavior - Returns NULL when the input is NULL. - Accepts code points in the range [0, 0x10FFFF] (the full Unicode range). - For code point 0, returns a string containing a single NUL character (U+0000). - For code points in surrogate ranges [0xD800, 0xDFFF], the result is implementation-defined; do not rely on it. - Produces a string of length 1 in characters, but the byte length depends on the code point (1 byte for [0, 127], 2 bytes for [128, 2047], 3 bytes for [2048, 65535], 4 bytes for [65536, 0x10FFFF]). - Negative values and values above 0x10FFFF raise an error. ## Compatibility - Matches the common SQL convention for CHR/CHAR code-point conversion. - CHR is a supported alias.

Parameters

NameTypeDescription
codeSpecifies the Unicode code point to convert. Must be a non-negative integer no greater than 0x10FFFF.

Examples

-- ASCII letter
SELECT CHAR(65);  -- 'A'
-- Lowercase letter
SELECT CHAR(97);  -- 'a'
-- Newline character
SELECT CHAR(10);  -- line feed
-- Space character
SELECT CHAR(32);  -- ' '
-- Unicode euro sign
SELECT CHAR(8364);  -- '€'
-- NULL propagates
SELECT CHAR(CAST(NULL AS INT));  -- NULL

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →