Click to copy

• Reviewed for ksqlDB 0.29

How to Add a Column to a Table in ksqlDB

To add a column to a table, simply rerun the CREATE statement by adding the OR REPLACE modifier alongside the new column at the end:

CREATE TABLE OR REPLACE product (
  id STRING PRIMARY KEY,
  name STRING,
  color STRING,
  new_category STRING
) WITH (...);
Remember how to get the statement used to create a table.

The table was created from a query

If your table was created from a query, rerun the same CREATE TABLE AS SELECT statement with the new column.

CREATE TABLE OR REPLACE blue_product
AS SELECT id, name, color, new_category
FROM product_source
WHERE color = 'blue';

Materialization and new values

Note that since ksqlDB reuses the same offsets for the new query, the new column will only be parsed and populated for newly produced records after the moment you ran the statement.

This only applies to pull queries on materialized tables since push queries on non-materialized tables will do a full scan on the source anyways.

Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like