I have 2 database already restored on 2 different database on the same instance, call it geo
and restore1
the schema is identical, the only difference is that geo
database contain only records before <= 2023-11-23
and after >= 2023-12-01
, while restore1
contains <= 2023-11-30
,
how can I copy those missing values (2023-11-23
until 2023-11-30
from restore1
to geo
database) for each table easily?
one way that I could think of is, create a program, for each table, selecting latest id before 2023-11-24
from geo
(call it X
), then select all record with id greater than X
, and then insert it manually to geo
database.
Is there any simpler way?
there's hundreds of tables, but most of them something like this:
restore1=# \d station_logs_599
Table "public.station_logs_599"
Column | Type | Collation | Nullable | Default
------------------------+--------------------------------+-----------+----------+------------------------------------------
id | integer | | not null | nextval('station_logs_id_seq'::regclass)
created_at | timestamp(6) without time zone | | |
updated_at | timestamp(6) without time zone | | |
deleted_at | timestamp(6) without time zone | | |
submitted_at | timestamp(6) without time zone | | not null |
sequence | integer | | |
level_sensor | double precision | | |
accel_x | double precision | | |
accel_y | double precision | | |
accel_z | double precision | | |
power_current | double precision | | |
ip_address | character varying(50) | | |
log_type | integer | | |
station_id | integer | | not null |
power_voltage | double precision | | |
data | jsonb | | |
is_deleted | boolean | | not null | false
temperature | double precision | | |
wind_speed | double precision | | |
soil_moisture | double precision | | |
wind_direction | double precision | | |
raindrop | double precision | | |
humidity | integer | | |
barometric_pressure | double precision | | |
wind_speed_average | double precision | | |
wind_gust | double precision | | |
wind_direction_average | double precision | | |
rain_rate | double precision | | |
Indexes:
"station_logs_599_epoch" btree (date_part('epoch'::text, submitted_at))
"station_logs_599_submitted_at" btree (submitted_at)
"uniq_sid_sat_599" UNIQUE CONSTRAINT, btree (submitted_at)
Foreign-key constraints:
"station_logs_599_station_fk" FOREIGN KEY (station_id) REFERENCES stations(id)
IDENTITY
specification for theid
column? Click on edit and add the details to your question. Thanks.DATE(submitted_at), count(1)
, between both table, if the same then skip, if not select raw value from source, then insert it to destination.