Skip to content

Commit

Permalink
sql: properly report information_schema functions in metadata
Browse files Browse the repository at this point in the history
Prior to this patch, the `information_schema` functions were listed
with the `information_schema.` prefix in the pg_catalog namespace.
This was incorrect and caused confusion during tab completion.

Release note (bug fix): The compatibility scalar functions in
`information_schema` are now listed in the proper namespace in
`pg_catalog.pg_proc`.
  • Loading branch information
knz committed Feb 6, 2023
1 parent 0723521 commit 3f50d81
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/cli/clisqlshell/testdata/complete/composite_names
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ select "PG_CATALOG".@
complete 0 20
msg: ""
(no completions generated)

complete
select information_schema . _pg_index@
----
complete 0 37
msg: ""
completions:
- "functions":
"information_schema._pg_index_position(" (Not usable; exposed only for compatibility with PostgreSQL) -> "information_schema._pg_index_position(" (0, 30)
2 changes: 1 addition & 1 deletion pkg/cli/clisqlshell/testdata/complete/sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ completions:
"\"extract_duration\"(" ((from schema pg_catalog) Extracts `element` from `input`) -> "\"extract_duration\"(" (0, 0)
"\"family\"(" ((from schema pg_catalog) Extracts the IP family of the value; 4 for IPv4, 6 for IPv6) -> "\"family\"(" (0, 0)
"\"greatest\"(" ((from schema pg_catalog) Returns the element with the greatest value) -> "\"greatest\"(" (0, 0)
"\"information_schema._pg_char_max_length\"(" ((from schema pg_catalog) Not usable; exposed only for compatibility with PostgreSQL) -> "\"information_schema._pg_char_max_length\"(" (0, 0)
"\"least\"(" ((from schema pg_catalog) Returns the element with the lowest value) -> "\"least\"(" (0, 0)
... entries omitted ...
- "keyword":
"ABORT" (unreserved) -> "ABORT" (0, 0)
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2753,9 +2753,13 @@ CREATE TABLE crdb_internal.builtin_functions (
props, overloads := builtinsregistry.GetBuiltinProperties(name)
schema := catconstants.PgCatalogName
const crdbInternal = catconstants.CRDBInternalSchemaName + "."
const infoSchema = catconstants.InformationSchemaName + "."
if strings.HasPrefix(name, crdbInternal) {
name = name[len(crdbInternal):]
schema = catconstants.CRDBInternalSchemaName
} else if strings.HasPrefix(name, infoSchema) {
name = name[len(infoSchema):]
schema = catconstants.InformationSchemaName
}
for _, f := range overloads {
if err := addRow(
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/pg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2357,9 +2357,13 @@ func addPgProcBuiltinRow(name string, addRow func(...tree.Datum) error) error {
_, overloads := builtinsregistry.GetBuiltinProperties(name)
nspOid := tree.NewDOid(catconstants.PgCatalogID)
const crdbInternal = catconstants.CRDBInternalSchemaName + "."
const infoSchema = catconstants.InformationSchemaName + "."
if strings.HasPrefix(name, crdbInternal) {
nspOid = tree.NewDOid(catconstants.CrdbInternalID)
name = name[len(crdbInternal):]
} else if strings.HasPrefix(name, infoSchema) {
nspOid = tree.NewDOid(catconstants.InformationSchemaID)
name = name[len(infoSchema):]
}

for _, builtin := range overloads {
Expand Down

0 comments on commit 3f50d81

Please sign in to comment.