Click to copy

• Reviewed for ksqlDB 0.29

How to Insert Values into Stream in ksqlDB

Here is an example of an insert statement in ksqlDB:

INSERT INTO scores_stream (
  student_id,
  name,
  score
) VALUES (
  1,
  'Alice',
  3.5
);

This statement will produce a new message to the underlying topic and be queryable by using the stream.

Make sure the name and type of the fields in the stream match with the values passed. As a reference, the scores_stream stream was created using this statement:

CREATE STREAM scores_stream (
  student_id BIGINT,
  name STRING,
  score DOUBLE
) WITH (
  KAFKA_TOPIC = 'scores_topic',
  VALUE_FORMAT = 'JSON',
  PARTITIONS = 10
);

Setting the record timestamp

Optionally, you can also set the record timestamp by passing a value as ROWTIME like this.

INSERT INTO scores_stream (
  ROWTIME,
  student_id,
  name,
  score
) VALUES (
  1658334086899,
  1,
  'Alice',
  3.5
);
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