![]() ![]() I want to get the entity with the lowest id in each group ( Need help on this).I want to get the number of entities in each group ( Done).So I want to select the first entity (The entity with the minimal id) and the number of entities grouped by some_value or the first i_want_this and the count grouped by some_value So I could do this: groups = db.session.query(db.func.min(Entity.id), db.unt()).group_by(Entity.some_value)īut I don't want these additional get queries. I'm actually only interested in the count and the first i_want_this value. My second question is obvious: How would I do it with PostgreSQL? So my first question is: Why does SQLite allow this and how does it do it (what hidden aggregation is used)? LINE 1: SELECT entity.id AS entity_id, entity.i_want_this AS entity_not. Now in PostgrSQL we get this error: : (psycopg2.ProgrammingError) column "entity.id" must appear in the GROUP BY clause or be used in an aggregate function I can't say for sure which of the entities was returned. In retrospect I see that it does not make sense but SQLite did make sense of it. I want to group all Entitys by some_value which i did like this (simplified): db.session.query(Entity, db.unt()).group_by(Entity.some_value) Id = db.Column(db.Integer, primary_key=True) We have this SQLAlchemy model (simplified) class Entity(db.Model): Recently we wanted to migrate to PostgreSQL. For the web app we are building we used SQLite for testing purposes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |