Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: report precise oid type names to pg_type #13355

Merged
merged 1 commit into from
Feb 3, 2017
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
21 changes: 20 additions & 1 deletion pkg/sql/pg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,13 @@ CREATE TABLE pg_catalog.pg_type (
if cat == typCategoryArray {
typInput = arrayInProcOid
}
typname := typ.String()
if n, ok := aliasedOidToName[oid]; ok {
typname = n
}
if err := addRow(
parser.NewDOid(parser.DInt(oid)), // oid
parser.NewDName(typ.String()), // typname
parser.NewDName(typname), // typname
pgNamespacePGCatalog.Oid, // typnamespace
parser.DNull, // typowner
typLen(typ), // typlen
Expand Down Expand Up @@ -1455,6 +1459,21 @@ CREATE TABLE pg_catalog.pg_type (
},
}

// aliasedOidToName maps Postgres object IDs to type names for those OIDs that map to
// Cockroach types that have more than one associated OID, like Int. The name
// for these OIDs will override the type name of the corresponding type when
// looking up the display name for an OID.
var aliasedOidToName = map[oid.Oid]string{
oid.T_float4: "float4",
oid.T_float8: "float8",
oid.T_int2: "int2",
oid.T_int4: "int4",
oid.T_int8: "int8",
oid.T__int2: "int2[]",
oid.T__int4: "int4[]",
oid.T__int8: "int8[]",
}

// typOid is the only OID generation approach that does not use oidHasher, because
// object identifiers for types are not arbitrary, but instead need to be kept in
// sync with Postgres.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/testdata/builtin_function
Original file line number Diff line number Diff line change
Expand Up @@ -1396,17 +1396,17 @@ SELECT format_type(oid, -1) FROM pg_type WHERE typname='string' LIMIT 1
text

query T
SELECT format_type(oid, -1) FROM pg_type WHERE typname='int' LIMIT 1
SELECT format_type(oid, -1) FROM pg_type WHERE typname='int8' LIMIT 1
----
bigint

query T
SELECT format_type(oid, -1) FROM pg_type WHERE typname='float' LIMIT 1
SELECT format_type(oid, -1) FROM pg_type WHERE typname='float8' LIMIT 1
----
double precision

query T
SELECT format_type(oid, -1) FROM pg_type WHERE typname='int[]' LIMIT 1
SELECT format_type(oid, -1) FROM pg_type WHERE typname='int8[]' LIMIT 1
----
bigint[]

Expand Down
80 changes: 40 additions & 40 deletions pkg/sql/testdata/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -653,17 +653,17 @@ oid typname typnamespace typowner typlen typbyval typtype
16 bool 1782195457 NULL 1 true b
17 bytes 1782195457 NULL -1 false b
19 name 1782195457 NULL -1 false b
20 int 1782195457 NULL 8 true b
21 int 1782195457 NULL 8 true b
23 int 1782195457 NULL 8 true b
20 int8 1782195457 NULL 8 true b
21 int2 1782195457 NULL 8 true b
23 int4 1782195457 NULL 8 true b
25 string 1782195457 NULL -1 false b
26 oid 1782195457 NULL 8 true b
700 float 1782195457 NULL 8 true b
701 float 1782195457 NULL 8 true b
1005 int[] 1782195457 NULL -1 false b
1007 int[] 1782195457 NULL -1 false b
700 float4 1782195457 NULL 8 true b
701 float8 1782195457 NULL 8 true b
1005 int2[] 1782195457 NULL -1 false b
1007 int4[] 1782195457 NULL -1 false b
1009 string[] 1782195457 NULL -1 false b
1016 int[] 1782195457 NULL -1 false b
1016 int8[] 1782195457 NULL -1 false b
1043 string 1782195457 NULL -1 false b
1082 date 1782195457 NULL 8 true b
1114 timestamp 1782195457 NULL 24 true b
Expand All @@ -682,17 +682,17 @@ oid typname typcategory typispreferred typisdefined typdelim typrelid
16 bool B false true , 0 0 0
17 bytes U false true , 0 0 0
19 name S false true , 0 0 0
20 int N false true , 0 0 0
21 int N false true , 0 0 0
23 int N false true , 0 0 0
20 int8 N false true , 0 0 0
21 int2 N false true , 0 0 0
23 int4 N false true , 0 0 0
25 string S false true , 0 0 0
26 oid N false true , 0 0 0
700 float N false true , 0 0 0
701 float N false true , 0 0 0
1005 int[] A false true , 0 0 0
1007 int[] A false true , 0 0 0
700 float4 N false true , 0 0 0
701 float8 N false true , 0 0 0
1005 int2[] A false true , 0 0 0
1007 int4[] A false true , 0 0 0
1009 string[] A false true , 0 0 0
1016 int[] A false true , 0 0 0
1016 int8[] A false true , 0 0 0
1043 string S false true , 0 0 0
1082 date D false true , 0 0 0
1114 timestamp D false true , 0 0 0
Expand All @@ -711,17 +711,17 @@ oid typname typinput typoutput typreceive typsend typmodin typmodo
16 bool 0 0 0 0 0 0 0
17 bytes 0 0 0 0 0 0 0
19 name 0 0 0 0 0 0 0
20 int 0 0 0 0 0 0 0
21 int 0 0 0 0 0 0 0
23 int 0 0 0 0 0 0 0
20 int8 0 0 0 0 0 0 0
21 int2 0 0 0 0 0 0 0
23 int4 0 0 0 0 0 0 0
25 string 0 0 0 0 0 0 0
26 oid 0 0 0 0 0 0 0
700 float 0 0 0 0 0 0 0
701 float 0 0 0 0 0 0 0
1005 int[] 2892088402 0 0 0 0 0 0
1007 int[] 2892088402 0 0 0 0 0 0
700 float4 0 0 0 0 0 0 0
701 float8 0 0 0 0 0 0 0
1005 int2[] 2892088402 0 0 0 0 0 0
1007 int4[] 2892088402 0 0 0 0 0 0
1009 string[] 2892088402 0 0 0 0 0 0
1016 int[] 2892088402 0 0 0 0 0 0
1016 int8[] 2892088402 0 0 0 0 0 0
1043 string 0 0 0 0 0 0 0
1082 date 0 0 0 0 0 0 0
1114 timestamp 0 0 0 0 0 0 0
Expand All @@ -740,17 +740,17 @@ oid typname typalign typstorage typnotnull typbasetype typtypmod
16 bool NULL NULL false 0 -1
17 bytes NULL NULL false 0 -1
19 name NULL NULL false 0 -1
20 int NULL NULL false 0 -1
21 int NULL NULL false 0 -1
23 int NULL NULL false 0 -1
20 int8 NULL NULL false 0 -1
21 int2 NULL NULL false 0 -1
23 int4 NULL NULL false 0 -1
25 string NULL NULL false 0 -1
26 oid NULL NULL false 0 -1
700 float NULL NULL false 0 -1
701 float NULL NULL false 0 -1
1005 int[] NULL NULL false 0 -1
1007 int[] NULL NULL false 0 -1
700 float4 NULL NULL false 0 -1
701 float8 NULL NULL false 0 -1
1005 int2[] NULL NULL false 0 -1
1007 int4[] NULL NULL false 0 -1
1009 string[] NULL NULL false 0 -1
1016 int[] NULL NULL false 0 -1
1016 int8[] NULL NULL false 0 -1
1043 string NULL NULL false 0 -1
1082 date NULL NULL false 0 -1
1114 timestamp NULL NULL false 0 -1
Expand All @@ -769,17 +769,17 @@ oid typname typndims typcollation typdefaultbin typdefault typacl
16 bool 0 0 NULL NULL NULL
17 bytes 0 0 NULL NULL NULL
19 name 0 1661428263 NULL NULL NULL
20 int 0 0 NULL NULL NULL
21 int 0 0 NULL NULL NULL
23 int 0 0 NULL NULL NULL
20 int8 0 0 NULL NULL NULL
21 int2 0 0 NULL NULL NULL
23 int4 0 0 NULL NULL NULL
25 string 0 1661428263 NULL NULL NULL
26 oid 0 0 NULL NULL NULL
700 float 0 0 NULL NULL NULL
701 float 0 0 NULL NULL NULL
1005 int[] 0 0 NULL NULL NULL
1007 int[] 0 0 NULL NULL NULL
700 float4 0 0 NULL NULL NULL
701 float8 0 0 NULL NULL NULL
1005 int2[] 0 0 NULL NULL NULL
1007 int4[] 0 0 NULL NULL NULL
1009 string[] 0 1661428263 NULL NULL NULL
1016 int[] 0 0 NULL NULL NULL
1016 int8[] 0 0 NULL NULL NULL
1043 string 0 1661428263 NULL NULL NULL
1082 date 0 0 NULL NULL NULL
1114 timestamp 0 0 NULL NULL NULL
Expand Down