diff --git a/pgtype/record.go b/pgtype/record.go index 26411af2..aeca1c54 100644 --- a/pgtype/record.go +++ b/pgtype/record.go @@ -98,9 +98,10 @@ func (dst *Record) DecodeBinary(ci *ConnInfo, src []byte) error { var binaryDecoder BinaryDecoder if dt, ok := ci.DataTypeForOID(fieldOID); ok { - if binaryDecoder, ok = dt.Value.(BinaryDecoder); !ok { - return errors.Errorf("unknown oid while decoding record: %v", fieldOID) - } + binaryDecoder, _ = dt.Value.(BinaryDecoder) + } + if binaryDecoder == nil { + return errors.Errorf("unknown oid while decoding record: %v", fieldOID) } var fieldBytes []byte diff --git a/pgtype/record_test.go b/pgtype/record_test.go index dc01cbbf..7cc8a59f 100644 --- a/pgtype/record_test.go +++ b/pgtype/record_test.go @@ -102,6 +102,28 @@ func TestRecordTranscode(t *testing.T) { } } +func TestRecordWithUnknownOID(t *testing.T) { + conn := testutil.MustConnectPgx(t) + defer testutil.MustClose(t, conn) + + _, err := conn.Exec(`drop type if exists floatrange; + +create type floatrange as range ( + subtype = float8, + subtype_diff = float8mi +);`) + if err != nil { + t.Fatal(err) + } + defer conn.Exec("drop type floatrange") + + var result pgtype.Record + err = conn.QueryRow("select row('foo'::text, floatrange(1, 10), 'bar'::text)").Scan(&result) + if err == nil { + t.Errorf("expected error but none") + } +} + func TestRecordAssignTo(t *testing.T) { var valueSlice []pgtype.Value var interfaceSlice []interface{}