Skip to content

Commit 8cb0380

Browse files
committed
feat(docs): document length_bytes
1 parent de20590 commit 8cb0380

1 file changed

Lines changed: 47 additions & 12 deletions

File tree

  • documentation/query/functions

documentation/query/functions/text.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,61 @@ trades,instrument=MI,side=B price=99348,quantity=8450 1571270400400
6464

6565
## length
6666

67-
`length(string)` - reads length of `string` value type (result is `int`)
67+
`length(value)` - reads length of the given value.
6868

69-
`length(symbol)` - reads length of `symbol` value type (result is `int`)
69+
**Arguments:**
70+
71+
- `value` is a value of one of the following types:
72+
- `varchar` - length is measured in characters (result is `int`)
73+
- `string` - length is measured in characters (result is `int`)
74+
- `symbol` - length is measured in characters (result is `int`)
75+
- `binary` blob - length is measured in bytes (result is `long`)
7076

71-
`length(blob)` - reads length of `binary` value type (result is `long`)
77+
**Return value:**
7278

73-
- a `string`
74-
- a `symbol`
75-
- a `binary` blob
79+
Returns an integer representing the length. For character types (`varchar`,
80+
`string`, `symbol`), returns the number of characters. For `binary`, returns the
81+
number of bytes. Returns `null` if the input is `null`.
82+
83+
**Examples:**
7684

7785
```questdb-sql title="Example"
7886
SELECT name a, length(name) b FROM names limit 4
7987
```
8088

81-
| a | b |
82-
| ------ | --- |
83-
| AARON | 5 |
84-
| AMELIE | 6 |
85-
| TOM | 3 |
86-
| null | -1 |
89+
| a | b |
90+
| ------ | ---- |
91+
| AARON | 5 |
92+
| AMELIE | 6 |
93+
| TOM | 3 |
94+
| null | null |
95+
96+
## length_bytes
97+
98+
`length_bytes(varchar)` - reads length of a `varchar` value in bytes.
99+
100+
**Arguments:**
101+
102+
- `varchar` is a varchar value to return byte length for.
103+
104+
**Return value:**
105+
106+
Returns an `int` representing the byte length of the varchar. This is useful for
107+
multi-byte character encodings (e.g., UTF-8) where the byte length may differ
108+
from the character length. Returns `null` if the input is `null`.
109+
110+
**Examples:**
111+
112+
```questdb-sql title="Example"
113+
SELECT name a, length_bytes(name) b FROM names limit 4
114+
```
115+
116+
| a | b |
117+
| ------ | ---- |
118+
| AARON | 5 |
119+
| AMELIE | 6 |
120+
| ДЖЕК | 8 |
121+
| null | null |
87122

88123
## left
89124

0 commit comments

Comments
 (0)