SQL quick reference
For detailed descriptions of ksqlDB SQL statements and keywords, see the ksqlDB API reference.
For details on SQL syntax, see ksqlDB syntax reference.
ADVANCE BY¶
Specify the duration of a "hop" in a HOPPING window. For more information, see Time and Windows in ksqlDB.
1 2 |
|
ALTER SYSTEM¶
Change a system-level property value (only available in Confluent Cloud).
1 |
|
ALTER STREAM¶
Add new columns to a stream. This is not supported for streams defined using queries
(CREATE STREAM ... AS
).
1 2 3 4 |
|
ALTER TABLE¶
Add new columns to a table. This is not supported for tables defined using queries
(CREATE TABLE ... AS
)
1 2 3 4 |
|
AND / OR¶
Logical AND/OR operators in a WHERE clause. For more information, see SELECT.
1 2 3 4 |
|
AS¶
Alias a column, expression, or type. For more information, see Create a table.
1 2 |
|
ASSERT¶
Assert values, stream, table, or tombstones.
1 |
|
ASSERT SCHEMA¶
Assert the existence or non-existence of a schema.
1 |
|
ASSERT TOPIC¶
Assert the existence or non-existence of a topic.
1 |
|
BETWEEN¶
Constrain a value to a specified range in a WHERE clause.
1 |
|
The BETWEEN operator is used to indicate that a certain value must be within a specified range, including boundaries. ksqlDB supports any expression that resolves to a numeric or string value for comparison.
The following push query uses the BETWEEN clause to select only records
that have an event_id
between 10 and 20.
1 2 3 4 |
|
CASE¶
Select a condition from one or more expressions.
1 2 3 4 5 6 7 8 9 |
|
ksqlDB supports a searched
form of CASE expression. In this form, CASE
evaluates each boolean condition
in WHEN clauses, from left to right.
If a condition is true, CASE returns the corresponding result. If none of
the conditions is true, CASE returns the result from the ELSE clause. If
none of the conditions is true and there is no ELSE clause, CASE returns null.
The schema for all results must be the same, otherwise ksqlDB rejects the statement.
The following example push query uses a CASE expression.
1 2 3 4 5 6 7 8 |
|
See CASE in action
CAST¶
Change the type of an expression to a different type.
1 |
|
You can cast an expression's type to a new type by using CAST.
The following example query converts a numerical count, which is a BIGINT, into
a suffixed string, which is a VARCHAR. For example, the integer 5
becomes
5_HELLO
.
1 2 3 4 |
|
CREATE CONNECTOR¶
Create a new connector in the Kafka Connect cluster. For more information, see CREATE CONNECTOR.
1 2 |
|
See CREATE CONNECTOR in action
CREATE STREAM¶
Register a stream on a Kafka topic. For more information, see CREATE STREAM.
1 2 |
|
CREATE STREAM AS SELECT¶
Create a new materialized stream and corresponding Kafka topic, and stream the result of the query into the topic. For more information, see CREATE STREAM AS SELECT.
1 2 3 4 5 6 7 8 9 10 11 |
|
CREATE TABLE¶
Register a stream on a Kafka topic. For more information, see CREATE TABLE.
1 2 |
|
CREATE TABLE AS SELECT¶
Create a new materialized table and corresponding Kafka topic, and stream the result of the query as a changelog into the topic. For more information, see CREATE TABLE AS SELECT.
1 2 3 4 5 6 7 8 9 10 |
|
CREATE TYPE¶
Alias a complex type declaration. For more information, see CREATE TYPE.
1 |
|
DEFINE¶
Defines a variable. For more information, see DEFINE.
1 |
|
DESCRIBE¶
List columns in a stream or table along with their data types and other attributes. For more information, see DESCRIBE.
1 |
|
DESCRIBE CONNECTOR¶
List details about a connector. For more information, see DESCRIBE CONNECTOR.
1 |
|
DESCRIBE FUNCTION¶
List details about a function, including input parameters and return type. For more information, see DESCRIBE FUNCTION.
1 |
|
DROP CONNECTOR¶
Delete a connector from the Connect cluster. For more information, see DROP CONNECTOR.
1 |
|
DROP STREAM¶
Drop an existing stream and optionally mark the stream's source topic for deletion. For more information, see DROP STREAM.
1 |
|
DROP TABLE¶
Drop an existing table and optionally mark the table's source topic for deletion. For more information, see DROP TABLE.
1 |
|
DROP TYPE¶
Remove a type alias from ksqlDB. For more information, see DROP TYPE.
1 |
|
EMIT CHANGES¶
Specify a push query with a continuous output refinement in a SELECT statement. For more information, see Push Queries.
1 2 3 4 |
|
EMIT FINAL¶
Specify a push query with a suppressed output refinement in a SELECT statement on a windowed aggregation. For more information, see Push Queries.
1 2 3 4 5 6 |
|
EXPLAIN¶
Show the execution plan for a SQL expression or running query. For more information, see EXPLAIN.
1 |
|
FULL JOIN¶
Select all records when there is a match in the left stream/table or the right stream/table records. Equivalent to FULL OUTER JOIN. For more information, see Join streams and tables.
1 2 3 4 |
|
GRACE PERIOD¶
Allow events to be accepted for a time period after a window ends. For more information, see Out-of-order events
1 2 3 4 |
|
GROUP BY¶
Group records in a window. Required by the WINDOW clause. Windowing queries must group by the keys that are selected in the query. For more information, see Time and Windows in ksqlDB.
1 2 3 4 |
|
HAVING¶
Extract records from an aggregation that fulfill a specified condition.
1 2 3 4 5 |
|
HEADER¶
Populate a column with the Kafka record's last header that matches the key.
1 2 |
|
HEADERS¶
Populate a column with the full list of the Kafka record's headers.
1 2 |
|
HOPPING¶
Group input records into fixed-sized, possibly overlapping windows, based on the timestamps of the records. For more information, see HOPPING.
1 2 3 4 |
|
IF EXISTS¶
Test whether a stream or table is present in ksqlDB.
1 2 |
|
IN¶
Specifies multiple OR
conditions.
1 2 3 |
|
The above is equivalent to:
1 2 3 |
|
INNER JOIN¶
Select records in a stream or table that have matching values in another stream or table. For more information, see Join streams and tables.
1 2 3 4 |
|
See INNER_JOIN in action
INSERT INTO¶
Stream the result of a SELECT query into an existing stream and its underlying Kafka topic. For more information, see INSERT INTO.
1 2 3 4 5 6 7 8 9 10 |
|
INSERT VALUES¶
Produce a row into an existing stream or table and its underlying Kafka topic based on explicitly specified values. For more information, see INSERT VALUES.
1 2 |
|
LEFT JOIN¶
Select all records from the left stream/table and the matched records from the right stream/table. For more information, see Join streams and tables.
1 2 3 4 |
|
LIKE¶
Match a string with the specified pattern.
1 2 3 |
|
The LIKE operator is used for prefix or suffix matching. ksqlDB supports
the %
wildcard, which represents zero or more characters.
The following push query uses the %
wildcard to match any user_id
that
starts with "santa".
1 2 3 4 |
|
PARTITION BY¶
Repartition a stream. For more information, see Partition Data to Enable Joins.
1 2 3 4 5 6 7 |
|
PAUSE¶
Pause a persistent query. For more information, see PAUSE.
1 |
|
PRINT¶
Print the contents of Kafka topics to the ksqlDB CLI. For more information, see PRINT.
1 |
|
RESUME¶
End a paused persistent query. For more information, see RESUME.
1 |
|
RIGHT JOIN¶
Select all records from the right stream/table and the matched records from the left stream/table. For more information, see Join streams and tables.
1 2 3 4 |
|
RUN SCRIPT¶
Execute predefined queries and commands from a file. For more information, see RUN SCRIPT.
1 |
|
SELECT (Pull Query)¶
Pull the current value from a materialized table and terminate. For more information, see SELECT (Pull Query).
1 2 3 4 5 |
|
SELECT (Push Query)¶
Push a continuous stream of updates to a stream or table. For more information, see SELECT (Push Query).
1 2 3 4 5 6 7 8 9 10 11 12 |
|
SESSION¶
Group input records into a session window. For more information, see SELECT (Push Query).
1 2 3 4 |
|
SET property¶
Assign a property value.
1 |
|
SHOW CONNECTORS¶
List all connectors in the Connect cluster. For more information, see SHOW CONNECTORS.
1 |
|
SHOW FUNCTIONS¶
List available scalar and aggregate functions available. For more information, see SHOW FUNCTIONS.
1 |
|
SHOW PROPERTIES¶
List the configuration settings that are currently in effect. For more information, see SHOW PROPERTIES.
1 |
|
SHOW QUERIES¶
List queries that are currently running in the cluster. For more information, see SHOW QUERIES.
1 |
|
SHOW STREAMS¶
List the currently defined streams. For more information, see SHOW STREAMS.
1 |
|
SHOW TABLES¶
List the currently defined tables. For more information, see SHOW TABLES.
1 |
|
SHOW TOPICS¶
List the available topics in the Kafka cluster that ksqlDB is configured to connect to. For more information, see SHOW TOPICS.
1 |
|
SHOW TYPES¶
List all custom types and their type definitions. For more information, see SHOW TYPES.
1 |
|
SHOW VARIABLES¶
List all defined variables.
1 |
|
SIZE¶
Specify the duration of a HOPPING or TUMBLING window. For more information, see Time and Windows in ksqlDB.
1 2 3 4 |
|
SPOOL¶
Store issued commands and their results in a file. For more information, see SPOOL.
1 |
|
TERMINATE¶
End a query. For more information, see TERMINATE.
1 |
|
TUMBLING¶
Group input records into fixed-sized, non-overlapping windows based on the timestamps of the records. For more information, see TUMBLING.
1 2 3 4 |
|
UNDEFINE¶
Undefines a variable.
1 |
|
UNSET property¶
Unassign a property value.
1 |
|
WHERE¶
Extract records that fulfill a specified condition. For more information, see SELECT.
1 2 3 |
|
WINDOW¶
Group input records that have the same key into a window, for operations like aggregations and joins. For more information, see WINDOW.
1 2 3 4 |
|
WINDOWSTART / WINDOWEND¶
Specify the beginning and end bounds of a window. For more information, see WINDOW.
1 2 3 4 |
|
See WINDOWSTART in action
NULLIF¶
Returns NULL if two expressions are equal, otherwise it returns the first expression.
1 2 3 |
|