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.

feat: Support COUNT of relevant rows

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

I’d like to perform COUNT(*) on relevant rows.

Describe the solution you’d like

A PostgrestTransformBuilder method. PostgREST supports this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:33 (30 by maintainers)

github_iconTop GitHub Comments

8reactions
steve-chavezcommented, Jan 7, 2021

Correct me if I am talking gibberish, but with this method, would you be able to query count value of joined table?

@dshukertjr No, this interface is just for counting the root table.

I guess I would have to send two request to achieve this huh?

Not necessarily, you can always create a VIEW or FUNCTION that has the aggregate to do it in one request.

There’s also another option, that is currently undocumented in postgrest since it’s not complete. Basically:

const { data, error } = await postgrest
    .from('users')
    .select(`
        name,
        tweets (
          count
        )
  `)

That will get the tweets count as you’d expect. However if you add more attributes(like tweets(content,date,count)) it will fail.

Calling other aggregate functions with group by is a future enhancement.

5reactions
dshukertjrcommented, Jan 8, 2021

Thanks @soedirgo and @steve-chavez. I will add this feature and create a pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Gentle Introduction on Market Basket Analysis
Market Basket Analysis is one of the key techniques used by large retailers to uncover associations between items.
Read more >
How to return all information of a row with MAX or MIN value in ...
Suppose we have a table “score” as below, and we need all information on a row with the maximum score of each team....
Read more >
Extracting, transforming and selecting features - Apache Spark
Extracting, transforming and selecting features. This section covers algorithms for working with features, roughly divided into these groups:.
Read more >
column-count | CSS-Tricks
Given the number of columns, the browser will evenly distribute the content in exactly that number of columns. This property can also be...
Read more >
Calculate Field Python examples—ArcGIS Pro | Documentation
Python also supports a number of numeric and mathematical functions, ... Instead of performing calculations one feature or row at a time, ...
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