Skip to content

TypeInfo.getPGType() behavior for timestamps changed in 42.2.11 #1744

@forketyfork

Description

@forketyfork

I'm submitting a ...

  • bug report
  • feature request

Describe the issue
org.postgresql.core.TypeInfo.getPGType() behavior changed unexpectedly in 42.2.11 for specific types, e.g. for Oid.TIMESTAMP. The method currently returns timestamp without time zone, but before 4.2.11 it returned just timestamp.

Driver Version?
42.2.11

PostgreSQL Version?
11.5

To Reproduce
The following code reproduces the issue:

try (Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
     BaseConnection baseConnection = (BaseConnection) connection) {
    System.out.println(baseConnection.getTypeInfo().getPGType(Oid.TIMESTAMP));
}

Expected behaviour
I expect, as in 42.2.10, to get timestamp as a result. Instead, I get timestamp without time zone. While not exactly an error, this has a significant impact on my code, and may also cause other unexpected compatibility issues.

Apparently, this is the result of the following changes: f554118

Studying the code, the problem seems to be as follows. The changes didn't take into account that the oid, as the 1st element of the TypeInfoCache.types array structure, should actually be unique. This implicitly follows from the constructor code:

  public TypeInfoCache(BaseConnection conn, int unknownLength) {
    // ...
    oidToPgName = new HashMap<Integer, String>((int) Math.round(types.length * 1.5));

The code populates a hash map and uses oid as a key. Lines added in #1719 cause the initial value to be overwritten for some of the keys, resulting in change of behavior.

A quick-and-dirty fix would be to reorder the values in the types array, but probably some more complicated refactoring is needed here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions