pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Youngblood <YoungblG@houstoncellular.com>
To: 'David Hartwig' <daybee@bellatlantic.net>
To: Greg Youngblood <YoungblG@houstoncellular.com>
Cc: 'PostgreSQL SQL List' <pgsql-sql@postgreSQL.org>
Subject: RE: [SQL] Please help: How to determine largest of two numbers in a  query?
Date: Thu, 3 Dec 1998 13:19:07 -0600
Message-ID: <2B9713A99045D211BB4E0008C75668692EA711@SCORPEXC1.houstoncell.com> (raw)

Thank you for the advice..

Ideally I would like to write a function, but I am just learning Postgres
and not familiar with creating functions like "greatest_int". 

In this case, the two values represent to different data streams. For the
information I need, I only need the greatest of the two. 

To work around this, I've started using two separate SELECT statements with
the comparison as part of the WHERE command. I also just tried the SELECT ..
UNION SELECT .. command, and it appears to have worked.

Thanks,
Greg

-----Original Message-----
From: David Hartwig [mailto:daybee@bellatlantic.net]
Sent: Wednesday, December 02, 1998 8:25 PM
To: Greg Youngblood
Cc: 'PostgreSQL SQL List'
Subject: Re: [SQL] Please help: How to determine largest of two numbers
in a query?


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

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

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

Then you do something like:

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

Or just do the SELECTs directly.

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





view thread (4+ messages)

Message-ID: <2B9713A99045D211BB4E0008C75668692EA711@SCORPEXC1.houstoncell.com>
Permalink:  ../2B9713A99045D211BB4E0008C75668692EA711@SCORPEXC1.houstoncell.com/
Also on:    postgresql.org/message-id/2B9713A99045D211BB4E0008C75668692EA711@SCORPEXC1.houstoncell.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: YoungblG@houstoncellular.com, daybee@bellatlantic.net
  Subject: Re: [SQL] Please help: How to determine largest of two numbers in a  query?
  In-Reply-To: <2B9713A99045D211BB4E0008C75668692EA711@SCORPEXC1.houstoncell.com>
  References: <2B9713A99045D211BB4E0008C75668692EA711@SCORPEXC1.houstoncell.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