pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
[pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
31+ messages / 7 participants
[nested] [flat]

* [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 13:42 "arturgspb (@arturgspb)" <[email protected]>
  0 siblings, 0 replies; 31+ messages in thread

From: arturgspb (@arturgspb) @ 2016-03-27 13:42 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Hello!

I have a problem in the integration of pgjdbc with spring jdbc. Spring JDBC code:
https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/spring...

Spring encapsulates ResultSetMetaData and call it method getSchemaName, but pgjdbc return empty string. Why pgjdbc not proxy call getBaseSchemaName? getTableName have proxy call getBaseTableName.

getColumnName real return getColumnLabel, but I think will better if return getBaseColumnName.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 13:46 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2016-03-27 13:46 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Because the backend doesn't send us the schema name

Dave Cramer

On 27 March 2016 at 09:42, Artur Geraschenko [email protected]
wrote:

> Hello!
> 
> I have a problem in the integration of pgjdbc with spring jdbc. Spring
> JDBC code:
> 
> https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/spring...
> 
> Spring encapsulates ResultSetMetaData and call it method getSchemaName,
> but pgjdbc return empty string. Why pgjdbc not proxy call
> getBaseSchemaName? getTableName have proxy call getBaseTableName.
> 
> getColumnName real return getColumnLabel, but I think will better if
> return getBaseColumnName.
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub
> https://github.com/pgjdbc/pgjdbc/issues/538


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 13:49 ` "arturgspb (@arturgspb)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: arturgspb (@arturgspb) @ 2016-03-27 13:49 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

@davecramer, not sure I understand you. getBaseSchemaName contains the actual schema.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 13:54 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2016-03-27 13:54 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

It will likely still return "".

see
https://github.com/pgjdbc/pgjdbc/blob/2d5e7fa57045a47887de4ea300a743a160ae4f86/pgjdbc/src/test/java/...

Dave Cramer

On 27 March 2016 at 09:49, Artur Geraschenko [email protected]
wrote:

> @davecramer https://github.com/davecramer, not sure I understand you.
> getBaseSchemaName contains the actual schema.
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly or view it on GitHub
> https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-202066955


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 14:09 ` "arturgspb (@arturgspb)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: arturgspb (@arturgspb) @ 2016-03-27 14:09 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Example code:

``` java
package ru.realweb.meta;

import org.apache.commons.dbcp2.BasicDataSource;
import org.postgresql.jdbc.PgResultSetMetaData;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;

public class Test {

    public static void main(String[] args) throws SQLException {
        String driverClassName = "org.postgresql.Driver";
        String schema = "postgresql";
        String urlAdditional = "?encoding=UNICODE&ApplicationName=app&allowMultiQueries=true";

        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driverClassName);
        String hostPort = "***:5432/";
        String url = "jdbc:" + schema + "://" + hostPort + "***" + urlAdditional;
        ds.setUrl(url);
        ds.setUsername("***");
        ds.setPassword("***");
        ds.setMaxTotal(50);
        ds.setMaxIdle(5);


        String sqlQuery = "select client_id as my_client_id, price as value from client_stats limit 10";

        System.out.println("*** Pure JDBC");
        PreparedStatement ps = ds.getConnection().prepareStatement(sqlQuery);
        ResultSetMetaData jdbcMetaData = ps.getMetaData();
        for (int i = 1; i <= jdbcMetaData.getColumnCount(); i++) {
            System.out.println("\n");
            System.out.println("jdbcMetaData.getColumnLabel() = " + jdbcMetaData.getColumnLabel(i));

            if (jdbcMetaData instanceof PgResultSetMetaData) {
                PgResultSetMetaData pgmd = (PgResultSetMetaData) jdbcMetaData;
                System.out.println("pgmd.getColumnName = " + pgmd.getBaseColumnName(i));
                System.out.println("pgmd.getBaseTableName = " + pgmd.getBaseTableName(i));
                System.out.println("pgmd.getBaseSchemaName = " + pgmd.getBaseSchemaName(i));
            }
        }

        System.out.println("\n\n");
        System.out.println("*** Spring JDBC");
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(ds);
        NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(transactionManager.getDataSource());
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sqlQuery, new HashMap<>());
        SqlRowSetMetaData springMetaData = sqlRowSet.getMetaData();
        for (int i = 1; i <= springMetaData.getColumnCount(); i++) {
            System.out.println("\n");
            System.out.println("springMetaData.getColumnLabel(i) = " + springMetaData.getColumnLabel(i));
            System.out.println("springMetaData.getColumnName(i) = " + springMetaData.getColumnName(i));
            System.out.println("springMetaData.getTableName(i) = " + springMetaData.getTableName(i));
            System.out.println("springMetaData.getSchemaName(i) = " + springMetaData.getSchemaName(i));
        }
    }
}
```

Will print:

``` plain
*** Pure JDBC


jdbcMetaData.getColumnLabel() = my_client_id
pgmd.getColumnName = client_id
pgmd.getBaseTableName = client_stats
pgmd.getBaseSchemaName = public


jdbcMetaData.getColumnLabel() = value
pgmd.getColumnName = price
pgmd.getBaseTableName = client_stats
pgmd.getBaseSchemaName = public



*** Spring JDBC


springMetaData.getColumnLabel(i) = my_client_id
springMetaData.getColumnName(i) = my_client_id
springMetaData.getTableName(i) = client_stats
springMetaData.getSchemaName(i) = 


springMetaData.getColumnLabel(i) = value
springMetaData.getColumnName(i) = value
springMetaData.getTableName(i) = client_stats
springMetaData.getSchemaName(i) = 
```

depends: 
org.springframework:spring-jdbc:4.2.5.RELEASE
org.postgresql:postgresql:9.4.1208


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 14:20 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2016-03-27 14:20 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

OK, I see the challenge.

As I said the server does not provide this information unless we ask for
it. getSchemaName would have to do a query to get the name. I seem to
recall we did not want to add a performance regression.

Doesn't spring have a "Dialect" like hibernate ?

Dave Cramer

On 27 March 2016 at 10:09, Artur Geraschenko [email protected]
wrote:

> Example code:
> 
> package ru.realweb.meta;
> import org.apache.commons.dbcp2.BasicDataSource;import org.postgresql.jdbc.PgResultSetMetaData;import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;import org.springframework.jdbc.datasource.DataSourceTransactionManager;import org.springframework.jdbc.support.rowset.SqlRowSet;import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
> import java.sql.PreparedStatement;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.util.HashMap;
> public class Test {
> 
> ```
> public static void main(String[] args) throws SQLException {
>     String driverClassName = "org.postgresql.Driver";
>     String schema = "postgresql";
>     String urlAdditional = "?encoding=UNICODE&ApplicationName=app&allowMultiQueries=true";
> 
>     BasicDataSource ds = new BasicDataSource();
>     ds.setDriverClassName(driverClassName);
>     String hostPort = "***:5432/";
>     String url = "jdbc:" + schema + "://" + hostPort + "***" + urlAdditional;
>     ds.setUrl(url);
>     ds.setUsername("***");
>     ds.setPassword("***");
>     ds.setMaxTotal(50);
>     ds.setMaxIdle(5);
> 
> 
>     String sqlQuery = "select client_id as my_client_id, price as value from client_stats limit 10";
> 
>     System.out.println("*** Pure JDBC");
>     PreparedStatement ps = ds.getConnection().prepareStatement(sqlQuery);
>     ResultSetMetaData jdbcMetaData = ps.getMetaData();
>     for (int i = 1; i <= jdbcMetaData.getColumnCount(); i++) {
>         System.out.println("\n");
>         System.out.println("jdbcMetaData.getColumnLabel() = " + jdbcMetaData.getColumnLabel(i));
> 
>         if (jdbcMetaData instanceof PgResultSetMetaData) {
>             PgResultSetMetaData pgmd = (PgResultSetMetaData) jdbcMetaData;
>             System.out.println("pgmd.getColumnName = " + pgmd.getBaseColumnName(i));
>             System.out.println("pgmd.getBaseTableName = " + pgmd.getBaseTableName(i));
>             System.out.println("pgmd.getBaseSchemaName = " + pgmd.getBaseSchemaName(i));
>         }
>     }
> 
>     System.out.println("\n\n");
>     System.out.println("*** Spring JDBC");
>     DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(ds);
>     NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(transactionManager.getDataSource());
>     SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sqlQuery, new HashMap<>());
>     SqlRowSetMetaData springMetaData = sqlRowSet.getMetaData();
>     for (int i = 1; i <= springMetaData.getColumnCount(); i++) {
>         System.out.println("\n");
>         System.out.println("springMetaData.getColumnLabel(i) = " + springMetaData.getColumnLabel(i));
>         System.out.println("springMetaData.getColumnName(i) = " + springMetaData.getColumnName(i));
>         System.out.println("springMetaData.getTableName(i) = " + springMetaData.getTableName(i));
>         System.out.println("springMetaData.getSchemaName(i) = " + springMetaData.getSchemaName(i));
>     }
> }
> ```
> 
> }
> 
> Will print:
> 
> **\* Pure JDBC
> 
> jdbcMetaData.getColumnLabel() = my_client_id
> pgmd.getColumnName = client_id
> pgmd.getBaseTableName = client_stats
> pgmd.getBaseSchemaName = public
> 
> jdbcMetaData.getColumnLabel() = value
> pgmd.getColumnName = price
> pgmd.getBaseTableName = client_stats
> pgmd.getBaseSchemaName = public
> 
> **\* Spring JDBC
> 
> springMetaData.getColumnLabel(i) = my_client_id
> springMetaData.getColumnName(i) = my_client_id
> springMetaData.getTableName(i) = client_stats
> springMetaData.getSchemaName(i) =
> 
> springMetaData.getColumnLabel(i) = value
> springMetaData.getColumnName(i) = value
> springMetaData.getTableName(i) = client_stats
> springMetaData.getSchemaName(i) =
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly or view it on GitHub
> https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-202069493


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 14:28 ` "arturgspb (@arturgspb)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: arturgspb (@arturgspb) @ 2016-03-27 14:28 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Unfortunately, I do not know. But there is the matter of performance, why this method works as a proxy?
https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMet...


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 14:38 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2016-03-27 14:38 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

So back to your original question. What is your problem? I see spring just
calls getSchemaName. The spec says it's fine to return ""

Dave Cramer

On 27 March 2016 at 10:28, Artur Geraschenko [email protected]
wrote:

> Unfortunately, I do not know. But there is the matter of performance, why
> this method works as a proxy?
> 
> https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMet...
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly or view it on GitHub
> https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-202072312


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-27 14:57 ` "arturgspb (@arturgspb)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: arturgspb (@arturgspb) @ 2016-03-27 14:57 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

I would like not interfering in the Spring mechanisms and when calling getSchemaName get the real schema name. And well as receiving a call getColumnName real column name and not the column alias.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-28 07:08 ` "vlsi (@vlsi)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: vlsi (@vlsi) @ 2016-03-28 07:08 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

It looks like it would be fine if org.postgresql.jdbc.PgResultSetMetaData#getSchemaName delegates to org.postgresql.jdbc.PgResultSetMetaData#getBaseSchemaName.

> And well as receiving a call getColumnName real column name and not the column alias

That seems feasible.

@arturgspb , would you like to prepare some PR to fix those issues?


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-28 07:14 ` "arturgspb (@arturgspb)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: arturgspb (@arturgspb) @ 2016-03-28 07:14 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

@vlsi, yes, of course, I am happy to do it.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-03-28 11:06 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2016-03-28 11:06 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Well I am still concerned what this is going to break. For some reason the
old code didn't do this.

Dave Cramer

On 28 March 2016 at 03:14, Artur Geraschenko [email protected]
wrote:

> Yes, of course, I am happy to do it.
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly or view it on GitHub
> https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-202275709


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2016-05-04 18:09 ` "hiro2k (@hiro2k)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: hiro2k (@hiro2k) @ 2016-05-04 18:09 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

I've had this patched into my jdbc driver for a long time and have not had any issues with it. There was some concern that column aliases would not be returned properly because that information is not sent from the db, but the base column name should be there and it's better to have those than just an empty string.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2019-08-12 14:12 ` "tapioko (@tapioko)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: tapioko (@tapioko) @ 2019-08-12 14:12 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Netbeans is affected by getSchemaName returning an empty string: https://issues.apache.org/jira/browse/NETBEANS-1140

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2022-12-12 09:57 ` "lukaseder (@lukaseder)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: lukaseder (@lukaseder) @ 2022-12-12 09:57 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

I wonder if this could be implemented relatively easily by now? It was implemented for `PgResultSetMetaData::getTableName`, in case of which a query like this one is issued:

```sql
SELECT
  c.oid,
  a.attnum,
  a.attname,
  c.relname,
  n.nspname,
  a.attnotnull OR (t.typtype = 'd' AND t.typnotnull),
  a.attidentity != '' OR pg_catalog.pg_get_expr(d.adbin, d.adrelid) LIKE '%nextval(%'
FROM
  pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON
  (c.relnamespace = n.oid)
JOIN pg_catalog.pg_attribute a ON
  (c.oid = a.attrelid)
JOIN pg_catalog.pg_type t ON
  (a.atttypid = t.oid)
LEFT JOIN pg_catalog.pg_attrdef d ON
  (d.adrelid = a.attrelid
    AND d.adnum = a.attnum)
JOIN (...) vals ON
  (c.oid = vals.oid AND a.attnum = vals.attnum)
```

That query produces the schema name (`n.nspname`) and the information is cached. Since users are likely going to call `PgResultSetMetaData::getTableName` as well when they call `PgResultSetMetaData::getSchemaName`, I suspect there wouldn't be any additional overhead?

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2022-12-12 10:00 ` "lukaseder (@lukaseder)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: lukaseder (@lukaseder) @ 2022-12-12 10:00 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

In fact, `PgResultSetMetaData::getBaseSchemaName` is already implemented. It's just not being called by `PgResultSetMetaData::getSchemaName`

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2022-12-12 13:05 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2022-12-12 13:05 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Well it can but most people don't really wan't to take the hit of doing another round trip. My admittedly fuzzy recollection here is that folks expected the schema name to be returned by the server in the results.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2022-12-12 14:07 ` "lukaseder (@lukaseder)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: lukaseder (@lukaseder) @ 2022-12-12 14:07 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

> Well it can but most people don't really wan't to take the hit of doing another round trip

But the result is cached in `BaseConnection::getFieldMetadataCache`, so between the various calls to `PgResultSetMetaData`, the extra round trip is shared as good as possible. Given that a round trip is highly likely already, I think that most people will not mind?

> My admittedly fuzzy recollection here is that folks expected the schema name to be returned by the server in the results.

That would be much better, no doubt. But apparently, this information isn't already present now.

Anyway, I just wanted to add this information here, given that I had to look it up myself and that I haven't seen anyone else mention the existing cached data from other round trips.

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-02 20:16 ` "prrvchr (@prrvchr)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: prrvchr (@prrvchr) @ 2025-08-02 20:16 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Hi all,

I'm surprised by this problem and apparently it's still not fixed.
Is there anything planned?

Thank you.

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-02 20:20 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2025-08-02 20:20 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Well, by default the resultset does not have the schema name in it.

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-02 20:40 ` "prrvchr (@prrvchr)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: prrvchr (@prrvchr) @ 2025-08-02 20:40 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

And maybe there could be a connection option so that this is filled in for example.

With several schemas I don't see how this can work correctly as is?

In fact, this would allow us to support [javax.sql.rowset.CachedRowSet](https://docs.oracle.com/javase/8/docs/api/javax/sql/rowset/CachedRowSet.html) in a slightly less cumbersome way.

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-05 11:33 ` "prrvchr (@prrvchr)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: prrvchr (@prrvchr) @ 2025-08-05 11:33 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Well, I have exactly the same problem with the Oracle JDBC driver ojdbc17.jar. Their ResultSets don't provide the table name or schema name in the metadata. Well done, Oracle...

But if I take the trouble to find the table name in the SQL query and make sure it is a `SELECT` query that only looks at one table, then I can find the missing data and make this ResultSet editable in LibreOffice Base.

I'm not going to claim anything from Oracle, that would be a waste of time, and neither here, but I would like to point out that analyzing the query in order to extract the name of the table should be part of the JDBC driver (if it is supposed to be called that).

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-05 14:54 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2025-08-05 14:54 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

@prrvchr the driver doesn't really analyze queries. It just passes them through. Analyzing queries would be quite expensive.



^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-05 15:04 ` "vlsi (@vlsi)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: vlsi (@vlsi) @ 2025-08-05 15:04 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Should we rather infer the schema name like Lukas suggested in https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-1346193264?

Sure think we should not try parsing SQL to infer the table names. However, I think we should retrieve the schema name along with the table name if we can do that.

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-05 19:40 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2025-08-05 19:40 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

So I was able to get the following to work 
```try (ResultSet resultSet = statement.executeQuery("select  foo.a.i,public.a.i from foo.a, a;")) {
                    ResultSetMetaData metaData = resultSet.getMetaData();
                    String schema1 = metaData.getSchemaName(1);
                    String table1 = metaData.getTableName(1);
                    System.out.println("Column 1 is from table: " + table1 + " Schema: " + schema1);
                    String schema2 = metaData.getSchemaName(2);
                    String table2 = metaData.getTableName(2);
                    System.out.println("Column 2 is from table: " + table2 + " Schema: " + schema2);
```
the output
```
Column 1 is from table: a Schema: foo
Column 2 is from table: a Schema: public
```

with the following change 
```diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMetaData.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMetaData.java
index 46ed0e60..d31e3a41 100644
--- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMetaData.java
+++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSetMetaData.java
@@ -172,7 +172,13 @@ public class PgResultSetMetaData implements ResultSetMetaData, PGResultSetMetaDa
 
   @Override
   public String getSchemaName(int column) throws SQLException {
-    return "";
+    Field field = getField(column);
+    if (field.getTableOid() == 0) {
+      return "";
+    }
+    fetchFieldMetaData();
+    FieldMetadata metadata = field.getMetadata();
+    return metadata == null ? "" : metadata.schemaName;
   }
 
   private boolean populateFieldsWithMetadata(Gettable<FieldMetadata.Key, FieldMetadata> metadata) {
```

Seems this is not that difficult. One question though. Do we want to return `public` or just leave it empty ?

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-05 20:20 ` "prrvchr (@prrvchr)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: prrvchr (@prrvchr) @ 2025-08-05 20:20 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

> Seems this is not that difficult.

If it's that simple, I think it's worth implementing.
All of this is nothing compared to the code needed to parse queries and complete the missing metadata for a ResultSet.

> One question though. Do we want to return `public` or just leave it empty ?

What are the cases where we cannot find the schema?



^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-05 21:20 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2025-08-05 21:20 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

> > Seems this is not that difficult.
> 
> If it's that simple, I think it's worth implementing. All of this is nothing compared to the code needed to parse queries and complete the missing metadata for a ResultSet.
Yes, agreed. 
> 
> > One question though. Do we want to return `public` or just leave it empty ?
> 
> What are the cases where we cannot find the schema?

`Select 1 as foo` will not provide a schema



^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-06 01:41 ` "prrvchr (@prrvchr)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: prrvchr (@prrvchr) @ 2025-08-06 01:41 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

> `Select 1 as foo` will not provide a schema

Okay, these columns are of little interest for updating and should normally be read-only.
An empty string seems to me to be the most suitable.


^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-06 08:51 ` "lukaseder (@lukaseder)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: lukaseder (@lukaseder) @ 2025-08-06 08:51 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

> One question though. Do we want to return public or just leave it empty ?

The `ResultSetMetaData::getSchemaName` Javadoc says *"name or "" if not applicable"*

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-06 09:20 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2025-08-06 09:20 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

> > One question though. Do we want to return public or just leave it empty ?
> 
> The `ResultSetMetaData::getSchemaName` Javadoc says _"name or "" if not applicable"_

The question is more about whether to add `public` since the original query did not have it and it's not necessary to create a query from it. Technically it is correct but seems odd to me. I would vote to return an empty string instead

^ permalink  raw  reply  [nested|flat] 31+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
@ 2025-08-06 15:30 ` "davecramer (@davecramer)" <[email protected]>
  29 siblings, 0 replies; 31+ messages in thread

From: davecramer (@davecramer) @ 2025-08-06 15:30 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

PR to fix this #3753 

^ permalink  raw  reply  [nested|flat] 31+ messages in thread


end of thread, other threads:[~2025-08-06 15:30 UTC | newest]

Thread overview: 31+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-27 13:42 [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel? "arturgspb (@arturgspb)" <[email protected]>
2016-03-27 13:46 ` "davecramer (@davecramer)" <[email protected]>
2016-03-27 13:49 ` "arturgspb (@arturgspb)" <[email protected]>
2016-03-27 13:54 ` "davecramer (@davecramer)" <[email protected]>
2016-03-27 14:09 ` "arturgspb (@arturgspb)" <[email protected]>
2016-03-27 14:20 ` "davecramer (@davecramer)" <[email protected]>
2016-03-27 14:28 ` "arturgspb (@arturgspb)" <[email protected]>
2016-03-27 14:38 ` "davecramer (@davecramer)" <[email protected]>
2016-03-27 14:57 ` "arturgspb (@arturgspb)" <[email protected]>
2016-03-28 07:08 ` "vlsi (@vlsi)" <[email protected]>
2016-03-28 07:14 ` "arturgspb (@arturgspb)" <[email protected]>
2016-03-28 11:06 ` "davecramer (@davecramer)" <[email protected]>
2016-05-04 18:09 ` "hiro2k (@hiro2k)" <[email protected]>
2019-08-12 14:12 ` "tapioko (@tapioko)" <[email protected]>
2022-12-12 09:57 ` "lukaseder (@lukaseder)" <[email protected]>
2022-12-12 10:00 ` "lukaseder (@lukaseder)" <[email protected]>
2022-12-12 13:05 ` "davecramer (@davecramer)" <[email protected]>
2022-12-12 14:07 ` "lukaseder (@lukaseder)" <[email protected]>
2025-08-02 20:16 ` "prrvchr (@prrvchr)" <[email protected]>
2025-08-02 20:20 ` "davecramer (@davecramer)" <[email protected]>
2025-08-02 20:40 ` "prrvchr (@prrvchr)" <[email protected]>
2025-08-05 11:33 ` "prrvchr (@prrvchr)" <[email protected]>
2025-08-05 14:54 ` "davecramer (@davecramer)" <[email protected]>
2025-08-05 15:04 ` "vlsi (@vlsi)" <[email protected]>
2025-08-05 19:40 ` "davecramer (@davecramer)" <[email protected]>
2025-08-05 20:20 ` "prrvchr (@prrvchr)" <[email protected]>
2025-08-05 21:20 ` "davecramer (@davecramer)" <[email protected]>
2025-08-06 01:41 ` "prrvchr (@prrvchr)" <[email protected]>
2025-08-06 08:51 ` "lukaseder (@lukaseder)" <[email protected]>
2025-08-06 09:20 ` "davecramer (@davecramer)" <[email protected]>
2025-08-06 15:30 ` "davecramer (@davecramer)" <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox