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

Incorrect base type returned from PgDatabaseMetaData#getUDTs() #2520

Closed
alurie opened this issue May 27, 2022 · 2 comments
Closed

Incorrect base type returned from PgDatabaseMetaData#getUDTs() #2520

alurie opened this issue May 27, 2022 · 2 comments
Milestone

Comments

@alurie
Copy link
Contributor

alurie commented May 27, 2022

Please read https://stackoverflow.com/help/minimal-reproducible-example

Describe the issue
When invoking the getUDTs method of PgDatabaseMetaData for a user-defined (aka domain) type, an incorrect value of
Types.OTHER is returned instead of the corresponding data type of the base data type.

Driver Version?
Change in behavior was introduced in 42.2.23

The change was this commit: e1b8437
which is a backport of this commit: 375cb37

Java Version?
n/a

OS Version?
n/a

PostgreSQL Version?
n/a

To Reproduce
Below is a small program that demonstrates the issue.
Prior to the driver upgrade (we were on 42.2.16) the expected type Types.VARCHAR was returned, and after the upgrade (to 42.2.25), Types.OTHER started to be returned.

import java.sql.*;

public class test1 {
    public static void main(String[] args) throws Exception
    {
        String url = "jdbc:postgresql://localhost:5432/postgres?user=host_user";
        Connection con = DriverManager.getConnection(url);
        Statement stmt = con.createStatement();
        stmt.execute("create domain mytype1 as text");
        ResultSet rs = con.getMetaData().getUDTs(null, null, "mytype1", null);
        rs.next();
        int bt = rs.getInt("base_type");
        if (bt != java.sql.Types.VARCHAR)
            System.out.println("Unexpected base type: " + rs.getInt("base_type"));
        stmt.execute("drop domain mytype1");
        con.close();
    }
}

// Output with driver 42.2.16:  
// Output with driver 42.2.25:  Unexpected base type: 1111 

Expected behaviour
It is expected that the data type of the base type of the domain is returned back in the base_type column of the result set from getUDTs method. Instead, Types.OTHER is being returned.

Logs
n/a

@alurie
Copy link
Contributor Author

alurie commented May 27, 2022

I have the fix for this issue, but I was not able to create a new branch (not authorized) for the PR.
Please let me know if I'm missing some steps or not following the correct process.

Essentially the issue is that there it a typo in the generated SQL that uses t.oid instead of the oid, because we want to reference the base type oid in that CASE statement.
I've also changed the corresponding test cases to test for the base type (previously it was merely testing whether base type was null or not).

Attaching the patch.
0001-fix-return-correct-base-type-from-getUDTs-2520.patch.txt

@davecramer
Copy link
Member

you need to create a fork and create a branch on your fork then push back to your fork to create the PR

alurie pushed a commit to alurie/pgjdbc that referenced this issue May 27, 2022
davecramer pushed a commit that referenced this issue May 28, 2022
@alurie alurie closed this as completed May 28, 2022
@vlsi vlsi added this to the 43.4 milestone Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants