question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clarification on using aggregates with limit argument

See original GitHub issue
subscription{
  suppliers_aggregate(limit:10){
    nodes{
      name
    }
    aggregate{
     count
    }
  }
} 

it still limit the aggregate query

SELECT
  json_build_object(
    'nodes',
    coalesce(json_agg("nodes"), '[]'),
    'aggregate',
    json_build_object('count', COUNT(*))
  ) AS "root"
FROM
  (
    SELECT
      1 AS "root__one",
      row_to_json(
        (
          SELECT
            "_1_e"
          FROM
            (
              SELECT
                "_0_root.base"."name" AS "name"
            ) AS "_1_e"
        )
      ) AS "nodes"
    FROM
      (
        SELECT
          *
        FROM
          "public"."suppliers"
        WHERE
          ('true')
      ) AS "_0_root.base"
    LIMIT
      10
  ) AS "_2_root"

heres the generated query. it doesnt define the only the node get to be limit

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
revskill10commented, May 8, 2019

@shahidhk I think the expected behaviour should be:

  • Limit is used to fetch real data rows.
  • Aggregate count is to calculate Total rows number of the table, independent of limit

So,

subscription {
  suppliers_aggregate(limit:10) {
    aggregate { count }    
  }
} 

should fetch 10 rows of data, but aggregate.count returns Total number of rows of that table based on permission.

1reaction
shahidhkcommented, May 8, 2019

@zesterquinn Since you’re adding the limit argument, this is the expected behaviour. If your intention is to get 10 items and also get the total count, you have to use two subscriptions:

# get 10 items
subscription {
  suppliers(limit:10) {
    name
  }
} 
# get the total count
subscription {
  suppliers_aggregate {
    aggregate{
     count
    }
  }
} 
Read more comments on GitHub >

github_iconTop Results From Across the Web

postgresql - How to apply ORDER BY and LIMIT in ...
I am applying order by p.name desc in two places ... Is there a way to avoid that? Yes. Aggregate with an ARRAY...
Read more >
Understanding symmetric aggregates | Looker - Google Cloud
Symmetric aggregates prevent analysts — and anyone else who uses Looker — from accidentally miscalculating aggregates such as sums, averages, and counts.
Read more >
Aggregate Functions in Tableau
An aggregate calculation that combines the values in the argument field. Null values are ignored. Note: The COLLECT function can only be used...
Read more >
15: 38.12. User-Defined Aggregates - PostgreSQL
To define a new aggregate function, one selects a data type for the state value, an initial value for the state, and a...
Read more >
Learn SQL: Aggregate Functions - SQLShack
While all aggregate functions could be used without the GROUP BY clause, the whole point is to use the GROUP BY clause. That...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found