Comments (6)
As a comment on a long closed issue, this will get lost. I don't plan to address your concerns any time soon (though you could, or you could sponsor us to), but if you'd like them to be tracked you should open a new issue.
from pg-aggregates.
{
allAccounts {
aggregates {
sum {
price }}}}
^ This is quite clear; something like: select sum(accounts.price) from accounts
{
allAccounts {
aggregates {
sum {
usersByAccountId {
price } } } } }
^ This is less clear, is this a single value across all accounts:
select sum(users.price)
from accounts
inner join users
on (accounts.id = users.account_id)
?
Or is it grouped by the account ID, so for each account id you get a value:
select accounts.id, sum(users.price)
from accounts
inner join users
on (accounts.id = users.account_id)
group by accounts.id
?
from pg-aggregates.
[semi-automated message] Hi, there has been no activity in this issue for a while so I'm closing it to keep the issues/pull requests manageable. If this is still an issue, please re-open with additional details.
from pg-aggregates.
Hi benjie! Thanks for another great addition to the postgraphile ecosystem!
The second example above is the critical use case; the desire is to group and aggregate from two different tables. I'd go so far as to say this is a universal desire since it is common in database design to store values in a separate table from metadata (so that the metadata need not be repeated for every value).
I'm sure there are several possibilities for the query shape, with various tradeoffs. One possibility is the groupBy
argument accepting something akin to what's used in postgraphile-plugin-connection-filter
in place of the enum that's used currently.
I'd be curious to hear whether you think this might ever be in scope. I've been poking around the source to see if it might be possible.
from pg-aggregates.
I think you can do that by adding a custom grouping which is a subquery to fetch the related data.
from pg-aggregates.
I'm trying to do exactly this, but currently there are some obstacles:
isSuitableType
is a check based only on a type, while it should be type + column, so you can e.g. add grouping only for id:Currentlyselect sum(users.price) from users group by (select accounts.id from accounts where accounts.id = users.account_id)
isSuitableType
makes this grouping available for all number-like columns (if you enable it foraccount_id
), which is meaningless.pgAggregateGroupBySpecs
enables aggregation only for single column, i.e.sqlFrag
=__local_123__.<column>
. If in prev. example you want to join by more than one column, you can't (I know a workaround with pg settings, but it is super ugly and verbose)- In general, "group by arbitrary expression" would be great to have. Currently it's doable, but there are a lot of ugliness
from pg-aggregates.
Related Issues (16)
- graphile-build:warn TypeError: getComputedColumnDetails is not a function HOT 1
- Aggregates provide null values HOT 5
- aggregates throwing "null" all the time HOT 1
- Not able to use pg-aggregates HOT 19
- TIMESTAMP_TRUNCATED_TO_MONTH & TIMESTAMP_TRUNCATED_TO_YEAR HOT 23
- Cannot get the given example to work HOT 3
- Filtering by totalCount HOT 3
- Getting - Error: Option 'appendPlugins' should be an array of functions, found 'object' at index 0 HOT 3
- Looks like aggregate order bys get generated even when table is omitted HOT 1
- GroupBy computed columns not generated ? HOT 4
- Aggregates ignore ordering HOT 6
- Removing limitation of stringified `keys` HOT 3
- Order by totalCount with per-query custom filtering applied HOT 2
- Aggregates can return unsafe integers HOT 8
- getComputedColumnDetails is not a function HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pg-aggregates.