sql >> Base de Datos >  >> RDS >> PostgreSQL

Para ignorar claves duplicadas durante 'copiar desde' en postgresql

Use el mismo enfoque que describió, pero DELETE (o agrupar, o modificar...) duplicar PK en la tabla temporal antes de cargar en la tabla principal.

Algo como:

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)

Detalles:CREATE TABLE AS , COPY , DISTINCT ON