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

Re: New version of money type

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-12-21 16:50:32
Message-ID: 20061221115032.0667cc55.darcy@druid.net (view raw or flat)
Thread:
Lists: pgsql-hackers
On Thu, 21 Dec 2006 10:47:52 -0500
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> > Very good points.  However, like the currency symbol issue I would like
> > to separate that into another discussion.  The code already exists with
> > the warts you mention (and more) and this proposal is to fix one thing
> > that will make it more useful to others.  Let's get that change in and
> > then start fixing up some of those other issues.
> 
> I've forgotten now --- was this patch intended *only* to convert money
> from int4 to int8 underlying representation, or did you do other things?

Well, the main intention was to just widen the underlying storage and
thus increase the range to the point that the type is useful to more
users.  In fact, as you can see, I have removed the change to drop the
currency on output just to keep this change to a single issue.
However, there was a little bit of cleanup as well.  I removed some
self-balancing XXX comments for example.  That's what CVS log is for.
I moved a few functions around in order to make static functions self
prototyping.  I added some consts to variables where appropriate.  The
cash_words function needed to be changed to accomodate the billions,
trillions and quadrillions that can now be handled.

Everything else should be directly related to the type change and
self-explanatory.

> It looks like there are unrelated changes in the patch, but I'm not sure
> if you just moved code around or did something more interesting.

Hopefully nothing too "interesting."  :-)

> One bug I see in it is that you'd better make the alignment 'd' if the

Fixed in my local tree.  Thanks.

> type is to be int8.  Also I much dislike these changes:
> 
> -	int32		i = PG_GETARG_INT32(1);
> +	int64		i = PG_GETARG_INT32(1);
> 
> I think they may not actually be wrong, but they certainly *look* wrong;
> in general the declared type of a parameter variable in a C-coded SQL
> function ought to match what the SQL signature says.  Anyway there is no
> need that I can see to widen these variables.  Every C compiler knows
> what to do if you ask it for arithmetic on a long and an int.

Right but I still need to accept int64 args here.  I have changed the
two relevant places to use PG_GETARG_INT64(1).

> (Speaking of which, have you thought about what happens on a machine
> with no 64-bit int, such that "int64" is really just 32 bits?  Ideally
> the code should continue to function but with reduced range.  I didn't
> see any places where you were obviously depending on the range, but
> it's something to have in the back of your mind while coding.)

Does PGSQL run on any such machines?  If so perhaps someone can
volunteer to do some testing if they have one.

-- 
D'Arcy J.M. Cain <darcy(at)druid(dot)net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

In response to

pgsql-hackers by date

Next:From: Simon RiggsDate: 2006-12-21 16:51:37
Subject: Re: Companies Contributing to Open Source
Previous:From: Martijn van OosterhoutDate: 2006-12-21 16:47:56
Subject: Re: column ordering, was Re: [PATCHES] Enums patch v2

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