hasura / hasura/graphql-engine

Aggregate in where clause is not supported for numeric columns

Open
#9,462 2 comments 0 reactions 0 assignees View on GitHub
k/bug t/native-dbs
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: 2.19.0

### Environment

OSS

### What is the current behaviour?

Filtering based on aggregations (originally requested in https://github.com/hasura/graphql-engine/issues/1498), which can be found in the docs [here](https://hasura.io/docs/latest/queries/postgres/query-filters/#filter-based-on-aggregations-of-nested-array-fields), works fine for all types except the numeric type.

Screenshot 2023-02-23 at 11 23 20

### What is the expected behaviour?

As it is supported by PostgreSQL as described [here](https://www.postgresql.org/docs/14/functions-aggregate.html), it should also be exposed by Hasura.

### How to reproduce the issue?

1. Add a numeric(12, 4) column named `my_column` to a table called `table`
2. Try to add an aggregate from another table `parent` that has an array relationship to `table`
3. `avg` is not exposed at all if there are only `numeric` columns or `my_column` is not available in `arguments`, so the below is not possible.
```graphql
{
parent(where: {tables_aggregate: {avg: {arguments: my_column, predicate: {_gt: "0"}}}}) {
id
}
}

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the numeric(12, 4) case with the GraphQL aggregate query shown in the issue, then compare it with the aggregation behavior described in the Hasura and PostgreSQL documentation links. Done means avg is exposed for numeric columns and the query can filter on my_column as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, postgresql
Domain
api, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.