Re: Order by in a sub query when aggregating the main query

2022-09-27 Thread Federico
I've changed the code to use order by in the aggregate and it seems there are no noticeable changes in the query performance. Thanks for the help. Best, Federico Caselli On Sun, 25 Sept 2022 at 00:30, Federico wrote: > > Understood, thanks for the explanation. > I'll work on updating the queries

Re: Order by in a sub query when aggregating the main query

2022-09-24 Thread Federico
Understood, thanks for the explanation. I'll work on updating the queries used by sqlalchemy to do array_agg(x order by x) instead of the order by in the subquery. > I think that right now that'd > incur additional sorting overhead, which is annoying. But work is > ongoing to recognize when the i

Re: Order by in a sub query when aggregating the main query

2022-09-24 Thread Tom Lane
Federico writes: > A basic example of the type of query in question is the following (see > below for the actual query): > select w, array_agg(x) > from ( > select v, v / 10 as w > from pg_catalog.generate_series(25, 0, -1) as t(v) > order by v > ) as t(x) > group by w > This

Order by in a sub query when aggregating the main query

2022-09-24 Thread Federico
Hi all, I have a question related to the order by clause used in a subquery of a main query that uses one or more aggregation functions with a group by. A basic example of the type of query in question is the following (see below for the actual query): select w, array_agg(x) from ( select