MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Resolve

Method Resolve

pkg/sql/sem/tree/name_resolution.go:386–435  ·  view source on GitHub ↗

Resolve is used for table prefixes. This is adequate for table patterns with stars, e.g. AllTablesSelector.

(
	ctx context.Context, r TableNameTargetResolver, curDb string, searchPath sessiondata.SearchPath,
)

Source from the content-addressed store, hash-verified

384// Resolve is used for table prefixes. This is adequate for table
385// patterns with stars, e.g. AllTablesSelector.
386func (tp *TableNamePrefix) Resolve(
387 ctx context.Context, r TableNameTargetResolver, curDb string, searchPath sessiondata.SearchPath,
388) (found bool, scMeta SchemaMeta, err error) {
389 if tp.ExplicitSchema {
390 // pg_temp can be used as an alias for the current sessions temporary schema.
391 // We must perform this resolution before looking up the object. This
392 // resolution only succeeds if the session already has a temporary schema.
393 scName, err := searchPath.MaybeResolveTemporarySchema(tp.Schema())
394 if err != nil {
395 return false, nil, err
396 }
397 if tp.ExplicitCatalog {
398 // Catalog name is explicit; nothing to do.
399 return r.LookupSchema(ctx, tp.Catalog(), scName)
400 }
401 // Try with the current database. This may be empty, because
402 // virtual schemas exist even when the db name is empty
403 // (CockroachDB extension).
404 if found, scMeta, err = r.LookupSchema(ctx, curDb, scName); found || err != nil {
405 if err == nil {
406 tp.CatalogName = Name(curDb)
407 }
408 return found, scMeta, err
409 }
410 // No luck so far. Compatibility with CockroachDB v1.1: use D.public.T instead.
411 if found, scMeta, err = r.LookupSchema(ctx, tp.Schema(), PublicSchema); found || err != nil {
412 if err == nil {
413 tp.CatalogName = tp.SchemaName
414 tp.SchemaName = PublicSchemaName
415 tp.ExplicitCatalog = true
416 }
417 return found, scMeta, err
418 }
419 // No luck.
420 return false, nil, nil
421 }
422 // This is a naked table name. Use the current schema = the first
423 // valid item in the search path.
424 iter := searchPath.IterWithoutImplicitPGSchemas()
425 for scName, ok := iter.Next(); ok; scName, ok = iter.Next() {
426 if found, scMeta, err = r.LookupSchema(ctx, curDb, scName); found || err != nil {
427 if err == nil {
428 tp.CatalogName = Name(curDb)
429 tp.SchemaName = Name(scName)
430 }
431 break
432 }
433 }
434 return found, scMeta, err
435}
436
437// ResolveFunction transforms an UnresolvedName to a FunctionDefinition.
438//

Callers

nothing calls this directly

Calls 7

SchemaMethod · 0.95
CatalogMethod · 0.95
NameTypeAlias · 0.85
LookupSchemaMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected