postgresql ignore duplicate on insert code example
Example 1: query to remove duplicate records in postgresql server
DELETE FROM
basket a
USING basket b
WHERE
a.id < b.id
AND a.fruit = b.fruit;
Example 2: To ignore duplicate keys during 'copy from' in postgresql
create temp table tmp_table on commit drop as select * from brand with no data;
copy tmp_table (name,slug) from '/var/lib/postgresql/data/Brands.csv' DELIMITER ',' csv header;
insert into brand select distinct on (slug) * from tmp_table;