Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions documentation/query/functions/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,23 @@ trades,instrument=MI,side=B price=99348,quantity=8450 1571270400400

## length

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

`length(symbol)` - reads length of `symbol` value type (result is `int`)
**Arguments:**

- `value` is a value of one of the following types:
- `varchar` - length is measured in characters (result is `int`)
- `string` - length is measured in characters (result is `int`)
- `symbol` - length is measured in characters (result is `int`)
- `binary` blob - length is measured in bytes (result is `long`)

**Return value:**

`length(blob)` - reads length of `binary` value type (result is `long`)
Returns an integer representing the length. For character types (`varchar`,
`string`, `symbol`), returns the number of characters. For `binary`, returns the
number of bytes. Returns `-1` if the input is `null`.

- a `string`
- a `symbol`
- a `binary` blob
**Examples:**

```questdb-sql title="Example"
SELECT name a, length(name) b FROM names limit 4
Expand All @@ -85,6 +93,33 @@ SELECT name a, length(name) b FROM names limit 4
| TOM | 3 |
| null | -1 |

## length_bytes

`length_bytes(varchar)` - reads length of a `varchar` value in bytes.

**Arguments:**

- `varchar` is a varchar value to return byte length for.

**Return value:**

Returns an `int` representing the byte length of the varchar. This is useful for
multi-byte character encodings (e.g., UTF-8) where the byte length may differ
from the character length. Returns `-1` if the input is `null`.

**Examples:**

```questdb-sql title="Example"
SELECT name a, length_bytes(name) b FROM names limit 4
```

| a | b |
| ------ | --- |
| AARON | 5 |
| AMELIE | 6 |
| ДЖЕК | 8 |
| null | -1 |

## left

`left(string, count)` - extracts a substring of the given length from a string
Expand Down