{"id":"867f3d854071a371","repo":"jackc/pgx","slug":"domain-base-type-oid-not-registered","errorCode":null,"errorMessage":"domain base type OID not registered","messagePattern":"domain base type OID not registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conn.go","lineNumber":1333,"sourceCode":"\t\t}\n\n\t\tdt, ok := c.TypeMap().TypeForOID(elementOID)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"array element OID not registered\")\n\t\t}\n\n\t\treturn &pgtype.Type{Name: typeName, OID: oid, Codec: &pgtype.ArrayCodec{ElementType: dt}}, nil\n\tcase \"c\": // composite\n\t\tfields, err := c.getCompositeFields(ctx, oid)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\treturn &pgtype.Type{Name: typeName, OID: oid, Codec: &pgtype.CompositeCodec{Fields: fields}}, nil\n\tcase \"d\": // domain\n\t\tdt, ok := c.TypeMap().TypeForOID(typbasetype)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"domain base type OID not registered\")\n\t\t}\n\n\t\treturn &pgtype.Type{Name: typeName, OID: oid, Codec: dt.Codec}, nil\n\tcase \"e\": // enum\n\t\treturn &pgtype.Type{Name: typeName, OID: oid, Codec: &pgtype.EnumCodec{}}, nil\n\tcase \"r\": // range\n\t\telementOID, err := c.getRangeElementOID(ctx, oid)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tdt, ok := c.TypeMap().TypeForOID(elementOID)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"range element OID not registered\")\n\t\t}\n\n\t\treturn &pgtype.Type{Name: typeName, OID: oid, Codec: &pgtype.RangeCodec{ElementType: dt}}, nil\n\tcase \"m\": // multirange","sourceCodeStart":1315,"sourceCodeEnd":1351,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/conn.go#L1315-L1351","documentation":"Returned by Conn.LoadType for a typtype='d' (domain) type when its base type OID (pg_type.typbasetype) is not found in the connection's TypeMap (conn.go:1331-1333). A domain is just a named constraint over a base type, so pgx reuses the base type's Codec; without the base registered it cannot construct the domain codec.","triggerScenarios":"Calling Conn.LoadType on a domain whose underlying base type is custom and unregistered — e.g. CREATE DOMAIN positive_int AS my_int where my_int is a custom type that has not been loaded yet.","commonSituations":"Loading a domain defined over a custom base type without first registering the base; schema changes that introduce a domain over a new base type; migrations that create domains before their base types are mapped.","solutions":["LoadType the base type first and register it, then LoadType the domain.","Walk pg_type.typbasetype chains in dependency order before loading domains.","If the base is built-in, ensure your TypeMap has the default codecs loaded (it does by default).","Register the base codec manually via RegisterType if you provide a custom implementation."],"exampleFix":"// before\ndt, err := conn.LoadType(ctx, \"pos_int\") // domain over custom base 'my_int'\n// -> \"domain base type OID not registered\"\n\n// after\nbase, err := conn.LoadType(ctx, \"my_int\")\nif err != nil { return err }\nconn.TypeMap().RegisterType(base)\ndt, err := conn.LoadType(ctx, \"pos_int\")","handlingStrategy":"validation","validationCode":"// resolve typbasetype and ensure it is registered first\nvar baseOID uint32\nconn.QueryRow(ctx, \"select typbasetype from pg_type where typname=$1\", domainName).Scan(&baseOID)\nif _, ok := conn.TypeMap().TypeForOID(baseOID); !ok {\n    // LoadType the base, register, then LoadType the domain\n}","typeGuard":"func baseRegistered(m *pgtype.Map, baseOID uint32) bool { _, ok := m.TypeForOID(baseOID); return ok }","tryCatchPattern":"if t, err := conn.LoadType(ctx, domainName); err != nil {\n    if strings.Contains(err.Error(), \"domain base type OID not registered\") {\n        // load+register base, retry\n    }\n    return nil, err\n}","preventionTips":["LoadType base types before domains.","Walk typbasetype chains to discover and register transitively.","Keep custom base codecs registered before loading derived domains."],"tags":["types","loadtype","registration","domain"],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}