pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re[2]: [SQL] Please help: How to determine largest of two numbers in a query?
7+ messages / 5 participants
[nested] [flat]

* Re[2]: [SQL] Please help: How to determine largest of two numbers in a query?
@ 1998-12-03 12:38 Sferacarta Software <sferac@bo.nettuno.it>
  0 siblings, 0 replies; 7+ messages in thread

From: Sferacarta Software @ 1998-12-03 12:38 UTC (permalink / raw)
  To: Greg Youngblood <YoungblG@houstoncellular.com>; David Hartwig <daybee@bellatlantic.net>; pgsql-sql

Hello David,

giovedì, 3 dicembre 98, you wrote:

DH> My $.03 worth, without really knowing what these values represent:

DH> There is no such "standard" query that can conditionally select between two
DH> columns.   Fortunately PostgreSQL will allow you to create function - of one
DH> does not already exist.

DH> The function would be something like:
DH>     greater_int(integer a, integer b)
DH> It takes two integers arguments and returns the greater integer.

DH> Then you do something like:

DH> CREATE VIEW  myview AS
DH>     SELECT yyymmdd, key, greater_int(value1, value2) FROM mytable;

DH> Or just do the SELECTs directly.

DH> This may not be the most efficient way to accomplish your goal.   I would also
DH> take a good look at may table design.   Value1 and value2 MAY be a repeating
DH> group and you may want to normalize a little more.  Or not.


DH> Greg Youngblood wrote:

>> I have a table with the following structure:
>>         yyyymmdd        int4
>>         key             char(16)
>>         value1          int4
>>         value2          int4
>>
>> with the following sample data:
>>         yyyymmdd        key     value1  value2
>>         19981201        hello   32      16
>>         19981201        bye     29      64
>>         19981202        hello   16      20
>>         19981202        bye     23      13
>>
>> What I need is to select the greatest between value1 and value2, so the
>> answer would be:
>>         yyyymmdd        key     value
>>         19981201        hello   32
>>         19981201        bye     64
>>         19981202        hello   20
>>         19981202        bye     23
>>
>> I can do this via ODBC using access by creating a column which is defined as
>> IF(value1>value2,value1,value2) but that doesn't work in psql.
>>
>> How can I make this work in psql?
>>
>> Thanks
>> Greg

PostgreSQL has already these built-in funcions (those used on
aggregate MIN/MAX):

int2     |int2larger         |int2 int2     |larger of two
int2     |int2smaller        |int2 int2     |smaller of two                    
int4     |int4larger         |int4 int4     |larger of two                     
int4     |int4smaller        |int4 int4     |smaller of two                    
int8     |int8larger         |int8 int8     |larger of two                     
int8     |int8smaller        |int8 int8     |smaller of two 

exemple:

SELECT int4larger(3,10)
int4larger
----------
        10
(1 row)

-Jose'-





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

* RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a  query?
@ 1998-12-03 19:23 Greg Youngblood <YoungblG@houstoncellular.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Greg Youngblood @ 1998-12-03 19:23 UTC (permalink / raw)
  To: 'Sferacarta Software' <sferac@bo.nettuno.it>; pgsql-sql

Many many thanks.. This is exactly what I was looking for.

I must be totally blind... Where can I find a list of the functions Postgres
already has.. I'm sure there has to be a way.. 

-----Original Message-----
From: Sferacarta Software [mailto:sferac@bo.nettuno.it]
Sent: Thursday, December 03, 1998 6:39 AM
To: Greg Youngblood; David Hartwig; 'PostgreSQL SQL List'
Subject: Re[2]: [SQL] Please help: How to determine largest of two
numbers in a query?
PostgreSQL has already these built-in funcions (those used on
aggregate MIN/MAX):

int2     |int2larger         |int2 int2     |larger of two
int2     |int2smaller        |int2 int2     |smaller of two

int4     |int4larger         |int4 int4     |larger of two

int4     |int4smaller        |int4 int4     |smaller of two

int8     |int8larger         |int8 int8     |larger of two

int8     |int8smaller        |int8 int8     |smaller of two 

exemple:

SELECT int4larger(3,10)
int4larger
----------
        10
(1 row)

-Jose'-




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

* RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query?
@ 1998-12-03 19:53 Barracuda <cuda_fx@yahoo.com>
  1998-12-03 23:24 ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Barracuda @ 1998-12-03 19:53 UTC (permalink / raw)
  To: pgsql-sql

Is this what you're looking for?

\do

this one eluded me for some time:)

Charles




---Greg Youngblood <YoungblG@houstoncellular.com> wrote:
>
> Many many thanks.. This is exactly what I was looking for.
> 
> I must be totally blind... Where can I find a list of the functions
Postgres
> already has.. I'm sure there has to be a way.. 
> 
> 
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com




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

* Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query?
  1998-12-03 19:53 RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Barracuda <cuda_fx@yahoo.com>
@ 1998-12-03 23:24 ` Bruce Momjian <maillist@candle.pha.pa.us>
  1998-12-04 12:27   ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Roderick A. Anderson <raanders@altoplanos.net>
  0 siblings, 1 reply; 7+ messages in thread

From: Bruce Momjian @ 1998-12-03 23:24 UTC (permalink / raw)
  To: cuda_fx@yahoo.com; +Cc: pgsql-sql

> Is this what you're looking for?
> 
> \do
> 
> this one eluded me for some time:)
> 
> Charles

Please tell me why it was hard to find, and how to better document it.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



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

* Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query?
  1998-12-03 19:53 RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Barracuda <cuda_fx@yahoo.com>
  1998-12-03 23:24 ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
@ 1998-12-04 12:27   ` Roderick A. Anderson <raanders@altoplanos.net>
  1998-12-04 15:26     ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Roderick A. Anderson @ 1998-12-04 12:27 UTC (permalink / raw)
  To: Bruce Momjian <maillist@candle.pha.pa.us>; +Cc: pgsql-sql

On Thu, 3 Dec 1998, Bruce Momjian wrote:

> Please tell me why it was hard to find, and how to better document it.

Probably because it scrolls off the top of a standard 24 row screen when
the \? is used.  Or at least on my 6.3.x system at home.  Can't imagine
the command list getting shorter in 6.4 ;-)  Maybe the \? command could
page the display?

Rod
--
Roderick A. Anderson
raanders@altoplanos.net               Altoplanos Information Systems, Inc.
Voice: 208.765.6149                            212 S. 11th Street, Suite 5
FAX: 208.664.5299                                  Coeur d'Alene, ID 83814




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

* Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query?
  1998-12-03 19:53 RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Barracuda <cuda_fx@yahoo.com>
  1998-12-03 23:24 ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
  1998-12-04 12:27   ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Roderick A. Anderson <raanders@altoplanos.net>
@ 1998-12-04 15:26     ` Bruce Momjian <maillist@candle.pha.pa.us>
  1998-12-04 19:55       ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Roderick A. Anderson <raanders@altoplanos.net>
  0 siblings, 1 reply; 7+ messages in thread

From: Bruce Momjian @ 1998-12-04 15:26 UTC (permalink / raw)
  To: raanders@altoplanos.net; +Cc: pgsql-sql

> On Thu, 3 Dec 1998, Bruce Momjian wrote:
> 
> > Please tell me why it was hard to find, and how to better document it.
> 
> Probably because it scrolls off the top of a standard 24 row screen when
> the \? is used.  Or at least on my 6.3.x system at home.  Can't imagine
> the command list getting shorter in 6.4 ;-)  Maybe the \? command could
> page the display?

It does page display here.  Do you have the environment variable PAGER
defined?


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



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

* Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query?
  1998-12-03 19:53 RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Barracuda <cuda_fx@yahoo.com>
  1998-12-03 23:24 ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
  1998-12-04 12:27   ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Roderick A. Anderson <raanders@altoplanos.net>
  1998-12-04 15:26     ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
@ 1998-12-04 19:55       ` Roderick A. Anderson <raanders@altoplanos.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Roderick A. Anderson @ 1998-12-04 19:55 UTC (permalink / raw)
  To: Bruce Momjian <maillist@candle.pha.pa.us>; +Cc: pgsql-sql

On Fri, 4 Dec 1998, Bruce Momjian wrote:

> It does page display here.  Do you have the environment variable PAGER
> defined?

Gently pointed out to me earlier today.  No I don't.  I don't get to play
(work) with PostgreSQL as much as I'd like to so this fell out of my short
term memory unit.  It will come in handy when I get back to work on a
couple of projects.
   Sounds like we're running out of excuses for missing the '\do' ;-)  I
didn't have a problem finding it when I've been exploring PostgreSQL but
then I'm very observant (or AR if you believe my wife).

Rod
> 
> 
> -- 
>   Bruce Momjian                        |  http://www.op.net/~candle
>   maillist@candle.pha.pa.us            |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
> 

--
Roderick A. Anderson
raanders@altoplanos.net               Altoplanos Information Systems, Inc.
Voice: 208.765.6149                            212 S. 11th Street, Suite 5
FAX: 208.664.5299                                  Coeur d'Alene, ID 83814




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


end of thread, other threads:[~1998-12-04 19:55 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-12-03 12:38 Re[2]: [SQL] Please help: How to determine largest of two numbers in a query? Sferacarta Software <sferac@bo.nettuno.it>
1998-12-03 19:23 RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a  query? Greg Youngblood <YoungblG@houstoncellular.com>
1998-12-03 19:53 RE: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Barracuda <cuda_fx@yahoo.com>
1998-12-03 23:24 ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
1998-12-04 12:27   ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Roderick A. Anderson <raanders@altoplanos.net>
1998-12-04 15:26     ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Bruce Momjian <maillist@candle.pha.pa.us>
1998-12-04 19:55       ` Re: Re[2]: [SQL] Please help: How to determine largest of two num bers in a query? Roderick A. Anderson <raanders@altoplanos.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