Click to copy

• Reviewed for ksqlDB 0.29

How to Create Table from Stream in ksqlDB

To create a table from an existing stream, use a CREATE TABLE AS SELECT statement where the query is an EMIT CHANGES push query.

CREATE TABLE max_course_score
AS SELECT
  course_name,
  max(score) as score
FROM student_records
GROUP BY course_name
EMIT CHANGES;
This method creates a materialized table, that has a persistent query keeping its state up-to-date so that you can run pull queries on it.

The fields or expressions that are present in the GROUP BY clause will be used as the PRIMARY KEY of the table.

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