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.


In reply to Re: Altering SQL code from Update to Insert by jZed
in thread Altering SQL code from Update to Insert by AFritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.