on-internet
← Community

Batch Insert from Dataframe to DB ignoring failed row in Pyspark

Stack Overflow ·

I am trying to insert spark DF to Postgres using JDBC write. The postgres table has a unique constraint on one of the columns, when the df to be inserted violates the constraint entire batch is rejected and spark session closes giving an error duplicate key value violates unique constraint which is correct as the data is duplicate (already exists in the database) org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:148 What is needed that the data rows which do not violate the constraint be inserted and the failed row be ignored, without failing the entire batch. The code

Comments

Sign in or sign up to comment and upvote.

No comments yet.