Q: Upsert Statement Deleting Non-Conflicting Data (Postgres) I am currently attempting to run a function withing Postgres to update my production table from my staging table. I have been able to get the function to run, but not as I intended it to do. 
My current goal with the use of this statement is to perform an Upsert, but what is happening is that all the data that doesn't exist within the date range of what's being transferred from staging to production is being deleted. This isn't ideal. 
INSERT INTO xyz.crimsontwreng 

SELECT *
FROM xyz.stg_crimsontwreng 
ON CONFLICT (date, monitorid)
DO UPDATE SET
  replies = excluded.replies,
  retweets = excluded.retweets,
  mentions = excluded.mentions;

Curious to know what I am missing from this function to prevent data from outside the date range being deleted. I have year to date data, and now I just have the last seven days worth of information my python script retrieved this morning.
If it helps my function is setup as such. 
RETURNS text
LANGUAGE 'sql'
VOLATILE
PARALLEL UNSAFE
COST 100

*Appears that this issue might be related to a datetime issue with the date field I am calling. 
