{"record":{"id":"93ae1b94c5e36178","repo":"apache/seatunnel","slug":"jdbcconnectorerrorcode-data-type-cast-failed-93ae1b","errorCode":"JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED","errorMessage":"error field:${fieldName}","messagePattern":"error field:(.+?)","errorType":"error_code","errorClass":"JdbcConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java","lineNumber":338,"sourceCode":"                        if (SqlType.TINYINT.equals(elementType.getSqlType())) {\n                            Short[] shortArray = new Short[array.length];\n                            for (int i = 0; i < array.length; i++) {\n                                shortArray[i] = Short.valueOf(array[i].toString());\n                            }\n                            statement.setObject(statementIndex, shortArray);\n                        } else {\n                            statement.setObject(statementIndex, array);\n                        }\n                        break;\n                    case MAP:\n                    case ROW:\n                    default:\n                        throw new JdbcConnectorException(\n                                CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,\n                                \"Unexpected value: \" + seaTunnelDataType);\n                }\n            } catch (Exception e) {\n                throw new JdbcConnectorException(\n                        JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED,\n                        \"error field:\" + rowType.getFieldNames()[fieldIndex],\n                        e);\n            }\n        }\n        return statement;\n    }\n\n    @Nullable private String resolveSourceType(\n            SeaTunnelRowType rowType,\n            int fieldIndex,\n            @Nullable TableSchema databaseTableSchema,\n            String[] sourceTypes) {\n        if (databaseTableSchema != null) {\n            String fieldName = rowType.getFieldName(fieldIndex);\n            if (databaseTableSchema.contains(fieldName)) {\n                return databaseTableSchema.getColumn(fieldName).getSourceType();\n            }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java#L320-L356","documentation":"In PostgresJdbcRowConverter.toExternal, any Exception thrown while binding a field's value into the PreparedStatement is rethrown as JdbcConnectorException with code DATA_TYPE_CAST_FAILED and message 'error field:<fieldName>', preserving the cause. It identifies which schema field failed the JDBC type conversion.","triggerScenarios":"Any exception inside the per-field binding block of toExternal - e.g. casting a value to the target JDBC type, setObject failures, array serialization errors, or type-conversion exceptions from the driver.","commonSituations":"Data values that don't fit the declared column (overflowing numeric, wrong string format for date/timestamp), nulls in unsupported positions, driver-side conversion failures on unusual values.","solutions":["Inspect the wrapped cause ('Caused by') to find the actual conversion failure","Fix the data: ensure values match the declared column type/range (e.g. valid dates, numerics within precision)","Adjust the SeaTunnel schema type to match the actual data, or cast values upstream before the sink"],"exampleFix":"// before\nfield(birthday, STRING_TYPE) // value \"31/02/2020\" to DATE column\n// after\nfield(birthday, DATE_TYPE) // and clean invalid date strings upstream","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    converter.toExternal(row, statement);\n} catch (JdbcConnectorException e) {\n    if (e.getCode().equals(JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED)) {\n        log.error(\"field '{}' failed conversion\", e.getMessage(), e.getCause());\n    }\n}","preventionTips":["Always inspect getCause() for the underlying driver conversion error","Validate data values against column type/precision upstream","Clean dates, numerics, and encodings before writing to Postgres"],"tags":["jdbc","postgres","row-converter","type-cast","data-conversion"],"backgroundTag":"type-mismatch","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}