Linux, WebDev and other…

Convert single mysql insert statements to one statement with multiple VALUES lists

I needed to convert multiple mysql insert statements to statements with multiple VALUE lists to insert several rows at a time. I have not found any tool for that, so I wrote this script in Python. Thankfully I found a non-validating SQL parser module for Python, so this task became very easy. You must install it, before using this script.

Example input data:

 Example output data (number of rows in one statement is defined by user):

The script:


The script requires input data file, output data file and number of rows per group. It’s not very fast, but it’s doing its job. Percentage progress is displayed during conversion.







Leave a Reply

Your email address will not be published. Required fields are marked *