pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: beikov (@beikov) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] issue #3049: TypeInfoCache should be clearable/resetable
Date: Thu, 30 Nov 2023 18:41:37 +0000
Message-ID: <[email protected]> (raw)
**Describe the issue**
Imagine TX1 binding a `PGObject` with type name `mystruct` via `PreparedStatement#setObject()`. This will put the oid of that type into `TypeInfoCache`. When the type gets dropped and a new type with the same name is created, one can never ever bind an object with this type name with this connection, because the oid does not exist anymore. The error I'm seeing is `ERROR: cache lookup failed for type 1234`.
**Driver Version?**
42.6.0
**Java Version?**
11
**OS Version?**
Linux/Windows
**PostgreSQL Version?**
15
**To Reproduce**
See example.
**Expected behaviour**
Either the driver should handle this situation automatically by retrying the statement after looking up the oid again, or at least the `TypeInfo` or `TypeInfoCache` types should provide a way to clear the cache.
Using the following template code make sure the bug can be replicated in the driver alone.
```
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class TestNullsFirst {
public static void main(String []args) throws Exception {
String url = "jdbc:postgresql://localhost:5432/test";
Properties props = new Properties();
props.setProperty("user", "test");
props.setProperty("password", "test");
try ( Connection conn = DriverManager.getConnection(url, props) ){
try ( Statement statement = conn.createStatement() ) {
statement.execute("create type structType as (v text)");
statement.execute("create table tbl as (s structType)");
}
try ( PreparedStatement statement = conn.prepareStatement( "insert into tbl values (?)" ) ) {
PGObject o = new PGObject();
o.setType("structType")
o.setValue("(\"abc\")")
statement.setObject( 1, o );
statement.executeUpdate();
}
try ( Statement statement = conn.createStatement() ) {
statement.execute("drop table tbl");
statement.execute("drop type structType");
statement.execute("create type structType as (v text)");
statement.execute("create table tbl as (s structType)");
}
try ( PreparedStatement statement = conn.prepareStatement( "insert into tbl values (?)" ) ) {
PGObject o = new PGObject();
o.setType("structType")
o.setValue("(\"abc\")")
statement.setObject( 1, o );
statement.executeUpdate();
}
}
}
}
```
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 #3049: TypeInfoCache should be clearable/resetable
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