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 456544110.9296591243013027623.JavaMail.root@sz0018a.emeryville.ca.mail.comcast.net
Whole thread Raw
In response to Re: Aggregate Function to return most common value for a column  (David Fetter <david@fetter.org>)
Responses Re: Aggregate Function to return most common value for a column
Re: Aggregate Function to return most common value for a column
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.

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().

Scott

pgsql-general by date:

Previous
From: Nico Sabbi
Date:
Subject: Re: I can't drop a user if I don't drop his grants beforehand??????????????????
Next
From: Keith Hayden
Date:
Subject: Re: How to update stavaluesN columns in pg_statistics (type anyarry)