in reply to Altering SQL code from Update to Insert

Well, here's a thought, if you know all of the index values (e.g. they're in sequence and you know the highest): create an empty new table with the structure you want, insert new rows for every value of index with no values for anything but the index field, then run all of the updates - they'll simply populate the existing index rows. No muss, no fuss, no perl.

If that won't work for you, then you may want to use SQL::Parser to parse each line in the SQL file, that will turn your UPDATE statements into perl data stuctures containing the names of the table, the fields, and the values and you can use that to construct an INSERT statement where needed.

If you go the route of using regexen to read the SQL file, the complexity of that task will depend on the complexity of your string values - if any of them contain embedded single quotes, you'll need to get fancy to deal with the single-quote delimiters around the values.

  • Comment on Re: Altering SQL code from Update to Insert