I see I can only insert into JDBC table with select from another table,
something like:
tEnv.executeSql("INSERT INTO Customers SELECT customer_number, pid_no, name
FROM another_table");
But what if I want to insert row that I created within Flink? For instance I
made some calculation and I want to insert completely new row into table (it
does not exist in any table)? Something like:
tEnv.executeSql("INSERT INTO Customers (customer_number, pid_no, name) VALUES
(4000, 100, 'customer')");
?
One more question - Flink dynamic table is just a link to real data (right?).
Is there any way to create empty table? Or table with some values defined in
Flink?
Thanks for help,
M.
Sent: Friday, September 09, 2022 at 3:03 PM
From: [email protected]
To: [email protected]
Subject: Insert into JDBC table
Why this INSERT does not insert row in table (jdbc connection works, I can
create 'Customers' table from MySQL table)?
tEnv.executeSql("CREATE TABLE Customers ("
+ " customer_number INT, "
+ " pid_no INT, "
+ " name STRING, "
+ " PRIMARY KEY (customer_number) NOT ENFORCED"
+ " ) WITH ( "
+ " 'connector' = 'jdbc', "
+ " 'url' = 'jdbc:mysql://localhost:3306/test', "
+ " 'username' = 'some_user', "
+ " 'table-name' = 'customers', "
+ " 'password' = ''"
+ ")");
//This insert does nothing (not even error)
tEnv.executeSql("INSERT INTO Customers (customer_number, pid_no, name) VALUES
(4000, 100, 'customer')");
According to documentation
(https://nightlies.apache.org/flink/flink-docs-master/docs/connectors/table/jdbc/)
it should work.
Regards,
Mike