Answer by Dragas for Managing the order of aggregation in postgres
In the Aggregate functions page (chapter 9, section 20 in postgresql 12 documentation "Aggregate Functions" (1)) there's a paragraph specifically addressing thisThe aggregate functions array_agg,...
View ArticleManaging the order of aggregation in postgres
Suppose I have the following merging function that merges two jsonb values overwriting duplicate keys with the values from the secondcreate or replace function jsonb_concat(a jsonb, b jsonb) returns...
View ArticleAnswer by Erwin Brandstetter for Managing the order of aggregation in Postgres
The manual goes on to say:... Alternatively, supplying the input values from a sorted subquerywill usually work. For example:SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;In fact,...
View Article