Skip to Content.
Sympa Menu

internetworkers - Re: [internetworkers] SQL Help?

internetworkers AT lists.ibiblio.org

Subject: Internetworkers: http://www.ibiblio.org/internetworkers/

List archive

Chronological Thread  
  • From: Ilan Volow <listboy AT clarux.com>
  • To: "Internetworkers: http://www.ibiblio.org/internetworkers/" <internetworkers AT lists.ibiblio.org>
  • Subject: Re: [internetworkers] SQL Help?
  • Date: Tue, 26 Feb 2008 09:40:14 -0500


If you're trying to do "use this value, but use 0 instead if the value is null", you may want to substitute IF() with COALESCE(), which is more ANSI friendly (or so I've heard) and more portable between databases (theoretically). 

e,g, COALESCE(possibly_null_column_value, 0)


-- Ilan


On Feb 25, 2008, at 10:22 PM, Scott Russell wrote:


On Mon, 2008-02-25 at 18:47 -0500, Scott Russell wrote:
On Mon, 2008-02-25 at 16:41 -0500, Ilan Volow wrote:
I'm a PostgreSQL guy, so take my educated guess with a grain of salt,
but you might want to try this just to see if it works:

Much appreciated. I'll take a look at it...


FYI, You're suggestion worked fine. I'm not entirely convinced I'm doing
this sanely still, but it does work.

I also do this to calculate a read_size column which has the formula of
(read_bytes/read_ops = read_size). Note that read_ops could be 0 which
would yield a NULL in the read_size column. To avoid that, I use a
nested IF!

IF(SUM(IF(latx_stats_data.statname = 'read_ops', `statval`, 0)), 
(SUM(IF(latx_stats_data.statname = 'read_data', `statval`, 0)) /
SUM(IF(latx_stats_data.statname = 'read_ops', `statval`, 0))), 0) AS
'read_size'

I have to do this with several columns. I wonder if should read up on
stored procedures...

-- 
AIM: BlueCame1

---
Come and play at the InterNetWorkers Web site!  http://www.ibiblio.org/internetworkers/
You are currently subscribed to InterNetWorkers mailing list

Ilan Volow
"Implicit code is inherently evil, and here's the reason why:"






Archive powered by MHonArc 2.6.24.

Top of Page