title: Insert inside of a case statement
body: <p>I have a table of data in which I have decided I want to change the way I save and extract data. It was a poor design on my part and now I need to fix it without going through every row manually. I want to change the primary keys from ItemID and VendorID to ItemID and Function. I want a separate record for each function+id rather than a combined record if the vendor id is the same for both functions. I will be eliminating the use of the other_functions column.</p>
  
  <p>Basically my table looks something like this:</p>
  
  <pre><code>ItemID(PK)| VendorID(PK) |   Function   |   other_functions
  _______________________________________________________
      1     |    23        |    cooking   |     
      1     |    36        |    cleaning  |
      2     |    45        |    cooking   |   cleaning
  </code></pre>
  
  <p>After I update the PK's, How do I go through the table, and for each record where other_functions = 'cleaning', insert a new row to make it look more like this:</p>
  
  <pre><code>ItemID(PK)| VendorID     | Function(PK)   
  ______________________________________
      1     |    23        |    cooking     
      1     |    36        |    cleaning 
      2     |    45        |    cooking
      2     |    45        |    cleaning
  </code></pre>
  
  <p>I am using PostgreSQL. It seems like it should be a simple solution but haven't been able to find the answer I am looking for. Can this be done with just an insert + case statement?</p>