diff --git a/query_test.go b/query_test.go index 28b0fb5d..5b0e85e2 100644 --- a/query_test.go +++ b/query_test.go @@ -197,6 +197,33 @@ func TestConnQueryValuesWhenUnableToDecode(t *testing.T) { require.Equal(t, "({1},)", values[0]) } +func TestConnQueryValuesWithUnknownOID(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) + defer closeConn(t, conn) + + tx, err := conn.Begin(ctx) + require.NoError(t, err) + defer tx.Rollback(ctx) + + _, err = tx.Exec(ctx, "create type fruit as enum('orange', 'apple', 'pear')") + require.NoError(t, err) + + rows, err := conn.Query(context.Background(), "select 'orange'::fruit") + require.NoError(t, err) + defer rows.Close() + + require.True(t, rows.Next()) + + values, err := rows.Values() + require.NoError(t, err) + require.Equal(t, "orange", values[0]) +} + // https://github.com/jackc/pgx/issues/478 func TestConnQueryReadRowMultipleTimes(t *testing.T) { t.Parallel() diff --git a/rows.go b/rows.go index 3474dd79..c16a64bd 100644 --- a/rows.go +++ b/rows.go @@ -237,7 +237,24 @@ func (rows *connRows) Values() ([]interface{}, error) { rows.fatal(errors.New("Unknown format code")) } } else { - rows.fatal(errors.New("Unknown type")) + switch fd.Format { + case TextFormatCode: + decoder := &pgtype.GenericText{} + err := decoder.DecodeText(rows.connInfo, buf) + if err != nil { + rows.fatal(err) + } + values = append(values, decoder.Get()) + case BinaryFormatCode: + decoder := &pgtype.GenericBinary{} + err := decoder.DecodeBinary(rows.connInfo, buf) + if err != nil { + rows.fatal(err) + } + values = append(values, decoder.Get()) + default: + rows.fatal(errors.New("Unknown format code")) + } } if rows.Err() != nil {