title: Merge in postgres
body: <p>Am trying to convert below oracle query to postgres,</p>
  
  <pre><code>MERGE INTO table1 g
  USING (SELECT distinct g.CDD , d.SGR
  from  table2 g, table3 d
  where g.IDF = d.IDF) f
  ON (g.SGR = f.SGR and g.CDD = f.CDD)
     WHEN NOT MATCHED THEN
     INSERT (SGR, CDD)
     VALUES (f.SGR, f.CDD);
  </code></pre>
  
  <p>I made changes as below compatible to postgres:</p>
  
  <pre><code>WITH f AS (
  SELECT distinct g.CDD , d.SGR
  from  table2 g, table3 d
  where g.IDF = d.IDF
  ),
  upd AS (
  update table1 g 
  set 
  SGR = f.SGR , CDD = f.CDD 
  FROM f where g.SGR = f.SGR  and g.CDD = f.CDD  
  returning g.CDD, g.SGR
  )
  INSERT INTO table1(SGR, CDD ) SELECT f.SGR, f.CDD FROM f;
  </code></pre>
  
  <p>But am doubtful ,my oracle query is not updating any columns if data matched , but am unable to convert it accordingly . Can anyone help me to correct it ?</p>