Bytea
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.
Examples
Create a table with a bytea column and insert binary data using the hex literal form:
CREATE TABLE binary_data (
id INT,
payload BYTEA
);
INSERT INTO binary_data (id, payload)
VALUES (1, '\xDEADBEEF'),
(2, '\x00FF');
Literal formats
You can write a bytea literal in either of two PostgreSQL-compatible forms:
| Format | Example | Notes |
|---|---|---|
Hex |
|
|
Escape (octal) |
|
Each |
To cast a string literal to bytea explicitly, append ::bytea:
SELECT '\xDEADBEEF'::bytea;
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:
SELECT '\336\255'::bytea;
+---------+
| bytea |
+---------+
| \xdead |
+---------+
Over the binary wire format, Redpanda SQL returns bytea values as raw bytes without transformation.
Supported operations
The bytea data type supports a narrow set of operations. Operations not listed are not supported.
| Operation | Example |
|---|---|
Equality and inequality |
|
Cast from a string literal |
|
|
Returns the byte count as |
|
Returns the byte count as |
Read bytea from external sources
Redpanda SQL maps binary fields from external sources to bytea automatically:
| Source | Maps to bytea |
|---|---|
Iceberg |
Columns of type |
Protobuf (topic schemas) |
Fields declared as |
Avro (topic schemas) |
Fields declared as |
Record metadata |
|
For more on querying a topic alongside its Iceberg-translated history, see Query Iceberg-enabled Topics.