I'm trying to make a bulk insert into my PostgreSQL DB using a python script (with psycopg connection). Now, the script has some duplicates on the primary column which makes it abort and rollback the entire script. However, what I want is to skip the duplicates and continue execution. My script looks something like the below
begin transaction;
create table t1 (c1 float, unique(c1));
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (1); --the script aborts and rolls back
commit;
I have looked around and found out that setting the ON_ERROR_ROLLBACK helps. But it seems like, it can be set only from the psql command line.
Is it possible to use ON_ERROR_ROLLBACK from inside the python script? Or is there any other alternative option?
Thanks in advance!