Re: Aggregate Function to return most common value for a column - Mailing list pgsql-general

From artacus@comcast.net
Subject Re: Aggregate Function to return most common value for a column
Date
Msg-id 1792626127.9256531243005787312.JavaMail.root@sz0018a.emeryville.ca.mail.comcast.net
Whole thread Raw
In response to Aggregate Function to return most common value for a column  ("Michael Harris" <michael.harris@ericsson.com>)
Responses Re: Aggregate Function to return most common value for a column  (David Fetter <david@fetter.org>)
Re: Aggregate Function to return most common value for a column  ("Michael Harris" <michael.harris@ericsson.com>)
List pgsql-general
> I want to use an aggregate function that will return the most commonly
> occurring value in a column.

It's actually dead simple in Postgres. No C either. You just need to create an aggregate function.
I wrote a most() aggregate a while back that does exactly what you are asking for. Here, I'll add it to my blog...

http://scottrbailey.wordpress.com/2009/05/22/postgres-adding-custom-aggregates-most/


Scott Bailey

pgsql-general by date:

Previous
From: Keith Hayden
Date:
Subject: How to update stavaluesN columns in pg_statistics (type anyarry)
Next
From: Vick Khera
Date:
Subject: Re: Tuning resource parameters for a logging database.