Re: how to get the max value in an array

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: fanngyuan <fanngyuan(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: how to get the max value in an array
Date: 2011-06-03 04:29:00
Message-ID: BANLkTikzzQgh6W+g82OwX7AVNSWJdRWkEA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 2, 2011 at 10:52 PM, fanngyuan <fanngyuan(at)gmail(dot)com> wrote:
> hi guys:
>    I'm using int[] in postgrsql to store int array. I want to get max value
> of each row . While I can't find any function to get it(max function will
> get max array in one column) . Even I could write a sql function to get the
> max value. I still think a native funtion is better . Can your guys help me?

Please post questions like this to pgsql-general, rather than here.

What you are looking for is unnest:

rhaas=# select max(x) from unnest(array[1,2,3]) x;
max
-----
3
(1 row)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2011-06-03 05:14:46 Re: Domains versus polymorphic functions, redux
Previous Message Robert Haas 2011-06-03 04:27:35 Re: Domains versus polymorphic functions, redux