diff --git a/CHANGELOG.md b/CHANGELOG.md index 369a9093..36cc4fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix *ConnPool.Deallocate() not deleting prepared statement from map * Fix stdlib not logging unprepared query SQL (Krzysztof Dryƛ) +* Fix Rows.Values() with varchar binary format ## Features diff --git a/query.go b/query.go index 71df1cd7..50c8e290 100644 --- a/query.go +++ b/query.go @@ -345,6 +345,8 @@ func (rows *Rows) Values() ([]interface{}, error) { values = append(values, vr.ReadString(vr.Len())) case BinaryFormatCode: switch vr.Type().DataType { + case TextOid, VarcharOid: + values = append(values, decodeText(vr)) case BoolOid: values = append(values, decodeBool(vr)) case ByteaOid: diff --git a/query_test.go b/query_test.go index d85c67c1..2cf8b3cd 100644 --- a/query_test.go +++ b/query_test.go @@ -52,7 +52,7 @@ func TestConnQueryValues(t *testing.T) { var rowCount int32 - rows, err := conn.Query("select 'foo', n, null, n::oid from generate_series(1,$1) n", 10) + rows, err := conn.Query("select 'foo'::text, 'bar'::varchar, n, null, n::oid from generate_series(1,$1) n", 10) if err != nil { t.Fatalf("conn.Query failed: %v", err) } @@ -65,26 +65,26 @@ func TestConnQueryValues(t *testing.T) { if err != nil { t.Fatalf("rows.Values failed: %v", err) } - if len(values) != 4 { - t.Errorf("Expected rows.Values to return 4 values, but it returned %d", len(values)) + if len(values) != 5 { + t.Errorf("Expected rows.Values to return 5 values, but it returned %d", len(values)) } if values[0] != "foo" { t.Errorf(`Expected values[0] to be "foo", but it was %v`, values[0]) } - if values[0] != "foo" { - t.Errorf(`Expected values[0] to be "foo", but it was %v`, values[0]) + if values[1] != "bar" { + t.Errorf(`Expected values[1] to be "bar", but it was %v`, values[1]) } - if values[1] != rowCount { - t.Errorf(`Expected values[1] to be %d, but it was %d`, rowCount, values[1]) + if values[2] != rowCount { + t.Errorf(`Expected values[2] to be %d, but it was %d`, rowCount, values[2]) } - if values[2] != nil { - t.Errorf(`Expected values[2] to be %v, but it was %d`, nil, values[2]) + if values[3] != nil { + t.Errorf(`Expected values[3] to be %v, but it was %d`, nil, values[3]) } - if values[3] != pgx.Oid(rowCount) { - t.Errorf(`Expected values[3] to be %d, but it was %d`, rowCount, values[3]) + if values[4] != pgx.Oid(rowCount) { + t.Errorf(`Expected values[4] to be %d, but it was %d`, rowCount, values[4]) } }