huaxingao commented on code in PR #13925:
URL: https://github.com/apache/iceberg/pull/13925#discussion_r2334305581
##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcTableOperations.java:
##########
@@ -138,7 +139,9 @@ public void doCommit(TableMetadata base, TableMetadata
metadata) {
throw new UncheckedSQLException(e, "Database warning");
} catch (SQLException e) {
// SQLite doesn't set SQLState or throw
SQLIntegrityConstraintViolationException
- if (e.getMessage() != null && e.getMessage().contains("constraint
failed")) {
+ // Postgres doesn't throw SQLIntegrityConstraintViolationException
Review Comment:
nit: how about
```
// Postgres doesn't throw SQLIntegrityConstraintViolationException but sets
SQLState to "23505" (unique violation)
```
##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcTableOperations.java:
##########
@@ -138,7 +139,9 @@ public void doCommit(TableMetadata base, TableMetadata
metadata) {
throw new UncheckedSQLException(e, "Database warning");
} catch (SQLException e) {
// SQLite doesn't set SQLState or throw
SQLIntegrityConstraintViolationException
- if (e.getMessage() != null && e.getMessage().contains("constraint
failed")) {
+ // Postgres doesn't throw SQLIntegrityConstraintViolationException
+ if (e.getMessage() != null
+ && (e.getMessage().contains("constraint failed") ||
"23505".equals(e.getSQLState()))) {
Review Comment:
nit: I think e.getMessage() != null is no need to be checked for "23505".
How about
```
if ("23505".equals(e.getSQLState())
|| (e.getMessage() != null && e.getMessage().contains("constraint
failed"))) {
throw new AlreadyExistsException("Table already exists: %s",
tableIdentifier);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]