Visitar URL original
GROUP BY, HAVING and aggregation functions support · Issue #266 · ormar-orm/ormar · GitHub
Skip to content

GROUP BY, HAVING and aggregation functions support #266

Open

Description

@MIREX

Describe the solution you'd like
GROUP BY, HAVING and aggregation functions (such as count, avg, max and so on) support in queries. It could be very useful for making queries like this:

# Select all users with votes and count votes for each user
select user.id, count(vote.id) as votes_count
from user
         left join vote on user.id = vote.user
group by user.id
having votes_count > 0;

Before ormar I used to use peewee and I really like a way how it implemented there.

I think it could be easily implemented for queries returning raw values. But it could be a problem with dynamic assigning of Pydantic model fields.

Activity

  1. collerek commented on Jul 7, 2021

    @collerek
    Collaborator

    There are related queries for functions and subqueries in #242 and #227.
    That seems like a nice feature, but as you wrote that might be challenging to properly parse to pydantic fields.

  2. JAKE4545 commented on Nov 12, 2021

    @JAKE4545

    I met this question now, but I have no idea to solve it.

  3. lewoudar commented on Jul 26, 2022

    @lewoudar

    Hi folks, sorry to bring this up, but do we have any visibility on its development?

  4. Phizilion commented on Mar 5, 2024

    @Phizilion

    Need it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions