We have two databases: database1
and database2
.
Everyday we want to copy from database1
all data from two tables: db1.table1
and db2.table2
to database2
to tables with the similar (not same) structure in single transaction.
Now I've following solution, but i'm not sure about single transaction:
SELECT * FROM db1.table
with ExecuteSQL
processor;PutDatabaseRecord
with pre-SQL query:DROP TABLE IF EXISTS db2.buffer_table1;
CREATE TABLE db2.buffer_table1
AS (SELECT t1.account_name, t1.cabinet_id
FROM db1.table1 t1
WHERE 1=2);
PutDatabaseRecord
with pre-SQL query.For actions above i don't really need transactional state, but in the next step I should put data from buffer tables into real tables in single transaction.
I need:
I can put all sql comands above into single ExecuteSQL
processor, but I guess it's not transactional (i didn't find any information about this).
For example after first step (delete from) error may occur while inserting data into database. And i'll lost all data that was there before and processor will throw error, but data already lost, rollback will be applied only to last failed operation. Or it's wrong?
Is it possible to do it only with Apache NiFi without stored procedure in PostgreSQL server? Any ideas?
Seem like this works (inside ExecuteSQL
):
BEGIN;
... //actions here
COMMIT;