The previous KSQL statement makes no assumptions about the Kafka message key
in the underlying Kafka topic. If the value of the message key in the topic
is the same as one of the columns defined in the stream, you can specify the
key in the WITH clause of the CREATE STREAM statement.

For example, if the Kafka message key has the same value as the pageid
column, you can write the CREATE STREAM statement like this:

Use the CREATE STREAM AS SELECT statement to create a persistent query stream
from an existing stream.

CREATE STREAM AS SELECT creates a stream that contains the results from a
SELECT query. KSQL persists the SELECT query results into a corresponding new
topic. A stream created this way represents a persistent, continuous, streaming
query, which means that it runs until you stop it explicitly.

Note

A SELECT statement by itself is a non-persistent continuous query. The result
of a SELECT statement isn't persisted in a Kafka topic and is only printed in the
KSQL console. Don't confuse persistent queries created by CREATE STREAM AS SELECT
with the streaming query result from a SELECT statement.

Use the SHOW QUERIES statement to list the persistent queries that are running
currently.

Use the PRINT statement to view the results of a persistent query in the KSQL CLI.
Press CTRL+C to stop printing records. When you stop printing, the query continues
to run.

Use the TERMINATE statement to stop a persistent query. Exiting the KSQL CLI
does not stop persistent queries. Your KSQL servers continue to process the
queries, and queries run continuously until you terminate them explicitly.

To stream the result of a SELECT query into an existing stream and its
underlying topic, use the INSERT INTO statement.

Note

The CREATE STREAM AS SELECT statement doesn't support the KEY property.
To specify a KEY field, use the PARTITION BY clause. For more information,
see Partition Data to Enable Joins.

The following KSQL statement creates a pageviews_intro stream that contains
results from a persistent query that matches "introductory" pages that have a
pageid value that's less than Page_20: