@@ -20,6 +20,8 @@ import (
2020
2121 "github.com/dolthub/dolt/go/libraries/doltcore/sqle/resolve"
2222 "github.com/dolthub/go-mysql-server/sql"
23+
24+ "github.com/dolthub/doltgresql/server/settings"
2325)
2426
2527// regclass_IoInput is the implementation for IoInput that avoids circular dependencies by being declared in a separate
@@ -109,25 +111,56 @@ func regclass_IoInput(ctx *sql.Context, input string) (uint32, error) {
109111// regclass_IoOutput is the implementation for IoOutput that avoids circular dependencies by being declared in a separate
110112// package.
111113func regclass_IoOutput (ctx * sql.Context , oid uint32 ) (string , error ) {
114+ // Find all the schemas on the search path. If a schema is on the search path, then it is not included in the
115+ // output of relation name. If the relation's schema is not on the search path, then it is explicitly included.
116+ schemasMap , err := settings .GetCurrentSchemasAsMap (ctx )
117+ if err != nil {
118+ return "" , err
119+ }
120+
121+ // The pg_catalog schema is always implicitly part of the search path
122+ // https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-CATALOG
123+ schemasMap ["pg_catalog" ] = struct {}{}
124+
112125 output := strconv .FormatUint (uint64 (oid ), 10 )
113- err : = RunCallback (ctx , oid , Callbacks {
126+ err = RunCallback (ctx , oid , Callbacks {
114127 Index : func (ctx * sql.Context , schema ItemSchema , table ItemTable , index ItemIndex ) (cont bool , err error ) {
115128 output = index .Item .ID ()
116129 if output == "PRIMARY" {
117- output = fmt .Sprintf ("%s_pkey" , index .Item .Table ())
130+ schemaName := schema .Item .SchemaName ()
131+ if _ , ok := schemasMap [schemaName ]; ok {
132+ output = fmt .Sprintf ("%s_pkey" , index .Item .Table ())
133+ } else {
134+ output = fmt .Sprintf ("%s.%s_pkey" , schemaName , index .Item .Table ())
135+ }
118136 }
119137 return false , nil
120138 },
121139 Sequence : func (ctx * sql.Context , schema ItemSchema , sequence ItemSequence ) (cont bool , err error ) {
122- output = sequence .Item .Name
140+ schemaName := schema .Item .SchemaName ()
141+ if _ , ok := schemasMap [schemaName ]; ok {
142+ output = sequence .Item .Name
143+ } else {
144+ output = fmt .Sprintf ("%s.%s" , schemaName , sequence .Item .Name )
145+ }
123146 return false , nil
124147 },
125148 Table : func (ctx * sql.Context , schema ItemSchema , table ItemTable ) (cont bool , err error ) {
126- output = table .Item .Name ()
149+ schemaName := schema .Item .SchemaName ()
150+ if _ , ok := schemasMap [schemaName ]; ok {
151+ output = table .Item .Name ()
152+ } else {
153+ output = fmt .Sprintf ("%s.%s" , schemaName , table .Item .Name ())
154+ }
127155 return false , nil
128156 },
129157 View : func (ctx * sql.Context , schema ItemSchema , view ItemView ) (cont bool , err error ) {
130- output = view .Item .Name
158+ schemaName := schema .Item .SchemaName ()
159+ if _ , ok := schemasMap [schemaName ]; ok {
160+ output = view .Item .Name
161+ } else {
162+ output = fmt .Sprintf ("%s.%s" , schemaName , view .Item .Name )
163+ }
131164 return false , nil
132165 },
133166 })
0 commit comments