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: 3 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type parameterStatus struct {
serverVersion int
currentLocation *time.Location
inHotStandby, defaultTransactionReadOnly sql.NullBool
isRedshift bool
}

type format int
Expand Down Expand Up @@ -1558,6 +1559,8 @@ func (cn *conn) processParameterStatus(r *readBuf) {
switch r.string() {
default:
// ignore
case "padb_version":
cn.parameterStatus.isRedshift = true
case "server_version":
var major1, major2 int
_, err := fmt.Sscanf(r.string(), "%d.%d", &major1, &major2)
Expand Down
7 changes: 0 additions & 7 deletions oid/doc.go

This file was deleted.

81 changes: 0 additions & 81 deletions oid/gen.go

This file was deleted.

6 changes: 4 additions & 2 deletions oid/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Code generated by gen.go. DO NOT EDIT.

// Package oid contains OID constants as defined by the Postgres server.
package oid

// Oid is a Postgres Object ID.
type Oid uint32

const (
T_bool Oid = 16
T_bytea Oid = 17
Expand Down
28 changes: 28 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func (rs *rows) ColumnTypeScanType(index int) reflect.Type {

// ColumnTypeDatabaseTypeName return the database system type name.
func (rs *rows) ColumnTypeDatabaseTypeName(index int) string {
if rs.cn.parameterStatus.isRedshift {
if n, ok := redshiftTypeName[rs.colTyps[index].OID]; ok {
return n
}
}
return rs.colTyps[index].Name()
}

Expand Down Expand Up @@ -243,3 +248,26 @@ func (fd fieldDesc) PrecisionScale() (precision, scale int64, ok bool) {
return 0, 0, false
}
}

var redshiftTypeName = map[oid.Oid]string{
86: "PG_SHADOW",
87: "PG_GROUP",
88: "PG_DATABASE",
90: "PG_TABLESPACE",
635: "_SPECTRUM_ARRAY",
636: "_SPECTRUM_MAP",
637: "_SPECTRUM_STRUCT",
1188: "INTERVALY2M",
1189: "_INTERVALY2M",
1190: "INTERVALD2S",
1191: "_INTERVALD2S",
2935: "HLLSKETCH",
3000: "GEOMETRY",
3001: "GEOGRAPHY",
4000: "SUPER",
4600: "USERITEM",
4601: "_USERITEM",
4602: "ROLEITEM",
4603: "_ROLEITEM",
6551: "VARBYTE",
}
50 changes: 31 additions & 19 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,42 @@ import (

func TestDataTypeName(t *testing.T) {
tests := []struct {
typ oid.Oid
name string
typ oid.Oid
name string
redshift bool
}{
{oid.T_int8, "INT8"},
{oid.T_int4, "INT4"},
{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"},
{oid.T_time, "TIME"},
{oid.T_timetz, "TIMETZ"},
{oid.T_timestamp, "TIMESTAMP"},
{oid.T_timestamptz, "TIMESTAMPTZ"},
{oid.T_bytea, "BYTEA"},
{oid.T_int8, "INT8", false},
{oid.T_int4, "INT4", false},
{oid.T_int2, "INT2", false},
{oid.T_varchar, "VARCHAR", false},
{oid.T_text, "TEXT", false},
{oid.T_bit, "BIT", false},
{oid.T_varbit, "VARBIT", false},
{oid.T_bool, "BOOL", false},
{oid.T_numeric, "NUMERIC", false},
{oid.T_date, "DATE", false},
{oid.T_time, "TIME", false},
{oid.T_timetz, "TIMETZ", false},
{oid.T_timestamp, "TIMESTAMP", false},
{oid.T_timestamptz, "TIMESTAMPTZ", false},
{oid.T_bytea, "BYTEA", false},

{oid.T_int8, "INT8", true},
{635, "_SPECTRUM_ARRAY", true},
{636, "_SPECTRUM_MAP", true},
{637, "_SPECTRUM_STRUCT", true},
{4000, "SUPER", true},

{635, "", false},
}

for _, tt := range tests {
t.Run("", func(t *testing.T) {
have := fieldDesc{OID: tt.typ}
if name := have.Name(); name != tt.name {
have := &rows{
cn: &conn{parameterStatus: parameterStatus{isRedshift: tt.redshift}},
rowsHeader: rowsHeader{colTyps: []fieldDesc{{OID: tt.typ}}},
}
if name := have.ColumnTypeDatabaseTypeName(0); name != tt.name {
t.Errorf("\nhave: %s\nwant: %s", name, tt.name)
}
})
Expand Down