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

PgDatabaseMetaData should return column names as described in specification. #830

Closed
bilak opened this issue May 22, 2017 · 14 comments
Closed
Assignees

Comments

@bilak
Copy link

bilak commented May 22, 2017

Hello,
In java specification for getTables are returned column names uppercased. As many implementations depends on this, would it be possible to convert values to uppercase and provide it as described in specification? I know that it's possible to retrieve resultset metadata with ignoringcase but when you don't have this in mind, it could produce errors.

Thanks

@davecramer
Copy link
Member

PostgreSQL by default folds to lower case. This would probably break everyone elses code. Pretty sure this is a non-starter

@bilak
Copy link
Author

bilak commented May 22, 2017

Then this issue could be closed.

@vlsi
Copy link
Member

vlsi commented May 22, 2017

@davecramer , technically speaking, "TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ..." are declared to be in upper case (not the contents, but the column names itself)

rs.getString("TABLE_TYPE") works since getString is case-insensitive.

Do you still consider it is not possible to adjust that?

@davecramer
Copy link
Member

I assumed he wanted the actually names of the columns returned in upper case ?

ie create table (id int, a text) would return column names id, and a in lower case.

Is this not the case ?

@bilak
Copy link
Author

bilak commented May 22, 2017

@davecramer no, as @vlsi described specifications is telling about "TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ..." as uppercase. So I expect column names to be returned in upper case also.

@vlsi
Copy link
Member

vlsi commented May 22, 2017

Implementation-wise, getTables works off a SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM..., that causes lower-case conversion.

@davecramer
Copy link
Member

This would not be difficult to fix. Just double quote the table names above. At this point I'm wondering what it would break ?

@vlsi
Copy link
Member

vlsi commented May 22, 2017

At this point I'm wondering what it would break ?

Lower case is visible via getTables().getMetaData().getColumName(1). However, I don't think one would ever rely on that level of meta-information. They would either use getTables().getString("TABLE_NAME") and/or column position getTables().getString(3).

However, metadata-API is always a pain, so we might want to add a kill switch. That is: make upper case the default (e.g. in 42.1.2+), add a connection property to flip back the case, and remove the switch in (42.2.0).

@vlsi
Copy link
Member

vlsi commented May 22, 2017

@davecramer , do you think a kill switch is required?

@davecramer
Copy link
Member

@vlsi yes, I do, as this is a behavioural change.

@EcoFreak
Copy link

EcoFreak commented Dec 5, 2018

This should be changed. Some applications use jdbc drivers and read the columns from the metadata.
Adding quotes to the getTables query and such will solve this problem and will make the methods completely compliant with the jdbc specs.

@davecramer
Copy link
Member

@EcoFreak if I'm understanding this problem this #1350 fixes it, no?

@EcoFreak
Copy link

EcoFreak commented Dec 5, 2018

Hi @davecramer , I'm trying to integrate a postgresql database with SAP JAVA BI (currently have MySQL, MSSQL and others running with JDBC drivers).

After some digging I found that the code used to determine database tables:

 ResultSet rs = connSQL.getMetaData().getTables(null, null, null, null);
    ResultSetMetaData rsmd = rs.getMetaData();
    int cols = rsmd.getColumnCount();
    
    while (rs.next())
    {
      try
      {
        for (int i = 1; i <= cols; i++)
        {

          if (rsmd.getColumnName(i).equals("TABLE_NAME")) {
            tableList.add(rs.getString(i));
          }
        }
      }
      catch (Exception e) {}
    }

As you can see, the column names are fetched using rs.getMetaData(); wich returns lower cased column names instead of TABLE_NAME, the column is name table_name.

Unfortunately I can't control the existing SAP code.

Any thoughts?

Thanks

@davecramer
Copy link
Member

@EcoFreak it would appear we need to fix the ResultSetMetaData as well. Pull requests are welcome

@davecramer davecramer self-assigned this Nov 26, 2019
davecramer added a commit to davecramer/pgjdbc that referenced this issue Mar 9, 2021
davecramer added a commit to davecramer/pgjdbc that referenced this issue Mar 22, 2021
pgjdbc#2092)

* fix: PgDatabaseMetaData should return UPPERCASE column names as per spec, fixes pgjdbc#830

* fix javadoc errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants