I have a created_at column which stores the datetime.datetime object.
And I have a column that stores an integer for each day called as collected.
What I want is to group this table by day of week (Mon, Tue, Wed.. etc) and sum up the collected value for each day.
The output should be like this ->
[{'collected': 11, 'day': 'Sunday'}, {'collected': 9, 'day': 'Monday'}, {'collected': 1, 'day': 'Tuesday'}, {'collected': 10, 'day': 'Wednesday'}, {'collected': 7, 'day': 'Saturday'}]
I tried using session.query(func.dayofweek( SQL_table.datetime_column).all()
and that throws error function dayofweek(timestamp without time zone) does not exist.
Please help me how can I make a query like this in SQLAlchemy. Thanks...
Measurement is a made up ORM class with columns
created_atandcollected.This is using to_char.
This uses
"FM"prefix of"Day"to suppress padding the day names to be the same length: