Message-ID: From: "davecramer (@davecramer)" To: "pgjdbc/pgjdbc" Date: Tue, 05 Aug 2025 19:40:15 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel? In-Reply-To: References: List-Id: X-GitHub-Author-Login: davecramer X-GitHub-Comment-Id: 3156380031 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 538 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-3156380031 Content-Type: text/plain; charset=utf-8 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 metadata) { ``` Seems this is not that difficult. One question though. Do we want to return `public` or just leave it empty ?