Skip to content

Does Hasura Engine support groupBy in GraphQL query? #2965

Closed

Description

@yyuankm1976

I need to run the SQL statement by using Group By. Does Hasura Engine support GroupBy in GraphQL query and map to SQL GroupBy? Thanks!

Activity

  1. marionschleifer commented on Oct 1, 2019

    @marionschleifer
    Contributor

    Hi @yyuankm1976 🙂 it's not possible to use GROUP BY inside queries. You have to create a view for that: https://docs.hasura.io/1.0/graphql/manual/queries/derived-data.html#step-1-create-a-view.

  2. yyuankm1976 commented on Oct 2, 2019

    @yyuankm1976
    Author

    Thanks marionschleifer, sure we can create a view for this purpose. but as I know, groupby can also be integrated into graphql. One example is as below. Do we plan to add this support in future?

    query {
    postsConnection(where: {
    someField: true,
    }) {
    groupBy {
    authorName {
    key
    connection {
    aggregate {
    count
    avg {
    nb_likes
    }
    }
    }
    }
    }
    }
    }

  3. 0x777 commented on Oct 2, 2019

    @0x777
    Member

    @yyuankm1976 The reason why we didn't implement this is because the above approach only works when you want to group by a single column.

  4. marionschleifer commented on Oct 4, 2019

    @marionschleifer
    Contributor

    @yyuankm1976 I'm closing this issue. Feel free to re-open if you have any additional questions 🙂

  5. nolandg commented on Apr 28, 2020

    @nolandg

    Example using a postgres function is here: #3478 (comment)

  6. agam-singsys commented on May 28, 2021

    @agam-singsys

    Find duplicate entries in a column in PostgreSQL graphql hasura?

  7. Mingyang-Li commented on Mar 19, 2022

    @Mingyang-Li

    @yyuankm1976 The reason why we didn't implement this is because the above approach only works when you want to group by a single column.

    Not everyone needs to group data by 2 or 3 columns - I'm trying to build some simple data-visualisation on the UI and it would be a huge blessing if we're able to just group data by even ONE column (with where filters etc)

  8. tirumaraiselvan commented on Apr 7, 2022

    @tirumaraiselvan
    Contributor

    Discussion on implementing various workaround are here: #3478

    An easy approach is here: #3478 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions