Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ newer. Previously PostgreSQL 8.4 and newer were supported.

- Decode bpchar into a string ([#949]).

- Recognize float types in ColumnTypeScanType() ([#1166]).
- Recognize bit/varbit ([#743]) and float types ([#1166]) in ColumnTypeScanType().

- Accept `PGGSSLIB` and `PGKRBSRVNAME` environment variables ([#1143]).

Expand All @@ -57,6 +57,7 @@ newer. Previously PostgreSQL 8.4 and newer were supported.

[#595]: https://github.com/lib/pq/pull/595
[#745]: https://github.com/lib/pq/pull/745
[#743]: https://github.com/lib/pq/pull/743
[#838]: https://github.com/lib/pq/pull/838
[#949]: https://github.com/lib/pq/pull/949
[#1125]: https://github.com/lib/pq/pull/1125
Expand Down
4 changes: 3 additions & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (fd fieldDesc) Type() reflect.Type {
return reflect.TypeOf(float64(0))
case oid.T_float4:
return reflect.TypeOf(float32(0))
case oid.T_varchar, oid.T_text:
case oid.T_varchar, oid.T_text, oid.T_varbit, oid.T_bit:
return reflect.TypeOf("")
case oid.T_bool:
return reflect.TypeOf(false)
Expand All @@ -56,6 +56,8 @@ func (fd fieldDesc) Length() (length int64, ok bool) {
return math.MaxInt64, true
case oid.T_varchar, oid.T_bpchar:
return int64(fd.Mod - headerSize), true
case oid.T_varbit, oid.T_bit:
return int64(fd.Mod), true
default:
return 0, false
}
Expand Down
26 changes: 24 additions & 2 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func TestDataTypeName(t *testing.T) {
{oid.T_int2, "INT2"},
{oid.T_varchar, "VARCHAR"},
{oid.T_text, "TEXT"},
{oid.T_bit, "BIT"},
{oid.T_varbit, "VARBIT"},
{oid.T_bool, "BOOL"},
{oid.T_numeric, "NUMERIC"},
{oid.T_date, "DATE"},
Expand Down Expand Up @@ -47,6 +49,8 @@ func TestDataType(t *testing.T) {
{oid.T_int2, reflect.Int16},
{oid.T_varchar, reflect.String},
{oid.T_text, reflect.String},
{oid.T_bit, reflect.String},
{oid.T_varbit, reflect.String},
{oid.T_bool, reflect.Bool},
{oid.T_date, reflect.Struct},
{oid.T_time, reflect.Struct},
Expand Down Expand Up @@ -76,6 +80,8 @@ func TestDataTypeLength(t *testing.T) {
{oid.T_varchar, 65535, 9, 5, true},
{oid.T_text, 65535, -1, math.MaxInt64, true},
{oid.T_bytea, 65535, -1, math.MaxInt64, true},
{oid.T_bit, 0, 10, 10, true},
{oid.T_varbit, 0, 10, 10, true},
}

for i, tt := range tts {
Expand Down Expand Up @@ -160,6 +166,20 @@ func TestRowsColumnTypes(t *testing.T) {
DecimalSize: decimalSize{Precision: 0, Scale: 0, OK: false},
ScanType: reflect.TypeOf(float64(0)),
},
{
Name: "bit4",
TypeName: "BIT",
Length: length{Len: 4, OK: true},
DecimalSize: decimalSize{Precision: 0, Scale: 0, OK: false},
ScanType: reflect.TypeOf(""),
},
{
Name: "varbit10",
TypeName: "VARBIT",
Length: length{Len: 10, OK: true},
DecimalSize: decimalSize{Precision: 0, Scale: 0, OK: false},
ScanType: reflect.TypeOf(""),
},
}

db := pqtest.MustDB(t)
Expand All @@ -169,7 +189,9 @@ func TestRowsColumnTypes(t *testing.T) {
1 as a,
text 'bar' as bar,
1.28::numeric(9, 2) as dec,
3.1415::float8 as f
3.1415::float8 as f,
'1111'::bit(4) as bit4,
'1111'::varbit(10) as varbit10
`)
if err != nil {
t.Fatal(err)
Expand All @@ -180,7 +202,7 @@ func TestRowsColumnTypes(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(columns) != 4 {
if len(columns) != 6 {
t.Errorf("expected 4 columns found %d", len(columns))
}

Expand Down
Loading