pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: emilu@encs.concordia.ca
Cc: Josh Williams <joshwilliams@ij.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Get the max(value1, value2, value3) from a table
Date: Mon, 7 Jan 2008 17:16:21 -0600
Message-ID: <dcc563d10801071516s429d1ff6hcfa1b59f9a83bc96@mail.gmail.com> (raw)
In-Reply-To: <4782AD66.3060606@encs.concordia.ca>
References: <4782A1B2.5050804@encs.concordia.ca>
	<1199745537.5877.9.camel@godzilla.local.scalefeather.com>
	<dcc563d10801071443g3c91a29sd27ce5bdf6c4652b@mail.gmail.com>
	<4782AD66.3060606@encs.concordia.ca>

On Jan 7, 2008 4:53 PM, Emi Lu <emilu@encs.concordia.ca> wrote:
> >>> select ?max?(col1, col2, col3) as result;
> >>> will return
> >>>
> >>> result
> >>> -------
> >>> 5
> >>> 8
> >>> 12
> >>>
> >>> (3 rows)
> >> 8.1 (I believe?) introduced GREATEST(), which does precisely what you're
> >> looking for.
> >
> > How would greatest give him three rows like that?  Maybe I'm
> > misunderstanding what the OP was asking for...
>
> IF 8.1, "select greatest(col1, col2, col3) from test" is exactly what I
> am looking for.
>
> I would do the optional query by union/or for now.

OK, looking back at your example, I do think I got it wrong.  The
greatest thing should work... Here's a test from 8.1 to prove it ...

create table test (col1 int, col2 int, col3 int);
insert into test values (1,5,2);
smarlowe=# insert into test values (8,1,3);
smarlowe=# insert into test values (12,1,1);
select greatest(col1,col2,col3) from test;
 greatest
----------
        5
        8
       12

tada!  So yeah, you want 8.1 (or 8.2 or 8.3)



view thread (11+ messages)  latest in thread

Message-ID: <dcc563d10801071516s429d1ff6hcfa1b59f9a83bc96@mail.gmail.com>
Permalink:  ../dcc563d10801071516s429d1ff6hcfa1b59f9a83bc96@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10801071516s429d1ff6hcfa1b59f9a83bc96@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: scott.marlowe@gmail.com, emilu@encs.concordia.ca, joshwilliams@ij.net
  Subject: Re: Get the max(value1, value2, value3) from a table
  In-Reply-To: <dcc563d10801071516s429d1ff6hcfa1b59f9a83bc96@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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