This article explains the method that PostgreSQL uses to implement upsert for automatically separating new data from old data.
This article introduces a new function of PostgreSQL 9.5 called Upsert (INSERT ON CONFLICT DO).