Re: Aggregate Function to return most common value for a column

From: artacus(at)comcast(dot)net
To: Michael Harris <michael(dot)harris(at)ericsson(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregate Function to return most common value for a column
Date: 2009-05-22 15:23:07
Message-ID: 1792626127.9256531243005787312.JavaMail.root@sz0018a.emeryville.ca.mail.comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alex Thurlow 2009-05-22 15:35:35 Re: Tuning resource parameters for a logging database.
Previous Message Brandon Metcalf 2009-05-22 15:04:25 Re: question on serial key