Skip to content
Open
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
2 changes: 1 addition & 1 deletion pkg/sql/sem/eval/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ func performIntToOidCast(
// independent of search_path. UDTs fall through to resolveOID for
// search-path-aware schema qualification.
if typ, ok := types.OidToType[o]; ok {
return tree.NewDOidWithTypeAndName(o, t, typ.PGName()), nil
return tree.NewDOidWithTypeAndName(o, t, typ.SQLStandardName()), nil
}
}
// resolveOID applies Postgres's search-path-aware schema qualification
Expand Down
93 changes: 93 additions & 0 deletions pkg/sql/sem/eval/testdata/eval/regtype
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Regression for #97456: regtype output uses SQL type names, including the
# element type's canonical name followed by [] for ordinary arrays.
eval
1016::OID::REGTYPE::STRING
----
'bigint[]'

eval
1016::REGTYPE::STRING
----
'bigint[]'

eval
1016::OID::REGTYPE::OID
----
1016

eval
1005::OID::REGTYPE::STRING
----
'smallint[]'

eval
1007::OID::REGTYPE::STRING
----
'integer[]'

eval
1000::OID::REGTYPE::STRING
----
'boolean[]'

eval
1009::OID::REGTYPE::STRING
----
'text[]'

eval
1022::OID::REGTYPE::STRING
----
'double precision[]'

eval
1015::OID::REGTYPE::STRING
----
'character varying[]'

# The same canonical names apply to scalar built-in types.
eval
23::OID::REGTYPE::STRING
----
'integer'

eval
20::OID::REGTYPE::STRING
----
'bigint'

# Pseudo-types and vector types retain their distinct names.
eval
2276::OID::REGTYPE::STRING
----
'any'

eval
2283::OID::REGTYPE::STRING
----
'anyelement'

eval
2277::OID::REGTYPE::STRING
----
'anyarray'

eval
22::OID::REGTYPE::STRING
----
'int2vector'

eval
30::OID::REGTYPE::STRING
----
'oidvector'

eval
NULL::OID::REGTYPE
----
NULL

eval
0::OID::REGTYPE::OID
----
0
3 changes: 3 additions & 0 deletions pkg/sql/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,9 @@ func (t *T) SQLStandardNameWithTypmod(haveTypmod bool, typmod int, useFQName boo
var buf strings.Builder
switch t.Family() {
case AnyFamily:
if t.Oid() == oid.T_any {
return "any"
}
return "anyelement"
case ArrayFamily:
switch t.Oid() {
Expand Down
15 changes: 15 additions & 0 deletions pkg/sql/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,21 @@ func TestSQLStandardName(t *testing.T) {
}
}

func TestSQLStandardNamePseudoTypes(t *testing.T) {
for _, tc := range []struct {
typ *T
expected string
}{
{Any, "any"},
{AnyElement, "anyelement"},
{AnyArray, "anyarray"},
} {
t.Run(tc.expected, func(t *testing.T) {
require.Equal(t, tc.expected, tc.typ.SQLStandardName())
})
}
}

func TestWithoutTypeModifiers(t *testing.T) {
const userDefinedOID = oidext.CockroachPredefinedOIDMax + 700
domain := MakeDomain(MakeString(2), userDefinedOID, userDefinedOID+1)
Expand Down