Catalog Error: The table or object already exists
A CREATE statement tried to add a table, view, schema or macro whose name is already taken in the same schema.
- Exception
Catalog Error- 카테고리
- Catalog Error
의미
DuckDB refuses to overwrite catalog objects, so CREATE TABLE 없이 IF NOT EXISTS fails when the name is taken. The message quotes the name and names the kind of object when it is not a table, for example Macro Function with name "m" already exists!.
In scripts that run more than once, this error is the normal second run. The fix is usually to make the statement idempotent rather than to drop data.
일반적인 원인
- A CREATE TABLE, CREATE VIEW, CREATE SCHEMA or CREATE MACRO without IF NOT EXISTS or OR REPLACE, run a second time.
- A migration that already ran, applied again by a rerun or a second deployment target.
- Two processes creating the same object concurrently.
- The name collides with a different kind of object in the same schema, since DuckDB shares one namespace per schema for tables and views.
Find the cause
-- See the object that holds the name, including its type: SELECT table_schema, table_name, table_type FROM information_schema.tables WHERE table_name = 'metrics'; SELECT database_name, schema_name, table_name, temporary FROM duckdb_tables() WHERE table_name = 'metrics'; -- A temp object of the same name does not collide: it lives in database 'temp' and, for unqualified names, DuckDB resolves to the temp one first: SELECT * FROM duckdb_databases();
해결 방법
-
Make the statement idempotent so reruns are harmless:
CREATE TABLE IF NOT EXISTS metrics (id INTEGER, ts TIMESTAMP); CREATE OR REPLACE VIEW recent_metrics AS SELECT * FROM metrics WHERE ts > now() - INTERVAL 1 DAY;
-
Check what already owns the name before replacing it:
SELECT table_name, table_type FROM information_schema.tables WHERE table_name = 'metrics';
-
If the old object really must go, drop it explicitly rather than relying on CREATE to overwrite:
DROP TABLE IF EXISTS metrics;
Other ways to handle it
In migration tooling, prefer a migrations ledger over IF NOT EXISTS everywhere: record which scripts ran and skip them, so a name change cannot silently leave an old table behind.
안전하게 재현하세요
CREATE TABLE t(a INT); CREATE TABLE t(a INT); -- Catalog Error: Table with name "t" already exists!
질문
Does CREATE OR REPLACE work for tables?
Yes. CREATE OR REPLACE TABLE drops the existing table and its data, then creates the new one, so use it only when losing the data is intended. Use CREATE TABLE IF NOT EXISTS to keep existing data.
관련 오류
Catalog ErrorThe table does not exist in this databaseCatalog ErrorThe schema does not exist in this databaseSQLITE_ERRORSQLite: SQL logic error42P07PostgreSQL: 릴레이션이 이미 존재함
코드와 메시지 텍스트의 출처는 다음과 같습니다 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. 라이선스 세부 정보 인용된 오류 메시지 텍스트의 권리는 해당 데이터베이스 공급업체에 있습니다.