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

Re: cast from integer to money

From: Joseph Adams <joeyadams3(dot)14159(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: cast from integer to money
Date: 2011-04-02 02:33:16
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Thu, Mar 31, 2011 at 6:39 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> Going just integer->money, with the "1" -> "$1.00", seems completely
> reasonable to me.  As for being too late in the cycle..  if someone's
> willing to do the work, I can't imagine it breaking anything, so I
> wouldn't be against putting it in.  It really should be before the
> first beta tho.

Attached is a patch which enables casting int2/int4/int8 to money,
with the same scaling as numeric uses.  Hence, 1::money yields '$1.00'
.  The only other numeric types (other than oid, cardinal_number,
etc.) that can't be casted directly to money are float4 and float8,
and I suspect this is intentional.

The patch includes tests, but does not update the documentation.
Should the docs be updated where it reads "Values of the numeric data
type can be cast to money. Other numeric types can be converted to
money by casting to numeric first" ?

Because this change adds rows to the pg_proc and pg_cast catalogs,
applying this patch for 9.1 will require alpha users to initdb again.
Is that acceptable?

Joey Adams

Attachment: cast-integer-to-money.patch
Description: text/x-patch (6.6 KB)

In response to


pgsql-hackers by date

Next:From: Rushabh LathiaDate: 2011-04-02 05:53:27
Subject: Re: postgres.exe has encountered a problem on windows
Previous:From: Darren DuncanDate: 2011-04-02 02:00:41
Subject: Re: Postgres 9.1 - Release Theme

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