Skip to content

Commit 1a04c53

Browse files
authored
Merge pull request #351 from shin1103/fix/numeric-precision-error
Add getDataLength for numeric without precision
2 parents 99d8603 + 4a240b0 commit 1a04c53

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
public class PostgreSQLOutputConnection
1717
extends JdbcOutputConnection
1818
{
19+
private static final int MIN_NUMERIC_PRECISION = 1;
1920
private static final int MAX_NUMERIC_PRECISION = 1000;
2021

2122
public PostgreSQLOutputConnection(Connection connection, String schemaName, String roleName)
@@ -263,9 +264,13 @@ protected String buildColumnTypeName(JdbcColumn c)
263264
}
264265
break;
265266
case "NUMERIC": // only "NUMERIC" because PostgreSQL JDBC driver will return also "NUMERIC" for the type name of decimal.
266-
if (c.getDataLength() > MAX_NUMERIC_PRECISION) {
267-
// getDataLength for numeric without precision will return 131089 .
268-
// but cannot create column of numeric(131089) .
267+
if (c.getDataLength() > MAX_NUMERIC_PRECISION || c.getDataLength() < MIN_NUMERIC_PRECISION) {
268+
// getDataLength for numeric without precision will return 0 or 131089 .
269+
// but cannot create column of numeric(0) and numeric(131089) .
270+
// before PostgreSQL JDBC driver 42.2.23, return 131089. from 42.2.23 return 0.
271+
// release note: https://jdbc.postgresql.org/changelogs/2021-07-06-42.2.23-release/
272+
// issue: https://github.com/pgjdbc/pgjdbc/issues/2188
273+
// pull request: https://github.com/pgjdbc/pgjdbc/pull/2189
269274
return "NUMERIC";
270275
}
271276
break;

0 commit comments

Comments
 (0)