// DuckDB error reference

Catalog Error: The schema does not exist in this database

A statement referenced a schema that is not in the connected database, so its objects cannot be reached.

Exception
Catalog Error
類別
Catalog Error
錯誤訊息
Catalog Error: Schema with name no_such_schema does not exist!

它的意義

DuckDB resolves qualified names as database.schema.object, and this error means the schema part is not one the connection can see. An unqualified name resolves against the search path, which points at the main schema of the connected database by default.

Attached databases multiply the places a name can live: every attachment has its own main schema, and the same schema name can exist in two databases at once. The wording depends on the statement: CREATE TABLE analytics.orders 和 DROP SCHEMA analytics name the schema directly, while a query that reads through a missing schema reports the table instead, as Table with name "analytics.orders" does not exist because schema "analytics" does not exist.. In practice the name is misspelled, the object was created on another connection or another database, or a qualification points at the wrong attached alias.

常見原因

  • A typo or wrong case in a qualified name such as analytics.orders.
  • The schema lives in an attached database, and the query used the wrong alias, or the ATTACH never ran on this connection.
  • The table was created in main while the query looks for it in another schema, or the search_path was changed.
  • A migration that creates the schema never ran on this connection.

Find the cause

-- Every schema in every attached database:
SELECT database_name, schema_name FROM duckdb_schemas() ORDER BY 1, 2;
-- Which databases are attached, and from which file:
SELECT database_name, path FROM duckdb_databases();

如何修正

  1. List the schemas the connection can actually see:

    SELECT database_name, schema_name
    FROM duckdb_schemas()
    ORDER BY 1, 2;
  2. Create the schema if it should exist, and qualify names while you populate it:

    CREATE SCHEMA analytics;
    CREATE TABLE analytics.orders (id INTEGER, total DECIMAL(10,2));
  3. Qualify with the attached database when the table lives there:

    SELECT * FROM warehouse.main.orders LIMIT 5;
  4. Point unqualified names at the right schema:

    SET search_path = 'analytics,main';

Other ways to handle it

Qualify every name in scripts that touch more than one database; unqualified names depend on the search path, which is invisible in the statement itself. Keep one migration per schema so creation and population cannot drift apart.

安全地重現問題

CREATE TABLE no_such_schema.t(a INTEGER);   -- Catalog Error: Schema with name no_such_schema does not exist!

問題

Where do temporary tables and views live?

In the temp database, under temp.main. Qualify them as temp.main.name when another schema is first in the search path.

Why is my table invisible after ATTACHing a second database?

Each database has its own schemas. An unqualified name resolves inside the connected database, not the attachment, so qualify it as attached.main.table or change the search path.

相關錯誤

程式碼和訊息文字來自 DuckDB documentation。瀏覽完整的 DuckDB error list 或 搜尋每個資料庫錯誤.

// 錯誤更少,修復更快

Work on DuckDB in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for DuckDB and the other databases you use.

本頁文字與資料: CC BY 4.0,請註明出處 SQLly (sqlly.app)。 程式碼與 SQL 片段: MIT. 授權詳情 引用的錯誤訊息文字歸其資料庫廠商所有。