# Bytea

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: Bytea
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-data-types/bytea
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-data-types/bytea.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-data-types/bytea.adoc
description: The bytea data type stores arbitrary binary data such as raw key and value bytes from Redpanda topics or binary columns from Iceberg tables.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-data-types/bytea.md -->

The bytea data type stores arbitrary binary data as a sequence of bytes. Unlike `text`, bytea values are not UTF-8 validated and can contain any byte value. Redpanda SQL uses bytea to surface binary fields from external sources, including Iceberg tables, Protobuf and Avro topic schemas, and the raw key and value bytes of Redpanda Streaming records.

## [](#syntax)Syntax

```sql
variable_name BYTEA
```

## [](#examples)Examples

Create a table with a bytea column and insert binary data using the hex literal form:

```sql
CREATE TABLE binary_data (
    id INT,
    payload BYTEA
);
INSERT INTO binary_data (id, payload)
VALUES (1, '\xDEADBEEF'),
       (2, '\x00FF');
```

## [](#literal-formats)Literal formats

You can write a bytea literal in either of two PostgreSQL-compatible forms:

| Format | Example | Notes |
| --- | --- | --- |
| Hex | '\xDEADBEEF' | \x prefix followed by an even number of hexadecimal digits. Case-insensitive. |
| Escape (octal) | '\336\255' | Each \ is followed by exactly three octal digits in the range 0-7. Use \\ for a literal backslash. Other characters are taken literally. |

To cast a string literal to bytea explicitly, append `::bytea`:

```sql
SELECT '\xDEADBEEF'::bytea;
```

## [](#output-format)Output format

When a bytea value is returned to a client over the text wire format, Redpanda SQL hex-encodes it with the `\x` prefix, regardless of which literal format was used as input:

```sql
SELECT '\336\255'::bytea;
```

```sql
+---------+
| bytea   |
+---------+
| \xdead  |
+---------+
```

Over the binary wire format, Redpanda SQL returns bytea values as raw bytes without transformation.

## [](#supported-operations)Supported operations

The bytea data type supports a narrow set of operations. Operations not listed are not supported.

| Operation | Example |
| --- | --- |
| Equality and inequality | payload = '\xDEADBEEF'::bytea, payload <> '\x00'::bytea |
| Cast from a string literal | '\xDEADBEEF'::bytea |
| length(payload) | Returns the byte count as int. Distinct from length(text), which returns the codepoint count. |
| octet_length(payload) | Returns the byte count as int. Equivalent to length() on a bytea value. |

## [](#read-bytea-from-external-sources)Read bytea from external sources

Redpanda SQL maps binary fields from external sources to bytea automatically:

| Source | Maps to bytea |
| --- | --- |
| Iceberg | Columns of type BinaryType or FixedType. |
| Protobuf (topic schemas) | Fields declared as bytes. |
| Avro (topic schemas) | Fields declared as bytes or fixed. |
| Record metadata | redpanda.key, redpanda.headers[].value, and the raw key and value bytes exposed through redpanda_raw. |

For more on querying a topic alongside its Iceberg-translated history, see [Query Iceberg-enabled Topics](https://docs.redpanda.com/cloud-data-platform/sql/query-data/query-iceberg-topics/).