From 5bfe0e8a9053cbe875b657f5fd34ca7593e9c5dc Mon Sep 17 00:00:00 2001 From: Shinichi Hashiba Date: Wed, 16 Oct 2024 20:41:07 +0900 Subject: [PATCH 1/2] Add getDataLength for numeric without precision --- .../output/postgresql/PostgreSQLOutputConnection.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java b/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java index 81076be5..a0ce1881 100644 --- a/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java +++ b/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java @@ -16,6 +16,7 @@ public class PostgreSQLOutputConnection extends JdbcOutputConnection { + private static final int MIN_NUMERIC_PRECISION = 1; private static final int MAX_NUMERIC_PRECISION = 1000; public PostgreSQLOutputConnection(Connection connection, String schemaName, String roleName) @@ -263,9 +264,9 @@ protected String buildColumnTypeName(JdbcColumn c) } break; case "NUMERIC": // only "NUMERIC" because PostgreSQL JDBC driver will return also "NUMERIC" for the type name of decimal. - if (c.getDataLength() > MAX_NUMERIC_PRECISION) { - // getDataLength for numeric without precision will return 131089 . - // but cannot create column of numeric(131089) . + if (c.getDataLength() > MAX_NUMERIC_PRECISION || c.getDataLength() < MIN_NUMERIC_PRECISION) { + // getDataLength for numeric without precision will return 0 or 131089 . + // but cannot create column of numeric(0) and numeric(131089) . return "NUMERIC"; } break; From 4a240b05bf932eca919c4629df5a3d59ba56e080 Mon Sep 17 00:00:00 2001 From: Shinichi Hashiba Date: Sun, 20 Oct 2024 09:55:32 +0900 Subject: [PATCH 2/2] Add comment why getDataLength return value change 131089 to 0 --- .../embulk/output/postgresql/PostgreSQLOutputConnection.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java b/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java index a0ce1881..0e95d9e8 100644 --- a/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java +++ b/embulk-output-postgresql/src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java @@ -267,6 +267,10 @@ protected String buildColumnTypeName(JdbcColumn c) if (c.getDataLength() > MAX_NUMERIC_PRECISION || c.getDataLength() < MIN_NUMERIC_PRECISION) { // getDataLength for numeric without precision will return 0 or 131089 . // but cannot create column of numeric(0) and numeric(131089) . + // before PostgreSQL JDBC driver 42.2.23, return 131089. from 42.2.23 return 0. + // release note: https://jdbc.postgresql.org/changelogs/2021-07-06-42.2.23-release/ + // issue: https://github.com/pgjdbc/pgjdbc/issues/2188 + // pull request: https://github.com/pgjdbc/pgjdbc/pull/2189 return "NUMERIC"; } break;