2
0

Unregistered OIDs are handled the same as unknown OIDs

This improves handling of unregistered types. In general, they should
"just work". But there are performance benefits gained and some edge
cases avoided by registering types. Updated documentation to mention
this.

https://github.com/jackc/pgx/issues/1445
This commit is contained in:
Jack Christensen
2022-12-23 13:11:28 -06:00
parent d737852654
commit 456a242f5c
5 changed files with 121 additions and 34 deletions
+6 -6
View File
@@ -1326,16 +1326,16 @@ func (m *Map) PlanEncode(oid uint32, format int16, value any) EncodePlan {
}
var dt *Type
if oid == 0 {
if dataType, ok := m.TypeForOID(oid); ok {
dt = dataType
} else {
// If no type for the OID was found, then either it is unknowable (e.g. the simple protocol) or it is an
// unregistered type. In either case try to find the type and OID that matches the value (e.g. a []byte would be
// registered to PostgreSQL bytea).
if dataType, ok := m.TypeForValue(value); ok {
dt = dataType
oid = dt.OID // Preserve assumed OID in case we are recursively called below.
}
} else {
if dataType, ok := m.TypeForOID(oid); ok {
dt = dataType
}
}
if dt != nil {