> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ENCODE

> Encodes text using a character encoding.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

NULL text returns NULL; NULL charset errors.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
encode(value, charset)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING | Yes | Text. |
| charset | STRING | Yes | The encoding. Must be a constant argument. |

## Returns

* Type: BINARY
* Possible values: Encoded bytes.
* NULL behavior: NULL text returns NULL; NULL charset errors.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Charset is case-insensitive and constant within an evaluated batch. Supported: US-ASCII, ISO-8859-1, UTF-8, UTF-16, UTF-16BE, UTF-16LE. UTF-16 adds a big-endian BOM.
* US-ASCII replaces non-ASCII characters with ?. ISO-8859-1 replaces code points above 255 with ?.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT hex(encode('é', 'UTF-8')) AS "value";
```

| value |
| - |
| C3A9 |

### Encode Unicode text as UTF-8

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT hex(encode('猫', 'UTF-8')) AS utf8_hex;
```

| utf8\_hex |
| - |
| E78CAB |

## Limitations

* Unsupported/nonconstant charsets error.
* ENCODE takes STRING text and a STRING character-set name. BINARY input is not supported.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.