In my Java application I import some CSV files in PostgreSQL 10.3 with PgAdmin4 (JDBC).
private static void importDB(String path, String type) {
Statement stmt = null;
try {
Class.forName(DRIVER_CLASS_NAME);
c = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = c.createStatement();
//System.out.println(''"+path+"');
String sql = "COPY "+type+" from '"+path+"' CSV HEADER";
stmt.executeUpdate(sql);
stmt.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now: if I modify some non-key-values in the CSV file and try to re-import there's an obvious primary key problem because it's just like another copy of the same file I imported first. Assuming that tables in PgAdmin4 has primary keys (id,sat), how can I check these keys in the table(in the rows actually) and modify the other non-key data? Just like overwriting them.