pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: me-honest (@me-honest) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] issue #3658: TypeInfoCache contains wrong entries when switching schemas and using an array of custom user type
Date: Thu, 12 Jun 2025 13:37:09 +0000
Message-ID: <[email protected]> (raw)
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!!
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 #3658: TypeInfoCache contains wrong entries when switching schemas and using an array of custom user type
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