dividing money by money - Mailing list pgsql-bugs

From Andy Balholm
Subject dividing money by money
Date
Msg-id 31F5F44C-0614-4CDD-ABCA-889DE778EF13@balholm.com
Whole thread Raw
List pgsql-bugs
When I divide a money value by another money value, I get an error message,=
 as follows:

***************************
psql (8.4.1)
Type "help" for help.

postgres=3D# select version();
                                                               version=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20
---------------------------------------------------------------------------=
-----------------------------------------------------------
 PostgreSQL 8.4.1 on i386-apple-darwin9.8.0, compiled by GCC i686-apple-dar=
win9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490), 32-bit
(1 row)

postgres=3D# select '$2'::money / '$1'::money;
ERROR:  operator does not exist: money / money
LINE 1: select '$2'::money / '$1'::money;
                           ^
HINT:  No operator matches the given name and argument type(s). You might n=
eed to add explicit type casts.
***************************

I expected to get a result of 2 or 2.0 in some numeric type (maybe double p=
recision). The result should be a pure number because the units (dollars, i=
n this case) cancel out.

The ability to divide money by money would be useful for finding what perce=
nt one money value is of another. That is what I was wanting to use it for=
=97finding out what percentage of a customer's original balance has been pa=
id off.

It would also provide a better way to convert money into numeric types than=
 the regular expression in the documentation. You could just divide the mon=
ey amount by '1'::money.

Andy Balholm
(509) 276-2065
andy@balholm.com

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: BUG #5272: PL/Python SELECT: return composite fields as dict, not str
Next
From: "Kevin Grittner"
Date:
Subject: Re: dividing money by money