-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments for MySQL to PostgreSQL Migration Tips #1061
Comments
As a substitute for 'replace into' you can also use a technique like this - for a table t whose primary key is column a: -- First we insert a row where none exists. -- Now a row with a=av definitely exists. Update it with the correct values for b and c. Here I have used Sybase/MSSQL syntax - perhaps Postgres will be a bit different with the 'select ... where not exists' but the principle is the same. First insert a row if none exists, and then update any row that exists. The advantage is that this usually doesn't require an explicit transaction. If there was no row, then the first insert succeeds and the update is a no-op. If there was a row, the insert is a no-op and the update sets the values. (Only if there is some test-and-set going on with columns b or c would you need an explicit transaction.) You can generalize this to 'insert or update' several rows at once from a temporary table, and again anyone observing the database sees a consistent picture, without the need to group the two operations in an explicit transaction. That said, Postgres's transaction handling is very good and doesn't suffer from the deadlocks which the older technology in earlier Sybase and MSSQL versions is sometimes prone to - so these careful manoeuvres to avoid explicit transaction handling are less necessary. |
P.S. in the case where the row already exists, I would expect this technique to perform somewhat better than delete+insert because there isn't maintenance work on any index which may exist on (a). |
Few years ago I publish a translation of MySQL functions to Postgres: http://okbob.blogspot.cz/2009/08/mysql-functions-for-postgresql.html |
Great write-up, David! An a big amen to your recommendation that all data migration work be scripted. It's always shortsighted to manually munge data if you're going to have to re-do that labor later on a fresh export. |
Comments for https://www.endpointdev.com/blog/2014/11/mysql-to-postgresql-migration-tips/
By David Christensen
To enter a comment:
The text was updated successfully, but these errors were encountered: