Skip to content

Fix(duckdb): Generate correct DETACH syntax if IF EXISTS is set#5235

Merged
tobymao merged 1 commit intomainfrom
erin/duckdb-detach
Jun 17, 2025
Merged

Fix(duckdb): Generate correct DETACH syntax if IF EXISTS is set#5235
tobymao merged 1 commit intomainfrom
erin/duckdb-detach

Conversation

@erindru
Copy link
Collaborator

@erindru erindru commented Jun 17, 2025

Prior to this PR:

>>> parse_one("DETACH DATABASE IF EXISTS foo", dialect="duckdb").sql(dialect="duckdb")
'DETACH IF EXISTS foo'

This is invalid syntax, at least as of DuckDB 1.3.0. Unlike ATTACH, when IF EXISTS is used for DETACH, it has to be DETACH DATABASE or the following error gets thrown:

Parser Error: syntax error at or near "exists" (Line Number: 1)

This is in line with the DuckDB documentation

Note that DETACH foo works as expected, the error is only thrown if IF EXISTS is added

@tobymao tobymao merged commit 781539d into main Jun 17, 2025
7 checks passed
@tobymao tobymao deleted the erin/duckdb-detach branch June 17, 2025 02:39
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