CREATE TABLE
The CREATE TABLE statement maps a Redpanda topic to a SQL table through a catalog. After creating the table, you can query the topic using standard SQL.
You must first create a Redpanda catalog connection before creating tables. CREATE TABLE in Redpanda SQL maps Redpanda topics to SQL tables and does not create standalone tables with user-defined schemas.
|
Syntax
CREATE TABLE [IF NOT EXISTS] catalog_name=>table_name
WITH (option = 'value' [, ...]);
-
catalog_name: Name of an existing Redpanda catalog. -
table_name: Name for the new table. -
IF NOT EXISTS: Optional. Prevents an error if a table with the same name already exists in the catalog.
Options
| Option | Type | Required | Description |
|---|---|---|---|
|
STRING |
Yes |
Name of the Redpanda topic to map to this table. |
|
STRING |
No |
Schema Registry subject name to use for deserializing topic data. Defaults to the topic-name strategy ( |
|
STRING |
No |
How to resolve the schema version. |
|
STRING |
No |
How to handle records that fail deserialization.
|
|
STRING |
No |
How to map nested structures from the topic schema to SQL columns.
|
|
STRING |
No |
Full Protobuf message name. Required when the schema contains multiple message definitions. |
|
STRING |
No |
Whether records on the topic are encoded with the Confluent Schema Registry wire format (a magic byte followed by a 4-byte schema ID before the payload).
Only valid when |
Auto-added columns
Every catalog-mapped table includes two struct columns in addition to the columns derived from the topic’s schema. Redpanda SQL adds these columns to both Kafka-backed and Iceberg-backed tables. The names redpanda and redpanda_raw are reserved. A topic schema cannot define columns with these names.
redpanda
Contains Kafka record metadata. Always present on every row.
| Field | Type | Nullable | Description |
|---|---|---|---|
|
|
No |
Partition the record was read from. |
|
|
No |
Offset of the record within its partition. |
|
|
Yes |
Record timestamp. |
|
Array of struct |
Yes |
Record headers, as an array where each element is a struct of header name and value bytes. |
|
|
Yes |
Record key bytes. |
|
|
Yes |
Kafka timestamp type code. |
redpanda_raw
Populated only when error_handling_policy = 'FILL_NULL' and a record fails to decode. In all other cases, redpanda_raw is NULL.
Use redpanda_raw as a dead-letter pattern. Rows whose value fails schema deserialization remain queryable, with the malformed payload preserved for inspection or reprocessing.
| Field | Type | Nullable | Description |
|---|---|---|---|
|
|
Yes |
Raw record key bytes. |
|
|
Yes |
Raw record value bytes that failed to decode. |
Examples
Map a topic to a table
Map the transactions topic to a table through default_redpanda_catalog:
CREATE TABLE default_redpanda_catalog=>transactions
WITH (
topic = 'transactions',
schema_subject = 'transactions-value'
);
Create a table from a multi-message Protobuf schema
When the Protobuf schema for the topic defines more than one message, specify the message to use with output_schema_message_full_name:
CREATE TABLE default_redpanda_catalog=>orders
WITH (
topic = 'orders',
schema_subject = 'orders-value',
output_schema_message_full_name = 'com.example.orders.Order'
);