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

From David Fetter
Subject Re: Aggregate Function to return most common value for a column
Date
Msg-id 20090522160213.GA29304@fetter.org
Whole thread Raw
In response to Re: Aggregate Function to return most common value for a column  (artacus@comcast.net)
Responses Re: Aggregate Function to return most common value for a column  (artacus@comcast.net)
List pgsql-general
On Fri, May 22, 2009 at 03:23:07PM +0000, artacus@comcast.net wrote:
> > 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/

Such an aggregate should probably be called, "mode," that being the
probability/statistics name for the concept.

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

pgsql-general by date:

Previous
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: question on serial key
Next
From: Scott Marlowe
Date:
Subject: Re: question on serial key