How to bulk insert only new rows in PostreSQL
Import data COPY everything to a temporary staging table and insert only new titles into your target table. CREATE TEMP TABLE tmp(title text); COPY tmp FROM ‘path/to/file.csv’; ANALYZE tmp; INSERT INTO tbl SELECT DISTINCT tmp.title FROM tmp LEFT JOIN tbl USING (title) WHERE tbl.title IS NULL; IDs should be generated automatically with a serial column … Read more