pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
MAX, MIN and arrays
2+ messages / 2 participants
[nested] [flat]

* MAX, MIN and arrays
@ 2005-11-26 17:18 Colton A Smith <smith@cs.utk.edu>
  2005-11-27 08:50 ` Re: MAX, MIN and arrays Andreas Kretschmer <akretschmer@spamfence.net>
  0 siblings, 1 reply; 2+ messages in thread

From: Colton A Smith @ 2005-11-26 17:18 UTC (permalink / raw)
  To: pgsql-sql

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
I have a table with a column of two-dimensional arrays.  What then?

Thanks!



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: MAX, MIN and arrays
  2005-11-26 17:18 MAX, MIN and arrays Colton A Smith <smith@cs.utk.edu>
@ 2005-11-27 08:50 ` Andreas Kretschmer <akretschmer@spamfence.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Andreas Kretschmer @ 2005-11-27 08:50 UTC (permalink / raw)
  To: pgsql-sql

Colton A Smith <smith@cs.utk.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°



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-11-27 08:50 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-26 17:18 MAX, MIN and arrays Colton A Smith <smith@cs.utk.edu>
2005-11-27 08:50 ` Andreas Kretschmer <akretschmer@spamfence.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox