title: Creating a merge statement from a conditional INSERT select
body: <p>I'm trying to create a merge statement where I keep all the values in my <code>FINAL_TABLE</code> before the column <code>DATE</code> is &gt;= today's date,
  and insert new values from today's date from my <code>LANDING_TABLE</code>.</p>
  <p>The working example with a DELETE and INSERT statement can be seen here:</p>
  <pre><code>DELETE FROM FINAL_TABLE
  WHERE &quot;DATE&quot; &gt;= CURRENT_DATE()
  
  INSERT INTO FINAL_TABLE
      SELECT X, Y.value :: string AS Y_SPLIT, &quot;DATE&quot;, &quot;PUBLIC&quot;
      FROM LANDING TABLE, LATERAL FLATTEN (INPUT =&gt; STRTOK_TO_ARRAY(LANDING_TABLE.column, ', '), OUTER =&gt; TRUE) y
      WHERE &quot;PUBLIC&quot; ILIKE 'TRUE' AND &quot;DATE&quot; &gt;= CURRENT_DATE()
  </code></pre>
  <p>I'd like to keep the FLATTEN statement and the WHERE conditions while having the whole statement in a single MERGE statement.</p>
  <p>Is it possible or should I first create a temporary table with the values I want to insert and then use that in the merge statement?</p>