Skip to content

Commit c4d525a

Browse files
authored
Merge pull request #26 from VACLab/detach-before-attach-duckdb
detaching duckdb before attaching it
2 parents 4bda2ae + 32c204d commit c4d525a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

biasanalyzer/database.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def _initialize(self, db_url, omop_db_url=None):
5656
ATTACH '{self.omop_cdm_db_url}' as {self.omop_alias} (TYPE postgres)
5757
""")
5858
elif omop_db_url.endswith(".duckdb"):
59+
try:
60+
self.conn.execute(f"DETACH DATABASE {self.omop_alias}")
61+
except (duckdb.BinderException, duckdb.CatalogException):
62+
# ignore if not attached yet
63+
pass
5964
self.conn.execute(f"""
6065
ATTACH '{self.omop_cdm_db_url}' as {self.omop_alias}
6166
""")

0 commit comments

Comments
 (0)