Click to copy

• Reviewed for ksqlDB 0.29

How to Insert Query Results into an Existing Stream in ksqlDB

This is an example of inserting a query output into another stream:

INSERT INTO florida_flights 
SELECT
    flight_id as id,
  departed_at as started_at 
FROM flights
WHERE from_airport = 'Florida'
EMIT CHANGES;

The selected fields in the query need to be compatible in name and type with the sink stream. In our example, the sink stream florida_flights was created like this:

CREATE STREAM florida_flights (
    id STRING,
  started_at TIMESTAMP
) WITH (...)

Use cases

This type of insert is useful when you need to union two streams into one.

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