Hard code standard PostgreSQL types
Instead of needing to instrospect the database on connection preload the standard OID / type map. Types from extensions (like hstore) and custom types can be registered by the application developer. Otherwise, they will be treated as strings.
This commit is contained in:
@@ -14,6 +14,20 @@ func TestHstoreArrayTranscode(t *testing.T) {
|
||||
conn := testutil.MustConnectPgx(t)
|
||||
defer testutil.MustCloseContext(t, conn)
|
||||
|
||||
var hstoreOID pgtype.OID
|
||||
err := conn.QueryRow(context.Background(), "select t.oid from pg_type t where t.typname='hstore';").Scan(&hstoreOID)
|
||||
if err != nil {
|
||||
t.Fatalf("did not find hstore OID, %v", err)
|
||||
}
|
||||
conn.ConnInfo.RegisterDataType(pgtype.DataType{Value: &pgtype.Hstore{}, Name: "hstore", OID: hstoreOID})
|
||||
|
||||
var hstoreArrayOID pgtype.OID
|
||||
err = conn.QueryRow(context.Background(), "select t.oid from pg_type t where t.typname='_hstore';").Scan(&hstoreArrayOID)
|
||||
if err != nil {
|
||||
t.Fatalf("did not find _hstore OID, %v", err)
|
||||
}
|
||||
conn.ConnInfo.RegisterDataType(pgtype.DataType{Value: &pgtype.HstoreArray{}, Name: "_hstore", OID: hstoreArrayOID})
|
||||
|
||||
text := func(s string) pgtype.Text {
|
||||
return pgtype.Text{String: s, Status: pgtype.Present}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user