how to link old and new IDs when migrating data from one table to another in postgresql
src: Stackoverflow
When proceeding a database migration, I often had to create a temporary table that will contains the data from the old database.
However, after the migration, I still need to have links between the old IDs and the new IDs for various post migration operation.
This post is about creating the table containing the linked ids.
Imagine we have the following:
I want to migrate to this new table:
With some CTE magic, I should be able to get my temp table that contains the links:
And VOILA, this SQL query will return the link between the old and new IDs.
Check this sqlfiddle.