-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort By Count Aggregation #2730
Comments
I would love to just be able to get the count
so that way I can know how many directors are there for the film (I didn't found any work around that will support filters ) |
Ah, actually the above already works like: GET /tbl?select=title,directors(count) Caveats:
|
To elaborate on the above: curl 'localhost:3000/clients?select=id,name,projects(count)'
[
{"id":1,"name":"Microsoft","projects":[{"count":3}]},
{"id":2,"name":"Apple","projects":[{"count":2}]}
] Addressing the OP issue. Using the new related order feature: #2511 I tried to do: curl 'localhost:3000/clients?select=id,name,projects(count)&order=projects(count)'
{"code":"PGRST118","details":"'clients' and 'projects' do not form a many-to-one or one-to-one relationship","hint":null,"message":"A related order on 'projects' is not possible"} It's close.. the underlying query should work. However, we need a way to mark the |
@steve-chavez - that would be awesome if ya'll can figure that out! Simple, short, would solve a lot of J |
Hi, I'm new to this community and to PostgREST, so apologies if this isn't the appropriate way to express this: I'd love to use an order for a My use case is kind of like this:
|
Would be awesome if this were possible! I don't suppose there's a current workaround that won't require me having to create a view or a computed column? Alright, I figured out one workaround for if you have a
So I guess the above request would become something like this. curl 'localhost:3000/projects?select=count(),...clients!inner(id,name)' @steve-chavez can you confirm this? Seems like a good workaround for me, but won't work for |
Ah, that's an interesting workaround. You can get the
I think It could work for # "users_projects" is junction table between "projects" and "users"
curl 'localhost:3000/users_projects?select=count(),...projects!inner(name)' [{"count":1,"name":"OSX"},
{"count":2,"name":"IOS"},
{"count":2,"name":"Windows 7"},
{"count":1,"name":"Windows 10"}] |
Yeah, you're right. I just ran into that and realised it too, sadly PostgREST doesn't support other types of joins yet (I think
True, if you create an intermediate view a lot of our problems would be solved, but I actually personally prefer not to create new views unless I have a good reason to. I prefer to just write a complex query and not add anything new to the database. |
While there is a need for
GROUP BY
in PostgREST, this feature would take care a lot of the use cases:#158
#167
#915
#158
It would be nice to be able to say:
I'm thinking you should be able to sort by the top level table OR by the foreign key / child table.
It should work similar to GraphQL like Hasura:
https://hasura.io/docs/latest/queries/postgres/sorting/#for-array-relationships
That way, we don't need to think about Group By, but think about the actual data and how you want to sort it.
So, from a regular data perspective, let's say we want to display the Top Votes of a Post:
So we want something like this:
OR
There are different ways to accomplish this, but basically you wouldn't need to think about
GROUP BY
, and it would write this SQL code automatically (maybe with Group By).J
The text was updated successfully, but these errors were encountered: