I have several tables, and I need to create a matching _hist
table for each one. For example if I have:
CREATE TABLE public.test (
first text,
middle text,
"last" text,
"timestamp" timestamp without time zone NOT NULL default now()
);
I would like to create:
CREATE TABLE public.test_hist (
"action" text,
"user" text,
first text,
middle text,
"last" text,
"timestamp" timestamp without time zone NOT NULL default now()
);
I'm in the initial phase of the project I'm working on, and requirements keep changing.
As I run the changed script that drops and re-creates tables, I would like for _hist
tables to somehow get automatically generated, so I don't need to make the same change in two places.
Is it possible to do that with SQL at the end of my table creation script?
I have postgreSQL 10.
Or should I do it in python?