Skip site navigation (1) Skip section navigation (2)

dividing money by money

From: Andy Balholm <andy(at)balholm(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: dividing money by money
Date: 2010-03-29 23:37:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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=# select version();
 PostgreSQL 8.4.1 on i386-apple-darwin9.8.0, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490), 32-bit
(1 row)

postgres=# 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 need to add explicit type casts.

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

The ability to divide money by money would be useful for finding what percent one money value is of another. That is what I was wanting to use it for—finding out what percentage of a customer's original balance has been paid 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 money amount by '1'::money.

Andy Balholm
(509) 276-2065

pgsql-bugs by date

Next:From: Kevin GrittnerDate: 2010-03-30 04:18:07
Subject: Re: dividing money by money
Previous:From: Peter EisentrautDate: 2010-03-29 21:36:42
Subject: Re: BUG #5272: PL/Python SELECT: return composite fields as dict, not str

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group