I want to query services between two dates and sum their prices. When I try to use func.sum
with Services.query
, I get TypeError: BaseQuery object is not callable
. How do I query using a function with Flask-SQLAlchemy?
Services.query(func.sum(Services.price)).filter(Services.dateAdd.between(start, end))
You delete everything in the database using the db. drop_all() function to add the tags and post_tag tables safely and to avoid any of the common issues related to adding new tables to a database. Then you create all the tables anew using the db. create_all() function.
SQLAlchemy Core The already created students table is referred which contains 4 columns, namely, first_name, last_name, course, score. But we will be only selecting a specific column. In the example, we have referred to the first_name and last_name columns. Other columns can also be provided in the entities list.
Flask-SQLAlchemy is the Flask extension that adds support for SQLAlchemy to your Flask application. What is ORM (Object Relation Mapping)? Most programming language platforms are object oriented.
SQLAlchemy is an SQL toolkit that provides efficient and high-performing database access for relational databases. It provides ways to interact with several database engines such as SQLite, MySQL, and PostgreSQL.
Model.query
is a shortcut to db.session.query(Model)
, it's not callable. If you're not querying a model, continue to use db.session.query(...)
as you would with regular SQLAlchemy.
db.session.query(db.func.sum(Services.price)).filter( Services.dateAdd.between(start, end) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With