Skip to content

Commit 2f395f8

Browse files
authored
update string CHAR func (#2421)
1 parent 48e3164 commit 2f395f8

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

docs/en/sql-reference/20-sql-functions/06-string-functions/char.md

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,82 @@ id: string-char
33
title: CHAR
44
---
55

6-
Return the character for each integer passed.
6+
import FunctionDescription from '@site/src/components/FunctionDescription';
7+
8+
<FunctionDescription description="Introduced or updated: v1.2.752"/>
9+
10+
11+
Returns the character(s) for each integer passed. The function converts each integer to its corresponding Unicode character.
712

813
## Syntax
914

1015
```sql
1116
CHAR(N, ...)
17+
CHR(N)
1218
```
1319

1420
## Arguments
1521

16-
| Arguments | Description |
17-
|-----------|----------------|
18-
| N | Numeric Column |
22+
| Arguments | Description |
23+
|-----------|----------------------------------------------------------------|
24+
| N | Integer value(s) representing Unicode code points (0 to 2^32-1) |
1925

2026
## Return Type
2127

22-
`BINARY`
28+
`STRING`
29+
30+
## Remarks
31+
32+
- Accepts any integer type (auto-casts to Int64).
33+
- Returns empty string ('') and logs an error for invalid code points.
34+
- `chr` is an alias for `char`.
35+
- NULL inputs result in NULL output.
2336

2437
## Examples
2538

2639
```sql
27-
SELECT CHAR(77,121,83,81,76) as a, a::String;
28-
┌────────────────────────┐
29-
│ a │ a::string │
30-
│ Binary │ String │
31-
├────────────┼───────────┤
32-
│ 4D7953514C │ MySQL │
33-
└────────────────────────┘
40+
-- Basic usage
41+
SELECT CHAR(65, 66, 67);
42+
┌───────┐
43+
char
44+
│ String│
45+
├───────┤
46+
│ ABC │
47+
└───────┘
48+
49+
-- Using the CHR alias
50+
SELECT CHR(68);
51+
┌───────┐
52+
│ chr │
53+
│ String│
54+
├───────┤
55+
│ D │
56+
└───────┘
57+
58+
-- Creating a string from multiple code points
59+
SELECT CHAR(77,121,83,81,76);
60+
┌───────┐
61+
char
62+
│ String│
63+
├───────┤
64+
│ MySQL │
65+
└───────┘
66+
67+
-- Auto-casting from different integer types
68+
SELECT CHAR(CAST(65 AS UInt16));
69+
┌───────┐
70+
char
71+
│ String│
72+
├───────┤
73+
│ A │
74+
└───────┘
75+
76+
-- NULL handling
77+
SELECT CHAR(NULL);
78+
┌───────┐
79+
char
80+
│ String│
81+
├───────┤
82+
NULL
83+
└───────┘
3484
```

docs/en/sql-reference/20-sql-functions/06-string-functions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ This page provides a comprehensive overview of String functions in Databend, org
8787
|----------|-------------|---------|
8888
| [ASCII](ascii.md) | Returns ASCII value of first character | `ASCII('D')``68` |
8989
| [ORD](ord.md) | Returns Unicode code point of first character | `ORD('D')``68` |
90-
| [CHAR](char.md) | Returns character for given code points | `CHAR(68,97,116,97)``'Data'` |
90+
| [CHAR](char.md) / [CHR](char.md) | Returns string of characters for given Unicode code points | `CHAR(68,97,116,97)``'Data'` |
9191
| [BIN](bin.md) | Returns binary representation | `BIN(5)``'101'` |
9292
| [OCT](oct.md) | Returns octal representation | `OCT(8)``'10'` |
9393
| [HEX](hex.md) | Returns hexadecimal representation | `HEX('ABC')``'414243'` |

0 commit comments

Comments
 (0)