Re: cast from integer to money

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Joseph Adams <joeyadams3(dot)14159(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cast from integer to money
Date: 2011-04-05 13:37:51
Message-ID: BANLkTinUxdO94FxO46+fVDgV=Z_AWNCf3g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Apr 5, 2011 at 1:10 AM, Joseph Adams <joeyadams3(dot)14159(at)gmail(dot)com> wrote:
> Attached is an updated version of the patch to allow conversion of
> int4/int8 directly to money.  I added overflow checks, dropped
> int2->cash, and updated the documentation.

Excellent, thanks.

My only gripe is that I don't think we should duplicate int8mul, so
I've changed your patch to use this incantation:

+ result = DatumGetInt64(DirectFunctionCall2(int8mul, Int64GetDatum(amount
+ Int64GetDatum(scale)));

...which is parallel to what the existing numeric -> money cast
already does. That results in a slightly different error message, but
I think that's OK: no one has complained about the numeric -> cash
error message, or the fact that the remaining functions in this module
do no overflow checking at all.

With that change, committed. Thanks for picking this one up.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2011-04-05 13:39:15 Re: Proposal: q-gram GIN and GiST indexes
Previous Message Dimitri Fontaine 2011-04-05 13:30:39 Re: Extensions Dependency Checking