Re: MAX, MIN and arrays

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: MAX, MIN and arrays
Date: 2005-11-27 08:50:41
Message-ID: 20051127085041.GA2081@kaufbach.delug.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Colton A Smith <smith(at)cs(dot)utk(dot)edu> schrieb:

> Hi:
>
> Let's say I have a table with a column of one-dimensional arrays. What
> exactly is returned when the database is queried for a maximum from that
> particular column? The array was the greatest average value? Let's say

What du you expect?

test=# select * from foo;
id | bar
----+---------
1 | {1,2,3}
2 | {2,2,2}
3 | {3,2,1}
(3 rows)

Which row is the max()?

test=# select max(bar) from foo;
max
---------
{3,2,1}
(1 row)

It compares the first value in every array. If you wish to compare the
array depending on a other column, you can use somethink like

test=# select id, bar from foo order by bar ;
id | bar
----+---------
1 | {1,2,3}
2 | {2,2,2}
3 | {3,2,1}
(3 rows)

test=# select id, bar from foo order by bar[3] ;
id | bar
----+---------
3 | {3,2,1}
2 | {2,2,2}
1 | {1,2,3}
(3 rows)

> I have a table with a column of two-dimensional arrays. What then?

The same.

HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Stark 2005-11-27 20:33:22 Re: Storing HTML in table
Previous Message Colton A Smith 2005-11-26 17:18:16 MAX, MIN and arrays