Flink SQL:INSERT Statements

本文介绍了Flink SQL中的INSERT语句,包括如何通过TableEnvironment执行单个或多个INSERT语句,如何在SQL CLI中运行INSERT语句,以及INSERT语句的不同用法,如从查询中插入数据、插入值到表中以及一次插入多张表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

INSERT Statement

INSERT statements are used to add rows to a table.
INSERT语句用于向表中添加行。

Run an INSERT statement

Java
Single INSERT statement can be executed through the executeSql() method of the TableEnvironment. The executeSql() method for INSERT statement will submit a Flink job immediately, and return a TableResult instance which associates the submitted job. Multiple INSERT statements can be executed through the addInsertSql() method of the StatementSet which can be created by the TableEnvironment.createStatementSet() method. The addInsertSql() method is a lazy execution, they will be executed only when StatementSet.execute() is invoked.
单个INSERT语句可以通过TableEnvironment的executeSql()方法执行。执行INSERT语句的executeSql()方法将立即提交Flink作业,并返回与提交的作业关联的TableResult实例。可以通过TableEnvironment.createStatementSet()创建的StatementSet的addInsertSql()方法执行多个INSERT语句。addInsertSql()方法是一个延迟执行,它们将仅在调用StatementSet.execute()时执行。

The following examples show how to run a single INSERT statement in TableEnvironment, run multiple INSERT statements in StatementSet.
以下示例演示如何在TableEnvironment中运行单个INSERT语句,在StatementSet中运行多个INSERT。

TableEnvironment tEnv = TableEnvironment.create(...);

// register a source table named "Orders" and a sink table named "RubberOrders"
tEnv.executeSql("CREATE TABLE Orders (`user` BIGINT, product VARCHAR, amount INT) WITH (...)");
tEnv.executeSql("CREATE TABLE RubberOrders(product VARCHAR, amount INT) WITH (...)");

// run a single INSERT query on the registered source table and emit the result to registered sink table
TableResult tableResult1 = tEnv.executeSql(
  "INSERT INTO RubberOrders SELECT product, amount FROM Orders WHERE product LIKE '%Rubber%'");
// get job status through TableResult
System.out.println(tableResult1.getJobClient().get().getJobStatus());

//----------------------------------------------------------------------------
// register another sink table named "GlassOrders" for multiple INSERT queries
tEnv.executeSql("CREATE TABLE GlassOrders(product VARCHAR, amount INT) WITH (...)");

// run multiple INSERT queries on the registered source table and emit the result to registered sink tables
StatementSet stmtSet = tEnv.createStatementSet();
// only single INSERT query can be accepted by `addInsertSql` method
stmtSet.addInsertSql(
  "INSERT INTO RubberOrders SELECT product, amount FROM Orders WHE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值