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!
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.
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
}
}
}
}
}
}
}
@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.
@yyuankm1976 I'm closing this issue. Feel free to re-open if you have any additional questions 馃檪
Example using a postgres function is here: https://github.com/hasura/graphql-engine/issues/3478#issuecomment-620313590