What are some example workflows for automatic loading of Foreign tables into tables each month?
0
votes
0
answers
17
views
I have a PostgresDB and PgAdmin4 installed. Beginning of each month a database with monthly payments is loaded as a Foreign table payments and a data for monthly customer numbers is loaded in Foreign table customers. On the 5th of the month I run code taking the previous month data from my foreign table payments and joining it with the data from my foreign table Customers and loading it in a historical table called Finance. So on the 5th of each month (in this case January) I have to write a code
that is
**SELECT A.cust_number, A.transaction_amount, B.cust_number_of_accounts
FROM payments A
LEFT JOIN customers B ON A.cust_number = B.cust_number
WHERE A.transaction_date > '2024-11-30' (this should change each month);**
And then insert the result into Finance
Also I have to run a code inserting the separate foreign tables into historical tables.
**INSERT INTO payments_historical
SELECT * from payments
WHERE A.transaction_date > '2024-11-30' (this should change each month);**
**INSERT INTO customers_historical
SELECT * from customers
WHERE A.date > '2024-11-30' (this should change each month);/*the customer table has a date the beginning of the month*/**
How to make this loading automatic but also checking whether the data has been correctly loaded into the foreign table to being with. Also changing the where clause as needed in order to only load the data for 1 month.
Asked by IKNv99
(1 rep)
Jan 17, 2025, 06:53 PM
Last activity: Jan 17, 2025, 06:54 PM
Last activity: Jan 17, 2025, 06:54 PM