title: Inserting Data in Postgres table when another table has been inserted with multiple rows
body: <p>I am new to Postgres. My problem is that I want to insert some <em>new rows</em> in "target table" when these <em>new rows</em> are inserted in a "source table".
  I wrote a trigger to do exactly that but whenever the source is inserted with say <em>7 new rows</em> then the trigger inserts <em>7x7 = 49 rows</em> in target. Next if I insert <em>3 more new rows</em> in source then the target becomes <em>49+3x10 = 79</em>. 
  What am I doing wrong..??</p>
  
  <p>Trigger function:  </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.rec_insert()
  RETURNS trigger AS
  $BODY$  
  BEGIN  
  INSERT INTO target_table ("TIME","REGION","CITY","DISTRICT","Population")
  SELECT NEW."TIME",NEW."REGION",NEW."CITY",NEW."DISTRICT",(100*(NEW."SAMPLES_MALE_Available")/(NULLIF((NEW."Total_AVAIL"-NEW."Female_AVAIL"),0)))
  FROM source_table;
  RETURN NEW; 
  END;
  $BODY$
  LANGUAGE plpgsql;
  </code></pre>
  
  <p>And my trigger is </p>
  
  <pre><code>CREATE TRIGGER ins_same_rec  
  AFTER UPDATE  
  ON source_table
  FOR EACH ROW  
  EXECUTE PROCEDURE rec_insert();
  </code></pre>