I have a table people
with less than 100,000 records and I have taken a backup of this table using the following:
create table people_backup as select * from people
I add some new records to my people
table over time, but eventually I want to merge the records from my backup table into people
. Unfortunately I cannot simply DROP
my table as my new records will be lost!
So I want to update the records in my people
table using the records from people_backup
, based on their primary key id
and I have found 2 ways to do this:
- MERGE the tables together
- use some sort of fancy correlated update
Great! However, both of these methods use SET
and make me specify what columns I want to update. Unfortunately I am lazy and the structure of people
may change over time and while my CTAS
statement doesn't need to be updated, my update/merge script will need changes, which feels like unnecessary work for me.
Is there a way merge entire rows without having to specify columns? I see here that not specifying columns during an INSERT
will direct SQL to insert values by order, can the same methodology be applied here, is this safe?
NB: The structure of the table will not change between backups