Click to copy

• Reviewed for ksqlDB 0.29

How to Query a Table in ksqlDB

Use SELECT statements to query a table. This is an example:

SELECT * FROM scores_table;
+------------+-------+------+
|STUDENT_ID  |NAME   |SCORE |
+------------+-------+------+
|1           |Alice  |4.0   |
|2           |Bob    |5.0   |

Pull queries

The previous example is a pull query. Pull queries are the equivalent of the queries you find in relational databases or data warehouse databases. They go through the data and return a result.

Push queries – Your new friend

Push queries process the underlying Apache Kafka topic from a particular offset and listen for any new records once they reach the end of the topic. They emit results as they get processed.

SELECT * 
FROM scores_table 
EMIT CHANGES;
Note the EMIT CHANGES modifier - you transform a pull query into a push query by adding it.

In interactive command line sessions, push queries will stream the results as they are produced until you hit CTRL+C (since they block your terminal while waiting for any new records coming from the source).

Push queries are useful when used to create derived tables or streams, as they will keep the new entity up to date as new records are produced in the source.

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