> For the complete documentation index, see [llms.txt](https://upsolver.gitbook.io/content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/string/bytes_substring.md).

# BYTES\_SUBSTRING

Returns a substring of the input value, using the offsets in bytes of the UTF-8 encoded byte representation. Partial characters and invalid UTF-8 code points are removed from the result.

## Syntax

Use the following syntax to include the `BYTES_SUBSTRING` function in your query:

```sql
BYTES_SUBSTRING(value, startIndex, endIndex)
```

## Arguments

The `BYTES_SUBSTRING` function requires the following arguments:

* `value` input is the string upon which you want to perform the substring function.&#x20;
* `startIndex` begins at `1` and includes the first character in your string.&#x20;
* `endIndex` counts from the first character in the string, not from the `startIndex` position. &#x20;

<table><thead><tr><th>Name</th><th width="138.33333333333331">Type</th><th>Description</th><th data-hidden>Default Value</th></tr></thead><tbody><tr><td>value</td><td>string</td><td>The input value to perform the substring function on</td><td></td></tr><tr><td>startIndex</td><td>int</td><td>The inclusive start index in bytes</td><td></td></tr><tr><td>endIndex</td><td>int</td><td>The exclusive end index in bytes</td><td></td></tr></tbody></table>

## Returns

Returns a `string` value.

***

## Examples

The following example shows how the `startIndex` and `endIndex` arguments affect the `Output` value. Here, the `endIndex` value demonstrates that regardless of the `startIndex` value, the `endIndex` works from position **1** in the string to include **10** characters. &#x20;

<table><thead><tr><th>value</th><th width="169">startIndex</th><th width="148">endIndex</th><th>Output</th></tr></thead><tbody><tr><td>'Hello World'</td><td>1</td><td>10</td><td><code>Hello Worl</code></td></tr><tr><td>'Hello World'</td><td>2</td><td>10</td><td><code>ello Worl</code></td></tr><tr><td>'⻤Hello Wor⻤'</td><td>2</td><td>10</td><td><code>Hello W</code></td></tr><tr><td>'⻤Hello Wor⻤'</td><td>1</td><td>10</td><td><code>⻤Hello W</code></td></tr><tr><td>'Hello'</td><td>1</td><td>10</td><td><code>Hello</code></td></tr></tbody></table>

### Transformation job example

The script below includes the `BYTES_SUBSTRING` function in a `SELECT` statement within a transformation job, using the "Hello World" string example.&#x20;

#### SQL

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT value, startIndex, endIndex,
        BYTES_SUBSTRING(value, 1, 10) AS Output
    FROM default_glue_catalog.upsolver_samples.orders_raw_data
    LET value = 'Hello World',
        startIndex = 1,
        endIndex = 10      
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

#### Query result

<table><thead><tr><th>value</th><th width="146">startIndex</th><th width="142">endIndex</th><th>Output</th></tr></thead><tbody><tr><td>'Hello World'</td><td>1</td><td>10</td><td><code>Hello Worl</code></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/string/bytes_substring.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
