Message-ID: From: "me-honest (@me-honest)" To: "pgjdbc/pgjdbc" Date: Thu, 12 Jun 2025 13:37:09 +0000 Subject: [pgjdbc/pgjdbc] issue #3658: TypeInfoCache contains wrong entries when switching schemas and using an array of custom user type List-Id: X-GitHub-Author-Id: 25753956 X-GitHub-Author-Login: me-honest X-GitHub-Issue: 3658 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3658 Content-Type: text/plain; charset=utf-8 Hello! I just ran into an issue which I believe is a bug on the driver. I have a schema based multitenant setup, and in my table definition I have a column "custom_type_column" which is an array of a user defined type "custom_type". All tables and types have the same name, in different schemas. The problem is that when I insert a row for schema1, everything works ok, but when I insert the same for schema2, I get the error: `ERROR: column \"custom_type_column\" is of type custom_type[] but expression is of type schema1.custom_type[]\n Hint: You will need to rewrite or cast the expression` I debugged for some hours, and found that the schema is being set for the session using org.postgresql.jbdc.PgConnection.setSchema(), and then going through many classes I could reach the point where the wrong type is set. This is happening on org.postgresql.jbdc.TypeInfoCache.getPGType(), where the map pgNameToOid is populated with the custom type information of the schema1, resulting in the oid of the custom type of schema1 being returned and not that of schema2. Seems like a stale cache from the last schema. I queried directly postgres with PgAdmin, and verified that the oids shown in this map belong to schema1, and not to the current session's schema2. Even some of the entries in the cache map contain the full name of the custom type, including schema, something like "schema1"."custom_type". I imagine that if we were searching for schema2.custom_type[], it would realize that its not in the map and do something about it, but since we only search for custom_type[], then the old schema's oid is found and returned. Using the postgresql java driver 42.7.7, Postgres 16.6, Java 21. Apologies that I am not attaching a minimum reproducer example, but I am not too sure how to reproduce this in isolation. I use Spring Boot and Hiberante, and they are handling a lot of the connection and statement preparing. If you provide hints on how to isolate, I will gladly do it. @davecramer I saw issue #3562, which seems related. Do you think it could be similar? Thank you!!