Created
January 15, 2021 21:38
-
-
Save montanalow/99dc3b5d735e6048bdb4a276738cf98a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO … | |
SELECT * FROM temp_staging_table -- first prepare the data by preloading into a temp table | |
ON CONFLICT … DO UPDATE SET … -- upsert on the primary key | |
WHERE updated_at <= excluded.updated_at -- ensure idempotent jobs | |
AND ( -- only write new distinct data | |
column_1 IS DISTINCT FROM excluded.column_1 OR | |
column_2 IS DISTINCT FROM excluded.column_2 OR | |
… | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment