How to aggregate for multiple levels of embedded resources? #3917
Unanswered
stefan-girlich
asked this question in
Q&A
Replies: 1 comment
-
Since this query has nested aggregates/group by mixed in between "has-many" and "has-one" relationships, it is too complex for a PostgREST query to resolve it. I'd go with a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using Supabase and PostgREST to aggregate sums by a nested property.
Resource hierarchy
locations
output_fractions
of which eachweight
batches
) with aproject_type
shipments
with another columnweight
In short:
locations
haveoutput_fractions
which have one ofbatches
and manyshipments
I want to query data for
locations
and aggregate nested weight sums:Case 1: Aggregate over 1 level
I want to aggregate
weight
foroutput_fractions
bybatches.project_type
which works fine:Case 2: Aggregating over more levels
I want to aggregate
weight
forshipments
bybatches.project_type
.I wonder if I could modify this code to achieve the desired results:
Expected:
fractions2
contains one item perproject_type
Actual:
fractions2
contains one item peroutput_fractions
itemIdeally, I could reference
shipments
directly as an embedded resource, but this is not possible since it is does not relate directly tolocations
, but only indirectly viaoutput_fractions
.Is there an idiomatic way to achieve this? If not, how would tackle this problem?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions