Skip to content

Commit

Permalink
Merge pull request #2077 from nicois/nicois/pgtype-other-schema-fix
Browse files Browse the repository at this point in the history
Fix bug relating to reuse of types
  • Loading branch information
jackc authored Jul 8, 2024
2 parents c64fa0f + b770252 commit 3563a2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion derived_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ func (c *Conn) LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Typ
if type_ != nil {
m.RegisterType(type_)
if ti.NspName != "" {
m.RegisterType(&pgtype.Type{Name: ti.NspName + "." + type_.Name, OID: type_.OID, Codec: type_.Codec})
nspType := &pgtype.Type{Name: ti.NspName + "." + type_.Name, OID: type_.OID, Codec: type_.Codec}
m.RegisterType(nspType)
result = append(result, nspType)
}
result = append(result, type_)
}
Expand Down
11 changes: 7 additions & 4 deletions derived_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ create type dtype_test as (

types, err := conn.LoadTypes(ctx, []string{"dtype_test"})
require.NoError(t, err)
require.Len(t, types, 3)
require.Equal(t, types[0].Name, "anotheruint64")
require.Equal(t, types[1].Name, "_anotheruint64")
require.Equal(t, types[2].Name, "dtype_test")
require.Len(t, types, 6)
require.Equal(t, types[0].Name, "public.anotheruint64")
require.Equal(t, types[1].Name, "anotheruint64")
require.Equal(t, types[2].Name, "public._anotheruint64")
require.Equal(t, types[3].Name, "_anotheruint64")
require.Equal(t, types[4].Name, "public.dtype_test")
require.Equal(t, types[5].Name, "dtype_test")
})
}
11 changes: 7 additions & 4 deletions pgtype/derived_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ create type dt_test as (
defer conn.Exec(ctx, "drop type dt_test")

dtypes, err := conn.LoadTypes(ctx, []string{"dt_test"})
require.Len(t, dtypes, 3)
require.Equal(t, dtypes[0].Name, "dt_uint64")
require.Equal(t, dtypes[1].Name, "_dt_uint64")
require.Equal(t, dtypes[2].Name, "dt_test")
require.Len(t, dtypes, 6)
require.Equal(t, dtypes[0].Name, "public.dt_uint64")
require.Equal(t, dtypes[1].Name, "dt_uint64")
require.Equal(t, dtypes[2].Name, "public._dt_uint64")
require.Equal(t, dtypes[3].Name, "_dt_uint64")
require.Equal(t, dtypes[4].Name, "public.dt_test")
require.Equal(t, dtypes[5].Name, "dt_test")
require.NoError(t, err)
conn.TypeMap().RegisterTypes(dtypes)

Expand Down

0 comments on commit 3563a2b

Please sign in to comment.