pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: davecramer (@davecramer) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
Date: Tue, 05 Aug 2025 19:40:15 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[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 ?
view thread (31+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: github://pgjdbc/pgjdbc
Cc: [email protected], [email protected]
Subject: Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
In-Reply-To: <<[email protected]>>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox