title: loops and inserts PostgreSQL PGADMIN III
body: <p>I'm a total SQL noob. I am trying to create a new record in a table for each of a partial list from another table. I can't get the loop syntax right. Basically, here's pseudocode for what I'm trying to do:</p>
  
  <pre><code>FOR EACH item FROM "SCHEMA1".table1.field1 WHERE table1.field2 = 500 OR table1.field2 = 900 LOOP
  USE "SCHEMA1".table2
  INSERT INTO "SCHEMA1".table2 (column1, column2, column3)
    VALUES (row_number(), table1.field1, "done")
  END LOOP;
  </code></pre>
  
  <p>table1 has about 4300 records and I want one field from about 90 specific records copied into another existing table as new records (with additional data). Both tables exist in a single schema but the servers have a dozen or so with duplicate tables and fields.</p>
  
  <p>Thanks for taking the time to educate an old noob.</p>