Gunakan pendekatan yang sama seperti yang Anda jelaskan, tetapi DELETE
(atau mengelompokkan, atau memodifikasi ...) duplikat PK
di tabel temp sebelum memuat ke tabel utama.
Sesuatu seperti:
CREATE TEMP TABLE tmp_table
ON COMMIT DROP
AS
SELECT *
FROM main_table
WITH NO DATA;
COPY tmp_table FROM 'full/file/name/here';
INSERT INTO main_table
SELECT DISTINCT ON (PK_field) *
FROM tmp_table
ORDER BY (some_fields)
Detail:CREATE TABLE AS
, COPY
, DISTINCT ON