From: | "Michael Harris" <michael(dot)harris(at)ericsson(dot)com> |
---|---|
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 22:14:00 |
Message-ID: | E5F4C5A18CAB7A4DA23080DE9CE815860834FD1A@eaubrmw001.eapac.ericsson.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi Scott,
Brilliant, that's exactly what I wanted.
I guess the only thing that worries me is if the table being aggregated
is very large, I assume this solution will use a lot of memory - since
it creates an array containing all of the values in the target
expression - but I suspect in my application that won't be a problem.
Thanks again,
Regards // Mike
-----Original Message-----
From: artacus(at)comcast(dot)net [mailto:artacus(at)comcast(dot)net]
Sent: Saturday, 23 May 2009 1:23 AM
To: Michael Harris
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Aggregate Function to return most common value
for a column
> 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-aggr
egates-most/
Scott Bailey
From | Date | Subject | |
---|---|---|---|
Next Message | Konstantin Izmailov | 2009-05-23 00:22:13 | Re: question about SSIS |
Previous Message | Benjamin Smith | 2009-05-22 22:10:11 | Code tables, conditional foreign keys? |