Subject: [pgjdbc/pgjdbc] issue #3527: Improve compatibility with non-Postgres databases

From: "kneth (@kneth)" <[email-masked]>
Date: Tue, 18 Feb 2025 16:10:11 +0000

Postgres compatible databases like https://github.com/crate/crate can use PG JDBC as driver. Often the PG JDBC driver is used by a tool or integration (JetBrains DataGrip to name one). As CrateDB isn't fully PG compatible, and hopefully the PG JDBC can offer a more robust support. The issue has also been reported as https://github.com/crate/crate/issues/17393.

A patch to work around the differences between the two databases can be found in https://github.com/pgjdbc/pgjdbc/pull/3526.

**Describe the issue**

As far as I can see, a query as `SELECT current_database()` will return a different column name. For Postgres, the column name will be `current_database` while for CrateDB, the column name will be the name of the current database. The PG JDBC driver will try to access the column `current_database` - which does not exist in the CrateDB case (leading to an error or exception).

It means that https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java#L1273 will fail as the column name is not specified in https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java#L1253 .

**Driver Version?** 

42.7.5

**Java Version?**

**OS Version?**

**PostgreSQL Version?**

**To Reproduce**

Any query with `current_database()` with the minimal case `SELECT current_database()`.

**Expected behaviour**

The driver should not throw an exception.

**Logs**

The following two screenshots show the difference between Postgres and CrateDB.

![Image](https://github.com/user-attachments/assets/910c468f-3bec-4ada-8e60-0f3041ba6f28)

![Image](https://github.com/user-attachments/assets/ddc71437-23c1-4ad5-a188-1f4829fac85e)

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 24 Feb 2025 07:28:56 +0000

@kneth , do you know if there's a possibility to execute basic crate tests in pgjdbc CI?
I guess we might consider including it if the tests are not too flaky.

---

From: "kneth (@kneth)" <[email-masked]>
Date: Mon, 24 Feb 2025 09:17:17 +0000

@vlsi It is definitely possible as we done it in https://github.com/crate/crate-qa/tree/master/tests/client_tests/stock_jdbc. We discovered the issue when [upgrading to 42.7.5](https://github.com/crate/crate-qa/pull/333) using our tests.

---

From: "kneth (@kneth)" <[email-masked]>
Date: Fri, 25 Apr 2025 13:38:58 +0000

As #3526 has been merged, I close the issue as completed.