Message-ID: From: "avinashyn (@avinashyn)" To: "pgjdbc/pgjdbc" Date: Mon, 03 Feb 2025 04:38:50 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3504: Wrong schemas fetched for a given catalog as input In-Reply-To: References: List-Id: X-GitHub-Author-Login: avinashyn X-GitHub-Comment-Id: 2629899216 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3504 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3504#issuecomment-2629899216 Content-Type: text/plain; charset=utf-8 Well Same with latest version as well. Below is the sample code ------------------------------------------------------------------- ``` public class DBFetchPostgresSchemas { static final String DB_URL = "jdbc:postgresql://host:5434/postgresutf8"; static final String USER = "user"; static final String PASS = "password"; public static void main(String[] args) { try { getCatalogs(); getSchemas("postgres"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void getCatalogs() throws SQLException { Connection conn = DriverManager.getConnection(DB_URL, USER,PASS); ResultSet rs = null; try { List catalogs = new ArrayList(); rs = conn.getMetaData().getCatalogs(); while (rs.next()) { String catalog = rs.getString("TABLE_CAT"); System.out.println("catalog:"+catalog); } } catch (SQLException e) { e.printStackTrace(); } finally { rs.close(); conn.close(); } } public static void getSchemas(String catalog) throws SQLException { Connection conn = DriverManager.getConnection(DB_URL, USER,PASS);; ResultSet rs = null; try { List schemas = new ArrayList(); if (catalog != null && catalog.length() > 0) conn.setCatalog(catalog); rs = conn.getMetaData().getSchemas(); while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); System.out.println("schema:"+schema); } } catch (SQLException e) { e.printStackTrace(); } finally { rs.close(); conn.close(); } } } ``` =========================== Here **getCatalog()** --> gives all the catalogs present in Database. Version **42.6** gives only the catalog passed in JDBC url where as **42.7** gives all the catalogs from database which is still fine but the problem arises with **getSchema()** -> It always gives schema of the one passed in JDBCUrl rather than the one passed in request. In above example, "**postgres**" catalog is passed in request but it fetches the schema of "**postgresutf8**" catalog which is passed in db URL