Please help me, how to add a check for an existing duplicate of a unique key, if there is a skip and import the lines with CSV further. Mistake:

psycopg2.IntegrityError: duplicate key value violates uniqueconstraint "dbname_pkey" DETAIL: Key (id)=(1) already exists.

 import psycopg2 def importoDB(self): self.conn = psycopg2.connect( host='ip', user='username', password='pass', dbname='dbname') self.cursor = self.conn.cursor() f = open(r'test.csv', 'r') self.cursor.copy_from(f, 'dbname', sep=';') f.close() self.conn.commit() 

0