Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getDataLength for numeric without precision #351

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -263,9 +264,13 @@ 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) .
// 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;
Expand Down