Basicly my situation is that I have a log file of SQL update commands and I need to recreate the table from scratch

That is only going to work if every single column of every single row in that table has been updated recently (within your log). You will not be able to recreate rows or columns within rows that have not been updated.

The only time I want to change an Update statement into an Insert statement is the first time the key shows up

You can just go ahead and try to update. If the update reports 0 affected rows (DBI->do tells you this), you have to change it to an insert and run it again. This way, you can let the DB keep track of "first times".

The second problem is that I need to be able to completely restructure the command

You could get away with a simplified insert (which just creates the row) and then running the original update. That would reduce the amount of intelligence you have to put into that update-to-insert query rewriter.


In reply to Re: Altering SQL code from Update to Insert by Thilosophy
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.