-
Notifications
You must be signed in to change notification settings - Fork 646
feat(duckdb): improve attach(), detach(), and attach_sqlite() #11198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
9cc5741
to
80bf360
Compare
ibis/backends/duckdb/__init__.py
Outdated
The name to attach the database as. | ||
If `None`, use the default behavior of DuckDB | ||
(as of duckdb==1.2.0 this is the basename of the path). | ||
skip_if_exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very explicitly choosing this language of "skip_if_exists" instead of "exist_ok" because I don't want users to think this has "CREATE OR REPLACE" semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also do on_exists: Literal["ignore", "replace", "error"]="error" and then this would be more inline with how I want to change the create_table() and create_view() APIs to be in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with on_exists: Literal["ignore", "error"] = "error"
so that it would be consistent with on_missing: Literal["ignore", "error"]="error"
of detach()
80bf360
to
a1345c2
Compare
ibis/backends/duckdb/__init__.py
Outdated
cur.execute( | ||
f"CALL sqlite_attach('{path}', overwrite={overwrite})" | ||
).fetchall() | ||
self._safe_raw_sql(f"SET GLOBAL sqlite_all_varchar={all_varchar}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't THINK it's needed to use this as a context manager here (or in fact most places within the duckdb backend), but double check me.
a1345c2
to
100149e
Compare
the sqlite_attach() approach is deprecated per https://duckdb.org/docs/stable/extensions/sqlite.html, and the newer syntax opens up read only flag, specifiying a name for the attachment, and not overwriting tables that already exist.
This is breaking in that some params are now keyword only.
100149e
to
0c1d64d
Compare
The sqlite_attach() approach is deprecated per
https://duckdb.org/docs/stable/extensions/sqlite.html,
and the newer syntax opens up read only flag, specifiying a name for the attachment, and not overwriting tables that already exist.
This is breaking:
on_exists: Literal["ignore", "error"] = "error"
This is prep for work I want to do to add attach_postgres(), but I want to get the API up to date so that the two APIs can be consistent. In fact, after this PR I don't even need another attach_postgres() method, since now the plain attach() is flexible enough to support this.