Inserting events

One fundamental operation for working with collections is populating them with events. There are a number of ways to do this:

  • Use ksqlDB’s INSERT INTO VALUES syntax. This is the simplest approach.
  • Use the Apache Kafka® clients to write data to the underlying topics.
  • Use connectors to source data from external systems.

The INSERT INTO VALUES statement inserts an event into an existing stream or table. This statement is similar to what you would find in Postgres. You specify:

  • the collection to insert values into;
  • the sequence of columns that you have values for;
  • the values.

The column names and values are zipped up to form a new event, which is serialized in the same format as the collection. The following example statement inserts an event that has two columns into a collection named all_publications:

1
INSERT INTO all_publications (author, title) VALUES ('C.S. Lewis', 'The Silver Chair');

Any column that doesn't get a value explicitly is set to null. If no columns are specified, a value for every column is expected in the same order as the schema, with any key columns first. If columns are specified, the order doesn’t matter. You can specify ROWTIME as an explicit column, but it’s not required when you omit the column specifications, defaulting to the local machine time.

For more information, see INSERT INTO VALUES.


Last update: 2020-10-19