FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

✨ Allow deleting all rows from a table by jnewbery · Pull Request #1349 · fastapi/sqlmodel · GitHub

Repository navigation

✨ Allow deleting all rows from a table - #1349

Closed
jnewbery wants to merge 1 commit into
fastapi:mainfrom
jnewbery:delete
Closed

jnewbery wants to merge 1 commit into
fastapi:mainfrom
jnewbery:delete

Conversation

Copy link
Copy Markdown

The sqlmodel docs explain how to delete a single row from a table.

It's also useful to be able to delete multiple rows (or even all rows) at the same time. See https://stackoverflow.com/questions/76648956/how-to-delete-all-rows-matching-a-condition-using-sqlmodel for example.

session.exec(delete(Table)) works fine, but triggers a type warning:

Pyright: Error: No overloads for "exec" match the provided arguments [reportCallIssue]
Pyright: Error: Argument of type "Delete" cannot be assigned to parameter "statement" of type "SelectOfScalar[_TSelectParam@exec]" in function "exec"
  "Delete" is not assignable to "SelectOfScalar[_TSelectParam@exec]" [reportArgumentType]

Adding an additional overload to Session.exec() allows this syntax to be used.

svlandeg changed the title Allow session.exec(delete(Table)) to delete all rows from a table ✨ Allow deleting all rows from a table Apr 28, 2025
svlandeg added the feature New feature or request label Apr 28, 2025
svlandeg marked this pull request as draft April 28, 2025 09:12
jnewbery marked this pull request as ready for review May 6, 2025 09:54

jnewbery commented May 6, 2025

Copy link
Copy Markdown
Author

Thanks for looking at this @svlandeg . I've fixed the failing pydantic error and marked this as ready for review.

rhwlo commented May 9, 2025

Copy link
Copy Markdown

This would be great to have – I just ran into this error!

I think #1342 solves the same problem using UpdateBase, which covers update operations as well as delete ones.

Copy link
Copy Markdown
Member

@jnewbery, thanks for your interest and efforts!

There is another PR #1342 that solves this problem in a more general way (also solves it for insert, update and text statements).
Let's close this PR and focus on #1342.

Thanks again!

YuriiMotov closed this Aug 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL