All Products
Search
Document Center

Realtime Compute for Apache Flink:INSERT INTO

Last Updated:Mar 26, 2026

Use the INSERT INTO statement to write to one or more sinks in a job.

SQL hints support

The INSERT statement supports SQL hints with the OPTIONS keyword to pass parameters to a sink table. For more information, see SQL Hints.

Write to a single sink

Run a single INSERT INTO statement directly, without a wrapper.

-- Create a source table.
CREATE TEMPORARY TABLE datagen_source (
  name VARCHAR,
  score BIGINT
) WITH (
  'connector' = 'datagen'
);

-- Create a sink table.
CREATE TEMPORARY TABLE blackhole_sink (
  name VARCHAR,
  score BIGINT
) WITH (
  'connector' = 'blackhole'
);

-- Write transformed data to the sink.
INSERT INTO blackhole_sink SELECT UPPER(name), score FROM datagen_source;

Write to multiple sinks

Wrap multiple INSERT INTO statements in a statement set using BEGIN STATEMENT SET; and END;.

Important

A statement that writes to multiple sinks must start with BEGIN STATEMENT SET; and end with END;.

The following example writes data to two sinks from the same source.

-- Create a source table.
CREATE TEMPORARY TABLE datagen_source (
  name VARCHAR,
  score BIGINT
) WITH (
  'connector' = 'datagen'
);

-- Create sink table A.
CREATE TEMPORARY TABLE blackhole_sinkA (
  name VARCHAR,
  score BIGINT
) WITH (
  'connector' = 'blackhole'
);

-- Create sink table B.
CREATE TEMPORARY TABLE blackhole_sinkB (
  name VARCHAR,
  score BIGINT
) WITH (
  'connector' = 'blackhole'
);

-- Write to both sinks in a single optimized execution.
BEGIN STATEMENT SET;      -- Required for writing to multiple sinks.
INSERT INTO blackhole_sinkA
  SELECT UPPER(name), sum(score)
  FROM datagen_source
  GROUP BY UPPER(name);
INSERT INTO blackhole_sinkB
  SELECT LOWER(name), max(score)
  FROM datagen_source
  GROUP BY LOWER(name);
END;                      -- Required for writing to multiple sinks.