Message-ID: From: "beikov (@beikov)" To: "pgjdbc/pgjdbc" Date: Thu, 30 Nov 2023 18:41:37 +0000 Subject: [pgjdbc/pgjdbc] issue #3049: TypeInfoCache should be clearable/resetable List-Id: X-GitHub-Assignees: vlsi X-GitHub-Author-Id: 358916 X-GitHub-Author-Login: beikov X-GitHub-Issue: 3049 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3049 Content-Type: text/plain; charset=utf-8 **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(); } } } } ```