title: Merge statement in SNOWFLAKE database on primary key error
body: <p>I am kinda confused with the way merge statement has to be written in my scenario to load data from a table into dimension and fact tables.</p>
  <p>Below is the merge statement where I am trying to load data into my DIM product table from the JSON table but I am getting NULL values loaded.</p>
  <p><strong>Am I doing something wrong with the merge and should I not merge on primary key and instead on the fields like cityname</strong></p>
  <p>I am having the same issue while trying to load data into the fact table</p>
  <p>Could someone please help?</p>
  <pre><code>merge into dim_product as a using (select productID, product from jsontable) as b
  on b.productID = a.productID
  when matched then update a.productID = b.productID
  when not matched then insert (productID, product) values (b.productID, b.product));
  </code></pre>
  <p>Below is the Existing Dimension Products table</p>
  <p><a href="https://i.stack.imgur.com/rPKv3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rPKv3.png" alt="enter image description here" /></a></p>
  <p>Below is the sample JSON from which I am trying to merge and insert the new record <strong>Mango</strong> into my DIM table and also populate the <strong>PRODUCTID</strong> into my fact table</p>
  <p><a href="https://i.stack.imgur.com/3QOIK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3QOIK.png" alt="enter image description here" /></a></p>
  <p>Below is the fact table</p>
  <p><a href="https://i.stack.imgur.com/izcdo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/izcdo.png" alt="enter image description here" /></a></p>