---
title: SQL binary string functions
description: Use binary string functions to encode and decode binary string values in SQL queries.
url: https://docs.influxdata.com/influxdb3/cloud-serverless/reference/sql/functions/binary-string/
estimated_tokens: 410
publisher: InfluxData
canonical: https://docs.influxdata.com/influxdb3/cloud-serverless/reference/sql/functions/binary-string/
date: '2025-09-05T08:26:38-06:00'
lastmod: '2025-09-05T08:26:38-06:00'
---

Use binary string functions to encode and decode binary string values in
SQL queries.

* [decode](#decode)
* [encode](#encode)

## decode

Decode binary data from textual representation in string.

```sql
decode(expression, format)
```

### Arguments

* **expression**: Expression containing encoded string data.
  Can be a constant, column, or function, and any combination of string operators.
* **format**: Encoding format of the encoded string. Supported formats are:
  * base64
  * hex

##### Related functions

[encode](#encode)

## encode

Encode binary data into a textual representation.

```sql
encode(expression, format)
```

### Arguments

* **expression**: Expression containing string or binary data.
  Can be a constant, column, or function, and any combination of string operators.
* **format**: Encoding format to use. Supported formats are:
  * base64
  * hex

##### Related functions

[decode](#decode)

[](#view-encode-query-example)

View `encode` query example

*The following example uses the[NOAA Bay Area weather sample data](/influxdb3/cloud-serverless/reference/sample-data/#noaa-bay-area-weather-data).*

```sql
SELECT DISTINCT
  location,
  encode(location::string, 'hex') AS location_encoded
FROM weather
```

|  location   |    location\_encoded     |
|-------------|--------------------------|
|   Concord   |      436f6e636f7264      |
|   Hayward   |      48617977617264      |
|San Francisco|53616e204672616e636973636f|
| location | location_encoded |
| --- | --- |
| location | location_encoded |
| Concord | 436f6e636f7264 |
| Hayward | 48617977617264 |
| San Francisco | 53616e204672616e636973636f |
