Let's say I have to create tons of different SQL views. Having actual and target table DDLs, is it possible to programmatically automate view creation?
Example: I have 2 table DDLs:
CREATE TABLE target_ddl (
invoice_sum INTEGER,
date date DATE
);
CREATE TABLE actual_ddl (
amount INTEGER,
year INTEGER,
months INTEGER,
day INTEGER
);
What I need to do is to make actual_ddl data match the target_ddl schema, so obvious answer is view creation:
CREATE VIEW actual_ddl_as_target_ddl AS
SELECT amount AS invoice_sum,
DATE(CONCAT_WS('-', year, months, day)) AS date FROM actual_ddl;
I wrote this one manually. Thought I feel like it's possible to write java/python library which will "create SQL views based on actual and target schema". What algorithms/best practices should I look into to achieve it?