Re: dividing money by money

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Chris Travers" <chris(at)metatrontech(dot)com>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: dividing money by money
Date: 2010-03-31 14:07:49
Message-ID: 4BB310E50200002500030262@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Chris Travers <chris(at)metatrontech(dot)com> wrote:

> Just thinking about the more general problem and how things could
> be handled more gracefully...

Sure, but in the meantime, consider:

test=# select '12'::money * '2'::numeric;
?column?
----------
$24.00
(1 row)

test=# select '24'::money / '2'::numeric;
?column?
----------
$12.00
(1 row)

test=# select '24'::money / '12'::money;
ERROR: operator does not exist: money / money
LINE 1: select '24'::money / '12'::money;
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.

So we support:

a * b = c
c / b = a

but don't even *think* about c / a = b ???

The OP just wanted to add some symmetry to this, so that the
existing class could handle a not-uncommon use case more easily. As
far as I can see, the implementation of this operator could convert
two int64 values to numeric values and perform numeric division to
get the result. (I was going to mark the TODO as an easy one.) I
don't see how this change would affect what you want to do, one way
or the other.

-Kevin

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2010-03-31 14:35:17 Re: BUG #5400: Columns count mismatch in RULE with subquery
Previous Message Ing . Marcos Luís Ortíz Valmaseda 2010-03-31 13:31:15