Sometimes, we want to check if row exists in table with Python Flask-SQLAlchemy.
In this article, we’ll look at how to check if row exists in table with Python Flask-SQLAlchemy.
How to check if row exists in table with Python Flask-SQLAlchemy?
To check if row exists in table with Python Flask-SQLAlchemy, we can use the exists
method.
For instance, we write
exists = db.session.query(
db.session.query(User).filter_by(name="John Smith").exists()
).scalar()
to call filter_by
to select the entry in the user
table with name
column value 'John Smith'
.
Then we call exists
to see if any result is returned.
Conclusion
To check if row exists in table with Python Flask-SQLAlchemy, we can use the exists
method.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- Custom Authentication Login And Registration Using Laravel 8
- How to Convert MySQL Data to JSON using PHP
- Google Login or Sign In with Angular Application
- How to change date format in PHP?
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example
Total Views: 3,292