pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Lane Van Ingen <lvaningen@esncc.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Why Doesn't SQL This Expression Work?
Date: Mon, 22 Aug 2005 13:29:05 -0700 (PDT)
Message-ID: <20050822132441.P16438@megazone.bigpanda.com> (raw)
In-Reply-To: <EKEMKEFLOMKDDLIALABIAEKMCBAA.lvaningen@esncc.com>
References: <EKEMKEFLOMKDDLIALABIAEKMCBAA.lvaningen@esncc.com>


On Mon, 22 Aug 2005, Lane Van Ingen wrote:

> Hi, am trying to do a simple computation on two views, but for some reason
> the current_util_in computation always returns zero. All fields being used
> are integer.
>
>   select a.if_id,
>     a.in_count,
>     a.time_incr,
>     b.speed,
>     ((a.time_incr * b.speed) / 8) as possible_bytes,
>     (a.in_count / ((a.time_incr * b.speed) / 8) * 100) AS current_util_in,
>     from if_history_view1 a, speed_history_view1 b
>     where a.if_id = b.if_id
>     and a.if_id = 2;
>
> The inner computation (a.time_incr * b.speed / 8) evaluated properly to
> 7675200.
> Add the "in_count divide operation", and the result is zero.

Integer division doesn't follow all the same rules as normal division
would.  In particular (a/b)*c is not the same as a*c/b.

Also, I think you may be expecting rounding rather than truncation (and in
the case of (a.time_incr*b.speed)/8 can that not be a multiple of 8, and
if so what should happen?)



view thread (4+ messages)  latest in thread

Message-ID: <20050822132441.P16438@megazone.bigpanda.com>
Permalink:  ../20050822132441.P16438@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20050822132441.P16438@megazone.bigpanda.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: sszabo@megazone.bigpanda.com, lvaningen@esncc.com
  Subject: Re: Why Doesn't SQL This Expression Work?
  In-Reply-To: <20050822132441.P16438@megazone.bigpanda.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