pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: aditsu (@aditsu) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] issue #3926: ResultSetMetaData.getColumnClassName is broken for jsonb
Date: Tue, 03 Feb 2026 13:58:18 +0000
Message-ID: <[email protected]> (raw)
**Describe the issue**
ResultSetMetaData.getColumnClassName does not return the correct class name for columns of type jsonb.
Specifically, the javadoc says it should return "the fully-qualified name of the class in the Java programming language that would be used by the method ResultSet.getObject to retrieve the value in the specified column"
The method returns "java.lang.String" in recent driver versions, whereas ResultSet.getObject returns instances of org.postgresql.util.PGobject, and that class does not extend java.lang.String.
This is not a problem for the "json" pg type, which is handled perfectly. Only "jsonb" is broken.
**Driver Version?**
42.7.9 (but I have tested older versions too)
**Java Version?**
17.0.13
**OS Version?**
Linux
**PostgreSQL Version?**
17.7
**To Reproduce**
Here is my table:
```
CREATE TABLE public.jsontest (
id int4 GENERATED ALWAYS AS IDENTITY NOT NULL,
fld_json json NOT NULL,
fld_jsonb jsonb NOT NULL,
CONSTRAINT jsontest_pk PRIMARY KEY (id)
);
```
I inserted one row with some dummy data.
kotlin test code:
```
import java.sql.DriverManager
import java.util.Properties
fun main() {
val url = "jdbc:postgresql://localhost/test"
val props = Properties().apply {
setProperty("user", "postgres")
setProperty("password", "")
}
DriverManager.getConnection(url, props).use { conn ->
val sql = "SELECT id, fld_json, fld_jsonb FROM jsontest"
val version = conn.metaData.driverVersion
println("driver version: $version")
conn.createStatement().use { statement ->
statement.executeQuery(sql).use { rs ->
val metaData = rs.metaData
while (rs.next()) {
for (i in 2..metaData.columnCount) {
val name = metaData.getColumnName(i)
val type = metaData.getColumnTypeName(i)
val cl = metaData.getColumnClassName(i)
val value = rs.getObject(i)
println("$name - type $type, metadata class $cl, value ${value.javaClass}")
println("instance test: " + Class.forName(cl).isInstance(value))
}
}
}
}
}
}
```
**Expected behaviour**
I expected the metadata class match the class of the returned value, or at least to be a supertype.
More specifically, I expected getColumnClassName to return "org.postgresql.util.PGobject" like it does for json.
It actually returns "java.lang.String" in recent driver versions, which would still be ok (though very weird and inconsistent with the json type) **IF** the value was actually returned as a String from getObject, but it is not - the actual value is a PGobject.
Actual results:
I tested this with several different driver versions, and got mainly 2 different outputs:
```
driver version: 42.2.0
fld_json - type json, metadata class org.postgresql.util.PGobject, value class org.postgresql.util.PGobject
instance test: true
fld_jsonb - type jsonb, metadata class java.lang.Object, value class org.postgresql.util.PGobject
instance test: true
```
Old versions:
type json - perfect match: PGobject to PGobject
type jsonb - inconsistent but not broken: Object to PGobject
```
driver version: 42.7.9
fld_json - type json, metadata class org.postgresql.util.PGobject, value class org.postgresql.util.PGobject
instance test: true
fld_jsonb - type jsonb, metadata class java.lang.String, value class org.postgresql.util.PGobject
instance test: false
```
New versions:
type json - perfect match: PGobject to PGobject
type jsonb - actually broken: String to PGobject
Proposed solution (preferred): getColumnClassName should return "org.postgresql.util.PGobject" like it does for json.
Alternative solution (inferior): getColumnClassName should return "java.lang.String" for both json and jsonb, but at the same time getObject should be modified to return a String value.
See also: bug #2153 - I don't really understand what happened there, but it seems to me that it was broken on purpose?! Very bizarre.
view thread (10+ 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 #3926: ResultSetMetaData.getColumnClassName is broken for jsonb
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