ResolveTarget performs name resolution for a table name when the target object is not expected to exist already.
( ctx context.Context, r TableNameTargetResolver, curDb string, searchPath sessiondata.SearchPath, )
| 331 | // ResolveTarget performs name resolution for a table name when |
| 332 | // the target object is not expected to exist already. |
| 333 | func (t *TableName) ResolveTarget( |
| 334 | ctx context.Context, r TableNameTargetResolver, curDb string, searchPath sessiondata.SearchPath, |
| 335 | ) (found bool, scMeta SchemaMeta, err error) { |
| 336 | if t.ExplicitSchema { |
| 337 | // pg_temp can be used as an alias for the current sessions temporary schema. |
| 338 | // We must perform this resolution before looking up the object. This |
| 339 | // resolution only succeeds if the session already has a temporary schema. |
| 340 | scName, err := searchPath.MaybeResolveTemporarySchema(t.Schema()) |
| 341 | if err != nil { |
| 342 | return false, nil, err |
| 343 | } |
| 344 | if t.ExplicitCatalog { |
| 345 | // Already 3 parts: nothing to do. |
| 346 | return r.LookupSchema(ctx, t.Catalog(), scName) |
| 347 | } |
| 348 | // Two parts: D.T. |
| 349 | // Try to use the current database, and be satisfied if it's sufficient to find the object. |
| 350 | if found, scMeta, err = r.LookupSchema(ctx, curDb, scName); found || err != nil { |
| 351 | if err == nil { |
| 352 | t.CatalogName = Name(curDb) |
| 353 | } |
| 354 | return found, scMeta, err |
| 355 | } |
| 356 | // No luck so far. Compatibility with CockroachDB v1.1: use D.public.T instead. |
| 357 | if found, scMeta, err = r.LookupSchema(ctx, t.Schema(), PublicSchema); found || err != nil { |
| 358 | if err == nil { |
| 359 | t.CatalogName = t.SchemaName |
| 360 | t.SchemaName = PublicSchemaName |
| 361 | t.ExplicitCatalog = true |
| 362 | } |
| 363 | return found, scMeta, err |
| 364 | } |
| 365 | // Welp, really haven't found anything. |
| 366 | return false, nil, nil |
| 367 | } |
| 368 | |
| 369 | // This is a naked table name. Use the current schema = the first |
| 370 | // valid item in the search path. |
| 371 | iter := searchPath.IterWithoutImplicitPGSchemas() |
| 372 | for scName, ok := iter.Next(); ok; scName, ok = iter.Next() { |
| 373 | if found, scMeta, err = r.LookupSchema(ctx, curDb, scName); found || err != nil { |
| 374 | if err == nil { |
| 375 | t.CatalogName = Name(curDb) |
| 376 | t.SchemaName = Name(scName) |
| 377 | } |
| 378 | break |
| 379 | } |
| 380 | } |
| 381 | return found, scMeta, err |
| 382 | } |
| 383 | |
| 384 | // Resolve is used for table prefixes. This is adequate for table |
| 385 | // patterns with stars, e.g. AllTablesSelector. |
nothing calls this directly
no test coverage detected