I'm trying to insert a row into my table, only if it doesn't already exist (based on a unique id (myId)). I don't want to query every single row before inserting as that takes some time. I'd like to just try to insert, and if it fails that's fine. Is there a way to do this?
At the moment, I'm doing:
try {
sqlObj.executeInsert(query)
}
catch (Exception e) {
println "Sql Exception"
}
but this is kind of slow, as almost every row throws an exception in some cases. Is there a way to handle this in SQL/Groovy/Postgresql?