title: Accidentally detected all data from a table, insert dummy data to table using loop psql
body: <p>I had accidentally deleted most of the rows in my Postgres table (data is not important its in my test environment, but I need a dummy data to be insert in to these table).</p>
  <p>Let us take three tables,</p>
  <ol>
  <li><code>MAIN_TABLE(main_table_id, main_fields)</code></li>
  <li><code>ADDRESS_TABLE(address_table_id, main_table_id, address_type, other_fielsds)</code></li>
  <li><code>CHAID_TABLE(chaid_table_id,main_table_id, shipping_address_id, chaild_fields)</code></li>
  </ol>
  <p>I had accidentally  deleted most of the data from ADDRESS_TABLE.</p>
  <ol>
  <li><p>ADDRESS_TABLE has a foreign key from MAIN_TABLE ,i.e. main_table_id. for each row in MAIN_TABLE there is two entries in ADDRESS_TABLE, in which one entry is its address_type  is &quot;billing/default&quot; and other entry is for  address_type &quot;shipping&quot;.</p>
  </li>
  <li><p>CHAID_TABLE has two foreign keys one from MAIN_TABLE, i.e. main_table_id and other from ADDRESS_TABLE i.e., shipping_address_id. this shipping_address_id is address id of ADDRESS_TABLE, its address_type is  shipping and ADDRESS_TABLE.main_table_id = CHAID_TABLE.main_table_id.</p>
  </li>
  </ol>
  <p>These are the things that I needed.</p>
  <ol>
  <li>I need to create two dummy address entries for each raw in MAIN_TABLE one is of address type &quot;billing/default&quot; and other is of type &quot;shipping&quot;.</li>
  <li>I need to insert address_table_id to the CHAID_TABLE whose ADDRESS_TABLE.main_table_id = CHAID_TABLE.main_table_id. and addres_type =&quot;shipping&quot;</li>
  </ol>
  <p>if first is done I know how to insert second, because it is a simple insert query. I guess.
  it can be done like,</p>
  <pre><code>UPDATE CHAID_TABLE 
    SET shipping_address_id = ADDRESS_TABLE.address_table_id 
  FROM ADDRESS_TABLE  
  WHERE ADDRESS_TABLE.main_table_id = CHAID_TABLE.main_table_id 
    AND ADDRESS_TABLE.addres_type ='shipping';
  </code></pre>
  <p>for doing first one i can use loop in psql, ie loop through all the entries in MAIN_TABLE and insert two dummy rows for each rows. But I don't know how to do these please help me to solve this.</p>