Skip to content
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

db["my_table"].drop(ignore=True) parameter, plus sqlite-utils drop-table --ignore and drop-view --ignore #237

Closed
mhalle opened this issue Feb 24, 2021 · 3 comments
Labels

Comments

@mhalle
Copy link

mhalle commented Feb 24, 2021

When I'm generating a derived table in python, I often drop the table and create it from scratch. However, the first time I generate the table, it doesn't exist, so the drop raises an exception. That means more boilerplate.

I was going to submit a pull request that adds an "if_exists" option to the drop method of tables and views.

However, for a utility like sqlite_utils, perhaps the "IF EXISTS" SQL semantics is what you want most of the time, and thus should be the default.

What do you think?

@simonw
Copy link
Owner

simonw commented Feb 25, 2021

Other methods (db.create_view() for example) have ignore=True to mean "don't throw an error if this causes a problem", so I'm good with adding that to .drop_view().

I don't like using it as the default partly because that would be a very minor breaking API change, but mainly because I don't want to hide mistakes people make - e.g. if you mistype the name of the table you are trying to drop.

@simonw
Copy link
Owner

simonw commented Feb 25, 2021

So:

    db["my_table"].drop(ignore=True)

@simonw simonw changed the title add drop-{table,view} "if exists" option, or make it default behavior db["my_table"].drop(ignore=True) parameter Feb 25, 2021
@simonw
Copy link
Owner

simonw commented Feb 25, 2021

sqlite-utils create-view currently has a --ignore option, so adding that to sqlite-utils drop-view and sqlite-utils drop-table makes sense as well.

@simonw simonw changed the title db["my_table"].drop(ignore=True) parameter db["my_table"].drop(ignore=True) parameter, plus sqlite-utils drop-table --ignore and drop-view --ignore Feb 25, 2021
@simonw simonw closed this as completed in bba6e24 Feb 25, 2021
simonw added a commit that referenced this issue Feb 25, 2021
simonw added a commit that referenced this issue May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants