Skip to content

Conversation

jeewonhh
Copy link
Contributor

This PR allows users to execute queries that refer to attached catalogs from a detached default catalog. This is useful in multi-connection settings.

Say con1's default catalog, db1, is detached and db2 is still attached. Previously, querying a table in db2 from con1 would give a binder error:

-- from con1, gives "Binder Error: Catalog "db1" does not exist!"
FROM db2.tbl; 

To allow the above query, Binder::BindSchemaOrCatalog now uses Catalog::GetCatalogEntry instead of Catalog::GetCatalog to avoid immediately throwing binder exception when default catalog (db1) is not found. This allows the catalog/schema names of db2 to be set properly and go through the rest of binding phase.

Also, we want to throw a sensible error when con1 is referencing some non-existent table in db2. When an entry is not found, DuckDB calls CreateMissingEntryException, which creates default entries in the default catalog (db1). Previously, the error message looked like:

-- "Binder Error: Catalog "db1" does not exist!" 
FROM db2.non_existent_tbl;

-- with fully qualifed path, "Binder Error: Catalog "" does not exist!"
FROM db2.main.non_existent_tbl;

This PR immediately throws a catalog exception when an entry is missing and the default catalog is not attached, avoiding going on to create default entries. Now, it will throw "Catalog Error: Table with name non_existent_table does not exist!"

@duckdb-draftbot duckdb-draftbot marked this pull request as draft February 18, 2025 13:19
@jeewonhh jeewonhh marked this pull request as ready for review February 18, 2025 13:19
@duckdb-draftbot duckdb-draftbot marked this pull request as draft February 19, 2025 08:42
@jeewonhh jeewonhh marked this pull request as ready for review February 19, 2025 08:42
@jeewonhh jeewonhh marked this pull request as draft February 19, 2025 09:13
@jeewonhh jeewonhh marked this pull request as ready for review February 19, 2025 10:19
@Mytherin Mytherin merged commit c79f529 into duckdb:v1.2-histrionicus Feb 21, 2025
50 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

krlmlr added a commit to duckdb/duckdb-r that referenced this pull request Mar 7, 2025
Allow querying attached catalog from detached catalog (duckdb/duckdb#16289)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants