Hello,I am currently using the following sqlalchemy code,_query = super().get_query(model, info, sort, **args)query = _query.group_by(func.date_format(DataModel.timestamp, "%Y-%m-%d %H"))return queryI am trying to aggregate the the max value of a field from DataModel.value utilizing the group by clause.In simple sql, you would do the following.SELECT max(data.value) AS data_valuefrom dataGROUP BY date_format(data.timestamp, "%Y-%m-%d %H")What would the proper way to express this? The various methods I have tried somehow overwrite the original query and do not map to our attributes.--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/a73c1830-8c64-437a-8ea7-a171767e2223n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAOV%2B3C2PU2ndh9Uf-ZGtDj_ao-3rhQATE9MjYAppSSnwKT6%2Beg%40mail.gmail.com.
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/j5fIV6NmAns/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAOV%2B3C2PU2ndh9Uf-ZGtDj_ao-3rhQATE9MjYAppSSnwKT6%2Beg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAOV%2B3C2PU2ndh9Uf-ZGtDj_ao-3rhQATE9MjYAppSSnwKT6%2Beg%40mail.gmail.com.
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following.Received incompatible instance \"(<server.db.models.Data object at 0x7f2c6cfd6670>, '2021-04-10 18', Decimal('7294.00000'))\".",
Here I am able to get the max for that row group, but am unable to pass it into the DataModel object
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/3eeda16b-9c36-4ca5-91b5-cba325343fban%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/ee62e370-b0c1-4656-95e2-4ecbcf4791e7%40app.fastmail.com.