Statement Set

Confluent Cloud for Apache Flink®️ enables executing multiple SQL statements as a single, optimized statement via Statement Sets.

Syntax

EXECUTE STATEMENT SET
BEGIN
  -- one or more INSERT INTO statements
  { INSERT INTO <select_statement>; }+
END;

Description

Statement Sets are a feature of Confluent Cloud for Apache Flink®️ that allow you to execute a set of SQL statements as a single, optimized statement. This is useful when you have multiple SQL statements that share common intermediate results, as it enables you to reuse those results and avoid unnecessary computation.

To use Statement Sets, you enclose one or more SQL statements in a block and execute them as a single unit. All statements in the block are optimized and executed together as a single Flink statement. Statement Sets are particularly useful when you have multiple INSERT INTO statements that read from the same table or share intermediate results. By executing these statements together as a single statement, you can avoid redundant computation and improve performance.

Example

The following query results in a single statement being executed which reads from table orders. In case the status is completed, the product and quantity is written to table sales. If the status is returned, the product and quantity are written to table returns.

EXECUTE STATEMENT SET
BEGIN
   INSERT INTO `sales` (product, quantity) SELECT product, quantity FROM orders WHERE status = 'completed';
   INSERT INTO `returns` (product, quantity) SELECT product, quantity FROM orders WHERE status = 'returned';
END;