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

From: David Fetter <david(at)fetter(dot)org>
To: artacus(at)comcast(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregate Function to return most common value for a column
Date: 2009-05-22 20:36:07
Message-ID: 20090522203607.GA10465@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, May 22, 2009 at 05:23:47PM +0000, artacus(at)comcast(dot)net wrote:
>
> On Fri, May 22, 2009 at 03:23:07PM +0000, artacus(at)comcast(dot)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.
>
> Excellent observation Dave. Sometimes I can't see outside of the box I'm in. And at the time I was focusing on text so statistics was in another box. I've update post with final functions for mode(), median() and range().

Thanks! :)

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

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-05-22 21:40:51 Re: Aggregate Function to return most common value for a column
Previous Message Joshua D. Drake 2009-05-22 20:14:38 Re: question about SSIS