# aggregate functions

Published articles for aggregate functions.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Emulating SQL FILTER with Oracle JSON Aggregate Functions

DevFeed: [Emulating SQL FILTER with Oracle JSON Aggregate Functions](<https://devfeed.tech/articles/emulating-sql-filter-with-oracle-json-aggregate-functions-28937.md>)

Original publisher: [Read original article](<https://blog.jooq.org/emulating-sql-filter-with-oracle-json-aggregate-functions/>)

Author: lukaseder

Published: 2024-06-03T12:17:41Z

Content type: article

Language: en

Sources: [jOOQ](<https://devfeed.tech/sources/jooq.md>)

Topics: [Oracle Database](<https://devfeed.tech/topics/oracle-database.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [JSON](<https://devfeed.tech/topics/json.md>)

Tags: [aggregate-functions](<https://devfeed.tech/tags/aggregate-functions.md>), [filter](<https://devfeed.tech/tags/filter.md>), [filter-clause](<https://devfeed.tech/tags/filter-clause.md>), [jooq-3-20](<https://devfeed.tech/tags/jooq-3-20.md>), [json](<https://devfeed.tech/tags/json.md>), [json-aggregate-functions](<https://devfeed.tech/tags/json-aggregate-functions.md>), [json-arrayagg](<https://devfeed.tech/tags/json-arrayagg.md>), [json-objectagg](<https://devfeed.tech/tags/json-objectagg.md>), [oracle](<https://devfeed.tech/tags/oracle.md>), [sql](<https://devfeed.tech/tags/sql.md>), [sql-json](<https://devfeed.tech/tags/sql-json.md>)

### AI overview

This article explains how to emulate the SQL FILTER clause for JSON aggregate functions, particularly in Oracle. It presents a workaround that wraps legitimate data in arrays, filters out emulation-generated rows, and then unwraps the arrays. jOOQ 3.20 will implement these emulations.

### Source excerpt

A cool standard SQL:2003 feature is the aggregate FILTER clause, which is supported natively by at least these RDBMS: The following aggregate function computes the number of rows per group which satifsy the FILTER clause: This is useful for pivot style queries, where multiple aggregate values are computed in one go. For most basic types ... Continue reading Emulating SQL FILTER with Oracle JSON Aggregate Functions ->

## Getting Top 1 Values Per Group in Oracle

DevFeed: [Getting Top 1 Values Per Group in Oracle](<https://devfeed.tech/articles/getting-top-1-values-per-group-in-oracle-28939.md>)

Original publisher: [Read original article](<https://blog.jooq.org/getting-top-1-values-per-group-in-oracle/>)

Author: lukaseder

Published: 2024-03-01T09:55:41Z

Content type: tutorial

Language: en

Sources: [jOOQ](<https://devfeed.tech/sources/jooq.md>)

Topics: [ordering](<https://devfeed.tech/topics/ordering.md>), [JSON](<https://devfeed.tech/topics/json.md>)

Tags: [aggregate-functions](<https://devfeed.tech/tags/aggregate-functions.md>), [any-value](<https://devfeed.tech/tags/any-value.md>), [function](<https://devfeed.tech/tags/function.md>), [json](<https://devfeed.tech/tags/json.md>), [keep](<https://devfeed.tech/tags/keep.md>), [oracle](<https://devfeed.tech/tags/oracle.md>), [ordering](<https://devfeed.tech/tags/ordering.md>), [sql](<https://devfeed.tech/tags/sql.md>), [syntax](<https://devfeed.tech/tags/syntax.md>), [top-1-per-category](<https://devfeed.tech/tags/top-1-per-category.md>), [type-safety](<https://devfeed.tech/tags/type-safety.md>), [types](<https://devfeed.tech/tags/types.md>)

### AI overview

A tutorial on selecting the top one or top n values per group in Oracle. It discusses ordering and ties, repetition when projecting multiple columns, Oracle object types and ANY_VALUE in Oracle 21c, and JSON as an alternative workaround.

### Source excerpt

I've blogged about generic ways of getting top 1 or top n per category queries before on this blog. An Oracle specific version in that post used the arcane KEEP syntax: This is a bit difficult to read when you see it for the first time. Think of it as a complicated way to say ... Continue reading Getting Top 1 Values Per Group in Oracle ->

## The Performance Impact of SQL's FILTER Clause

DevFeed: [The Performance Impact of SQL's FILTER Clause](<https://devfeed.tech/articles/the-performance-impact-of-sql-s-filter-clause-28964.md>)

Original publisher: [Read original article](<https://blog.jooq.org/the-performance-impact-of-sqls-filter-clause/>)

Author: lukaseder

Published: 2023-02-06T07:51:38Z

Content type: article

Language: en

Sources: [jOOQ](<https://devfeed.tech/sources/jooq.md>)

Topics: [SQL](<https://devfeed.tech/topics/sql.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>)

Tags: [aggregate-functions](<https://devfeed.tech/tags/aggregate-functions.md>), [benchmark](<https://devfeed.tech/tags/benchmark.md>), [filter](<https://devfeed.tech/tags/filter.md>), [filter-clause](<https://devfeed.tech/tags/filter-clause.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This article benchmarks SQL FILTER syntax against equivalent CASE expressions in PostgreSQL. On the author's machine, the benchmark found an 8% performance penalty for FILTER in the tested queries, while noting that results can vary with hardware and data sets.

### Source excerpt

I've found an interesting question on Twitter, recently. Is there any performance impact of using FILTER in SQL (PostgreSQL, specifically), or is it just syntax sugar for a CASE expression in an aggregate function? As a quick reminder, FILTER is an awesome standard SQL extension to filter out values before aggregating them in SQL. This ... Continue reading The Performance Impact of SQL's FILTER Clause ->

## The Mode Ordered-Set Aggregate Function

DevFeed: [The Mode Ordered-Set Aggregate Function](<https://devfeed.tech/articles/the-mode-ordered-set-aggregate-function-34570.md>)

Original publisher: [Read original article](<https://tapoueh.org/blog/2017/11/the-mode-ordered-set-aggregate-function/>)

Author: Dimitri Fontaine PostgreSQL Major Contributor; Author

Published: 2017-11-13T17:15:51Z

Content type: tutorial

Language: en

Sources: [Dimitri Fontaine](<https://devfeed.tech/sources/dimitri-fontaine.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [aggregate](<https://devfeed.tech/tags/aggregate.md>), [aggregate-functions](<https://devfeed.tech/tags/aggregate-functions.md>), [analytics](<https://devfeed.tech/tags/analytics.md>), [cte](<https://devfeed.tech/tags/cte.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sort](<https://devfeed.tech/tags/sort.md>), [sql](<https://devfeed.tech/tags/sql.md>), [statistics](<https://devfeed.tech/tags/statistics.md>)

### AI overview

A tutorial explains how PostgreSQL's ordered-set aggregate function mode() WITHIN GROUP selects the most frequent genre for albums in the Chinook sample database, including ties and the use of a CTE.

### Source excerpt

In our article Exploring a Data Set in SQL we discovered a data set related to music: the Chinook sample database. Our discovery led us to find albums containing tracks of multiple genres, and for the analytics we were then pursuing, we wanted to clean the data set and assign a single genre per album. We did that in SQL of course, and didn't actually edit the data. Finding the most frequent input value in a group is a job for the mode() WITHIN GROUP (ORDER BY sort_expression) Ordered-Set Aggregate Function, as documented in the PostgreSQL page about Aggregate Functions.

## Examining Postgres 9.4 - A first look

DevFeed: [Examining Postgres 9.4 - A first look](<https://devfeed.tech/articles/examining-postgres-9-4-a-first-look-41160.md>)

Original publisher: [Read original article](<https://www.craigkerstiens.com/2014/02/02/Examining-PostgreSQL-9.4/>)

Author: Map

Published: 2014-02-02T20:55:56Z

Content type: article

Language: en

Sources: [Craig Kerstiens](<https://devfeed.tech/sources/craig-kerstiens.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Caching](<https://devfeed.tech/topics/caching.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [functions](<https://devfeed.tech/topics/functions.md>)

Tags: [aggregate-functions](<https://devfeed.tech/tags/aggregate-functions.md>), [cache](<https://devfeed.tech/tags/cache.md>), [failover](<https://devfeed.tech/tags/failover.md>), [pg-stat-statements](<https://devfeed.tech/tags/pg-stat-statements.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [read-replica](<https://devfeed.tech/tags/read-replica.md>)

### AI overview

A first look at PostgreSQL 9.4 while it is still in its final commit fest. The article discusses pg_prewarm for loading data into memory, concurrent materialized-view refreshes, and ordered-set aggregates, while noting that additional features may still change before release.

### Source excerpt

PostgreSQL is currently entering its final commit fest. While its still going, which means there could still be more great features to come, we can start to take a look at what you can expect from it now. This release seems to bring a lot of minor increments versus some bigger highlights of previous ones. At the same time there's still a lot on the bubble that may or may not make it which could entirely change the shape of this one. For a peek back of some of the past ones: Highlights of 9.2 pg_stat_statements Index only scans JSON Support Range types Huge performance improvements Highlights of 9.3 Postgres foreign data wrapper Materialized views Checksums On to 9.4 With 9.4 instead of a simply list lets dive into a little deeper to the more noticable one. pg_prewarm I'll lead with one that those who need it should see huge gains (read larger apps that have a read replica they eventually may fail over to). Pg_prewarm will pre-warm your cache by loading data into memory. You may be interested in running pg_prewarm before bringing up a new Postgres DB or on a replica to keep it fresh. Why it matters - If you have a read replica it won't have the same cache as the leader. This can work great as you can send queries to it and it'll optimize its own cache. However, if you're using it as a failover when you do have to failover you'll be running in a degraded mode while your cache warms up. Running pg_pregwarm against it on a periodic basis will make the experience when you do failover a much better one. Refresh materialized view concurrently Materialized views just came into Postgres in 9.3. The problem with them is they were largely unusable. This was because they 1. Didn't auto-refresh and 2. When you did refresh them it would lock the table while it ran the refresh making it unreadable during that time. Materialized views are often most helpful on large reporting tables that can take some time to generate. Often such a query can take 10-30 minutes or even more to run.