Get Started Free
‹ Back to courses
course: ksqlDB 101

Hands On: Push Queries and Pull Queries

2 min
Allison

Allison Walther

Integration Architect (Presenter)

Robin Moffatt

Robin Moffatt

Principal Developer Advocate (Author)

Hands On: Push Queries and Pull Queries

Push and pull queries are easier to understand if you view them in action.

This exercise continues with the PERSON_STATS table from Hands On: Stateful Aggregations (Materialized Views).

Run Push and Pull Queries

  1. Issue a pull query on the PERSON_STATS table:

    SELECT LATEST_LOCATION, LOCATION_CHANGES, UNIQUE_LOCATIONS
    FROM PERSON_STATS WHERE PERSON = 'Allison';

    Click Run query and view the returned LATEST_LOCATION, LOCATION_CHANGES, and UNIQUE_LOCATIONS.

  2. Now issue a push query on the PERSON_STATS table:

    SELECT LATEST_LOCATION, LOCATION_CHANGES, UNIQUE_LOCATIONS
    FROM PERSON_STATS WHERE PERSON = 'Allison' EMIT CHANGES;
  3. Next, in another window, or perhaps in the CLI, insert some more data into the MOVEMENTS stream on which the PERSON_STATS table is based:

    INSERT INTO MOVEMENTS VALUES ('Robin', 'York');
    INSERT INTO MOVEMENTS VALUES ('Robin', 'Leeds');
    INSERT INTO MOVEMENTS VALUES ('Allison', 'Denver');
    INSERT INTO MOVEMENTS VALUES ('Robin', 'Ilkley');
    INSERT INTO MOVEMENTS VALUES ('Allison', 'Boulder');

    You should see new entries, reflecting this new data, appearing in the results of the push query from step 2.

  4. Kill the query with Stop. Push queries will run until they're manually killed.

Use the promo code KSQLDB101 to get $25 of free Confluent Cloud usage

Be the first to get updates and new content

We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.

Hands On: Push Queries and Pull Queries

Push and pull queries are easier to understand when you see them in action. First, I wanna review the structure of the PERSON_STATS table from the last lesson. We're gonna issue a pull query on the PERSON_STATS table. You'll see the latest location, latest location changes, and unique locations. Next, we'll issue a push query on the PERSON_STATS table, where the person equals Allison. You'll see that the current aggregate results appear and that the query is still running. Off-screen, I'm gonna go and add a new movement event. Look, you see a new aggregate record show up and another new aggregate record show up. Push queries will run continuously until they're manually killed. Let's go ahead and kill this query. That's all for demonstrating push and pull queries.