(based on aliasmrchips' answer:) if you have a Groovy environment (like me using it within ANT) you could do it like this (substituting the Oracle specifics with Postgres):
// exec.groovy
this.class.classLoader.rootLoader.addURL('${postgres-jdbc-driver-path}')
PgScript.load()
// PgScript.groovy
// (we cannot use the org.postgres.* classes in exec.groovy already!)
import java.io.FileReader
import java.sql.DriverManager
import org.postgresql.copy.CopyManager
import org.postgresql.core.BaseConnection
class PgScript {
static void load() {
DriverManager.getConnection (
'${jdbc-db-url}', '${db-usr}', '${db-usr-pass}'
).withCloseable {conn ->
new CopyManager((BaseConnection) conn).
copyIn('COPY t FROM STDIN', new FileReader('${sqlfile}'))
}
}
}
Based also on this javaworld.com article.