Re: New version of money type

Lists: pgsql-hackers
From: "Luke Lonergan" <LLonergan(at)greenplum(dot)com>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 15:09:17
Message-ID: 3E37B936B592014B978C4415F90D662D03EA23AF@MI8NYCMAIL06.Mi8.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Though this may be the kiss of death, I favor a 64 bit float version of money. It's more terse than numeric and a *lot* faster when performing numeric operations because it would use a cpu intrinsic operand.

- Luke

Msg is shrt cuz m on ma treo

-----Original Message-----
From: D'Arcy J.M. Cain [mailto:darcy(at)druid(dot)net]
Sent: Thursday, September 28, 2006 11:02 AM Eastern Standard Time
To: D'Arcy J.M. Cain
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] New version of money type

On Thu, 14 Sep 2006 10:35:03 -0400
"D'Arcy J.M. Cain" <darcy(at)druid(dot)net> wrote:
> For years I have been promising that a 64 bit version of the money type
> was on the way. Here it is. So far it compiles and I have done some
> basic testing on it and it seems to work fine. Note that the currency
> symbol is also dropped on output as well but it is accepted on input.
>
> darcy=# select '$92,233,720,368,547,758.07'::money;
> money
> ----------------------------
> 92,233,720,368,547,758.07

There has been plenty of discussion back and forth but still no ruling
from core. Is money out in the next release in which case I can
convert this to a contrib module or will this improvement be accepted
for the next release.

--
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.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: "Luke Lonergan" <LLonergan(at)greenplum(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 15:15:00
Message-ID: 20060928111500.d1f226b5.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sep 2006 11:09:17 -0400
"Luke Lonergan" <LLonergan(at)greenplum(dot)com> wrote:
> Though this may be the kiss of death, I favor a 64 bit float version of money. It's more terse than numeric and a

I assume you mean "...64 bit INT version..."

--
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.


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Luke Lonergan <LLonergan(at)greenplum(dot)com>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 16:44:24
Message-ID: 20060928164424.GX24675@kenobi.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Luke Lonergan (LLonergan(at)greenplum(dot)com) wrote:
> Though this may be the kiss of death, I favor a 64 bit float version of money. It's more terse than numeric and a *lot* faster when performing numeric operations because it would use a cpu intrinsic operand.

What about just having a numeric64, or changing numeric to support
moving to 64bit sizes when necessary and supported by the platform?
Exactly how much faster would it *really* be? Have you tested it? At
what point does it become a 'winning' change?

I'm not sure about 'money' in general but these claims of great
performance improvments over numeric just don't fly so easily with me.
numeric isn't all *that* much slower than regular old integer in the
tests that I've done.

Thanks,

Stephen


From: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
To: "Stephen Frost" <sfrost(at)snowman(dot)net>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 17:02:04
Message-ID: C1414E1C.2E0C%llonergan@greenplum.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen,

On 9/28/06 9:44 AM, "Stephen Frost" <sfrost(at)snowman(dot)net> wrote:

> I'm not sure about 'money' in general but these claims of great
> performance improvments over numeric just don't fly so easily with me.
> numeric isn't all *that* much slower than regular old integer in the
> tests that I've done.

Part of the problem is the *size* of Numeric. I've just looked for
something that describes the size of a Numeric and I saw an old post that
says:
10 + x/2 bytes

So, a minimum of 10 bytes (compared to the 8 proposed for money64) plus
scale (x) divided by two.

Currently on the TPC-H benchmark, Postgres requires 1.7 times the amount of
internal database storage as what is in the ASCII data file representation.
Oracle and MSFT SQLServer are almost 1:1. Part of this fluff is the 24
bytes of tuple header, part of it is in the Numeric.

- Luke


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: LLonergan(at)greenplum(dot)com, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 17:12:13
Message-ID: 20060928131213.bd641ff6.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sep 2006 12:44:24 -0400
Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> I'm not sure about 'money' in general but these claims of great
> performance improvments over numeric just don't fly so easily with me.
> numeric isn't all *that* much slower than regular old integer in the
> tests that I've done.

Numeric has been shown to be as good or better than money in I/O
operations. Where money shines is in internal calculations.

--
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.


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: LLonergan(at)greenplum(dot)com, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 18:37:36
Message-ID: 20060928183736.GZ24675@kenobi.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* D'Arcy J.M. Cain (darcy(at)druid(dot)net) wrote:
> On Thu, 28 Sep 2006 12:44:24 -0400
> Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > I'm not sure about 'money' in general but these claims of great
> > performance improvments over numeric just don't fly so easily with me.
> > numeric isn't all *that* much slower than regular old integer in the
> > tests that I've done.
>
> Numeric has been shown to be as good or better than money in I/O
> operations. Where money shines is in internal calculations.

Which may be an area which could be improved on for numeric, or even a
numeric64 type added for it. I'm not entirely sure there's a huge
amount to gain there either though...

Thanks,

Stephen


From: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, "Stephen Frost" <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 18:39:31
Message-ID: C14164F3.2E4D%llonergan@greenplum.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

D'Arcy,

On 9/28/06 10:12 AM, "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> wrote:

> Numeric has been shown to be as good or better than money in I/O
> operations.

What exactly does that mean in the context of a Datum: "I/O operations"?

- Luke


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Luke Lonergan <llonergan(at)greenplum(dot)com>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 18:53:15
Message-ID: 20060928185315.GA16473@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 28, 2006 at 11:39:31AM -0700, Luke Lonergan wrote:
> D'Arcy,
>
> On 9/28/06 10:12 AM, "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> wrote:
>
> > Numeric has been shown to be as good or better than money in I/O
> > operations.
>
> What exactly does that mean in the context of a Datum: "I/O operations"?

Converting to/from text format for when dealing with client
applications. Numeric can convert faster than plain integers sometimes.
Numeric isn't that slow really...

Have a ncie day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, "Stephen Frost" <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 18:57:10
Message-ID: C1416916.2E6A%llonergan@greenplum.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Martijn,

On 9/28/06 11:53 AM, "Martijn van Oosterhout" <kleptog(at)svana(dot)org> wrote:

> Converting to/from text format for when dealing with client
> applications. Numeric can convert faster than plain integers sometimes.
> Numeric isn't that slow really...

Got it - so the performance benefits of the fixed point versus Numeric are:

- Smaller size of fixed point (less than half)
- Faster arithmetic operations

These should be quantified, so that we can evaluate Money64 as a proposal
and to understand Numeric better.

- Luke


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Luke Lonergan <llonergan(at)greenplum(dot)com>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 19:42:08
Message-ID: 20060928194208.GC16473@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 28, 2006 at 11:57:10AM -0700, Luke Lonergan wrote:
> Got it - so the performance benefits of the fixed point versus Numeric are:
>
> - Smaller size of fixed point (less than half)
> - Faster arithmetic operations
>
> These should be quantified, so that we can evaluate Money64 as a proposal
> and to understand Numeric better.

However, none of this seems to deal with the major problems with the
money type right now:

- Only supports one currency (dollars)
- Only supports one scale (yen has no decimal normally, but what if you
want to track hundredths of a dollar-cent?)

My question, what is this Money64 type buying you over just storing an
integer in your database? There should be some value-add somewhere, but
what is it?

I've written applications tracking money using just an integer, if
there were a special money type, I'd expect it to do something more.

Have a ncie day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, "Stephen Frost" <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 20:29:57
Message-ID: C1417ED5.2E8A%llonergan@greenplum.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Martijn,

On 9/28/06 12:42 PM, "Martijn van Oosterhout" <kleptog(at)svana(dot)org> wrote:

> - Only supports one currency (dollars)

What are the manifestations of this?

> - Only supports one scale (yen has no decimal normally, but what if you
> want to track hundredths of a dollar-cent?)

So, without a quantified benefit, this is certainly a non-starter.

- Luke


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Luke Lonergan <llonergan(at)greenplum(dot)com>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 20:53:34
Message-ID: 20060928205334.GD16473@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 28, 2006 at 01:29:57PM -0700, Luke Lonergan wrote:
> Martijn,
>
> On 9/28/06 12:42 PM, "Martijn van Oosterhout" <kleptog(at)svana(dot)org> wrote:
>
> > - Only supports one currency (dollars)
>
> What are the manifestations of this?

test=# select '100'::money;
money
---------
$100.00
(1 row)

The use of the dollar sign and the two decimal places make it wrong for
the vast majority of the world's population.

Now, there is some localization involved, so you can play tricks like:

test=# set lc_monetary ='nl_NL';
SET
test=# select '100'::money;
money
-----------
EUR100,00
(1 row)

Oops, by changing a GUC variable we just changed the semantic value of
every currency field in the database. You still can't change the number
of decimal places though.

> > - Only supports one scale (yen has no decimal normally, but what if you
> > want to track hundredths of a dollar-cent?)
>
> So, without a quantified benefit, this is certainly a non-starter.

Every new type needs to have a well-defined use-case before it can be
considered for includion.

Currently we have:
- Is possibly faster than numeric
- Takes less space than numeric
- Customisable output (only one currency at a time though)
- Fixed number of decimal places

What else?
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
Cc: sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 21:07:10
Message-ID: 20060928170710.82d40dd8.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sep 2006 11:39:31 -0700
"Luke Lonergan" <llonergan(at)greenplum(dot)com> wrote:
> > Numeric has been shown to be as good or better than money in I/O
> > operations.
>
> What exactly does that mean in the context of a Datum: "I/O operations"?

It means that numeric is better and parsing/storing/displaying than
money.

--
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.


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 21:19:47
Message-ID: 20060928171947.00933f52.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sep 2006 22:53:34 +0200
Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> Every new type needs to have a well-defined use-case before it can be
> considered for includion.

Well, it is already included. The current proposal is simply to
improve the existing type. I guess you are arguing a different
proposal altogether - to remove the existing type.

> Currently we have:
> - Is possibly faster than numeric

I suppose I should quantify this but it's hard to get motivated after
the many man-hours (mine and my staff) I had to spend on code and
schema optimizations I needed to do just to get closer to the previous
speed our aps had before we converted from money to numeric. I will
try to find time to put together a test that appoximates that real
world example.

> - Takes less space than numeric

Never really considered this a major improvement over numeric given the
cost of disk these days. I suppose it could be contributing to the
speed increase.

> - Customisable output (only one currency at a time though)
> - Fixed number of decimal places

The original code actually handled number of decimal places. It tended
to cause problems though. These are areas that the existing type, as
well as the proposed change, could be worked on. I would hesitate to
work on both together though and going to 64bit will probably add more
value right now than those things, certainly for existing users of the
type.

By the way, the current proposal actually removes the currency symbol
but I have received complaints about that. It should probably go back
just because it is outside of the scope of the primary change. That
can be dealt with later.

--
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.


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-28 23:32:11
Message-ID: 20060928233211.GF34238@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 28, 2006 at 05:19:47PM -0400, D'Arcy J.M. Cain wrote:
> On Thu, 28 Sep 2006 22:53:34 +0200
> Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> > Every new type needs to have a well-defined use-case before it can be
> > considered for includion.
>
> Well, it is already included. The current proposal is simply to
> improve the existing type. I guess you are arguing a different
> proposal altogether - to remove the existing type.

The existing type is depricated and has been since at least 8.1; so yes,
it's slated for removal.

> > Currently we have:
> > - Is possibly faster than numeric
>
> I suppose I should quantify this but it's hard to get motivated after
> the many man-hours (mine and my staff) I had to spend on code and
> schema optimizations I needed to do just to get closer to the previous
> speed our aps had before we converted from money to numeric. I will
> try to find time to put together a test that appoximates that real
> world example.
>
> > - Takes less space than numeric
>
> Never really considered this a major improvement over numeric given the
> cost of disk these days. I suppose it could be contributing to the
> speed increase.

Less space == more speed

> > - Customisable output (only one currency at a time though)
> > - Fixed number of decimal places
>
> The original code actually handled number of decimal places. It tended
> to cause problems though. These are areas that the existing type, as
> well as the proposed change, could be worked on. I would hesitate to
> work on both together though and going to 64bit will probably add more
> value right now than those things, certainly for existing users of the
> type.
>
> By the way, the current proposal actually removes the currency symbol
> but I have received complaints about that. It should probably go back
> just because it is outside of the scope of the primary change. That
> can be dealt with later.

Perhaps a good compromise would be to call your type 'USD' or something
similar. I can see where there's use for it, but it seems too limited to
consider it a generic money type.

What would be ideal is a money type that stored what currency was used
and let you change precision (within reason).
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-09-29 03:23:30
Message-ID: 8919.1159500210@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Jim C. Nasby" <jim(at)nasby(dot)net> writes:
> On Thu, Sep 28, 2006 at 05:19:47PM -0400, D'Arcy J.M. Cain wrote:
>> Well, it is already included. The current proposal is simply to
>> improve the existing type. I guess you are arguing a different
>> proposal altogether - to remove the existing type.

> The existing type is depricated and has been since at least 8.1; so yes,
> it's slated for removal.

Well, my perception of that has always been "it needs to be upgraded or
removed". So if D'Arcy wants to work on the improvement angle, I have
no problem with him doing so. The thing we need to negotiate is "how
much improvement is needed to keep it in core".

regards, tom lane


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-09-29 03:53:29
Message-ID: 20060929035328.GA90915@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 28, 2006 at 11:23:30PM -0400, Tom Lane wrote:
> "Jim C. Nasby" <jim(at)nasby(dot)net> writes:
> > On Thu, Sep 28, 2006 at 05:19:47PM -0400, D'Arcy J.M. Cain wrote:
> >> Well, it is already included. The current proposal is simply to
> >> improve the existing type. I guess you are arguing a different
> >> proposal altogether - to remove the existing type.
>
> > The existing type is depricated and has been since at least 8.1; so yes,
> > it's slated for removal.
>
> Well, my perception of that has always been "it needs to be upgraded or
> removed". So if D'Arcy wants to work on the improvement angle, I have
> no problem with him doing so. The thing we need to negotiate is "how
> much improvement is needed to keep it in core".

I think it's also important to protect for the possibility of a more
complete (and probably incompatible) type in the future, such as one
that stores what currency a value is in.

Hrm... does ANSI say anything about money types?
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-09-29 04:07:58
Message-ID: 9633.1159502878@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Jim C. Nasby" <jim(at)nasby(dot)net> writes:
> I think it's also important to protect for the possibility of a more
> complete (and probably incompatible) type in the future, such as one
> that stores what currency a value is in.

Well, such a type could be called "currency", "cash", "forex" or several
other possibilities, so I don't see any particular argument that "money"
has to be removed before something better can exist. The tightrope that
D'Arcy has to walk is different: improving "money" without making it so
incompatible as to break existing apps that use it.

> Hrm... does ANSI say anything about money types?

No.

regards, tom lane


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
Cc: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-29 10:19:07
Message-ID: 20060929101907.GD8702@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 28, 2006 at 06:32:11PM -0500, Jim C. Nasby wrote:
> What would be ideal is a money type that stored what currency was used
> and let you change precision (within reason).

The taggedtypes version of currency does half of that, by storing the
currency and allowing the output format to depend on that. It doesn't
allow you to easily change the precision though, that would require
user-defined typmod which is still under discussion.

It would be possible to create a taggedtypes version of currency based
on int64. With the currency tag it would be 12 bytes total. And the
number of decimal places could be defined per currency...

Interesting thought, probably wouldn't take more than an hour to whip
up.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: tomas(at)tuxteam(dot)de
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-30 04:42:13
Message-ID: 20060930044213.GA7205@www.trapp.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Sep 29, 2006 at 12:19:07PM +0200, Martijn van Oosterhout wrote:
> On Thu, Sep 28, 2006 at 06:32:11PM -0500, Jim C. Nasby wrote:
> > What would be ideal is a money type that stored what currency was used
> > and let you change precision (within reason).
>
> The taggedtypes version of currency does half of that, by storing the
> currency and allowing the output format to depend on that. It doesn't
> allow you to easily change the precision though, that would require
> user-defined typmod which is still under discussion.
>
> It would be possible to create a taggedtypes version of currency based
> on int64. With the currency tag it would be 12 bytes total. And the
> number of decimal places could be defined per currency...
>
> Interesting thought, probably wouldn't take more than an hour to whip
> up.

If you are at that, it's worth noting that the currency tag consists of
three capital ASCII letters. That would be fifteen bits, take or give.
That leaves fourty-eightish bits for the number or about 10^14.

THis is only half-serious, since there are other problems with
currencies (their value is dependent on time, all that Pandora's box).

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFHfWlBcgs9XrR2kYRAhieAJ9GYKruXeW3nqGyg0TO8Mo5bFBNMQCfbfzK
lbARH+l5PxIexOElcxTg3WE=
=//LX
-----END PGP SIGNATURE-----


From: David Fetter <david(at)fetter(dot)org>
To: tomas(at)tuxteam(dot)de
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-30 05:43:53
Message-ID: 20060930054353.GH24766@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Sep 30, 2006 at 04:42:13AM +0000, tomas(at)tuxteam(dot)de wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Fri, Sep 29, 2006 at 12:19:07PM +0200, Martijn van Oosterhout wrote:
> > On Thu, Sep 28, 2006 at 06:32:11PM -0500, Jim C. Nasby wrote:
> If you are at that, it's worth noting that the currency tag consists
> of three capital ASCII letters. That would be fifteen bits, take or
> give.

I feel silly for even mentioning this, but there are less than 256
countries in the UN, and as far as I know, each has at most one
currency, so you could use 8 bits instead of 15.

> That leaves forty-eightish bits for the number or about 10^14.

By the above calculation, 56 bits or about 7.2 * 10^16.

> THis is only half-serious, since there are other problems with
> currencies (their value is dependent on time, all that Pandora's
> box).

It's not just dependent on time. Exchange rates vary in such a way
that the relationships are not always transitive :P

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: tomas(at)tuxteam(dot)de
To: David Fetter <david(at)fetter(dot)org>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-30 08:23:14
Message-ID: 20060930082314.GA7651@www.trapp.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Sep 29, 2006 at 10:43:53PM -0700, David Fetter wrote:
> On Sat, Sep 30, 2006 at 04:42:13AM +0000, tomas(at)tuxteam(dot)de wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > On Fri, Sep 29, 2006 at 12:19:07PM +0200, Martijn van Oosterhout wrote:
> > > On Thu, Sep 28, 2006 at 06:32:11PM -0500, Jim C. Nasby wrote:

[15 bit for three upcase ASCII]

> I feel silly for even mentioning this, but there are less than 256
> countries in the UN, and as far as I know, each has at most one
> currency, so you could use 8 bits instead of 15.

Hm. But then you'd have to cope with a mapping (currency-id ->
description) which changes over time. Maybe it'd suffice to postulate
that "no id be reused".

> > That leaves forty-eightish bits for the number or about 10^14.
>
> By the above calculation, 56 bits or about 7.2 * 10^16.

Yes, way more useful than 10^14 (about a hundred times ;)

> It's not just dependent on time. Exchange rates vary in such a way
> that the relationships are not always transitive :P

:-)

Regards
- -- tomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFHilyBcgs9XrR2kYRAg+mAJ96+TTAjqEJK7J1nbI7EwVibYFoxwCfWElO
VJCskdQThqxI90gzTX+gR8A=
=OCN0
-----END PGP SIGNATURE-----


From: "Xiaofeng Zhao" <xf10036(at)hotmail(dot)com>
To: "David Fetter" <david(at)fetter(dot)org>, <tomas(at)tuxteam(dot)de>
Cc: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, <llonergan(at)greenplum(dot)com>, <sfrost(at)snowman(dot)net>, <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: New version of money type
Date: 2006-09-30 15:36:04
Message-ID: BAY124-DAV154E760669E4587E797CBAE5190@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> I feel silly for even mentioning this, but there are less than 256
> countries in the UN, and as far as I know, each has at most one
> currency, so you could use 8 bits instead of 15.
>
That's not always true, e.g. China has RMB and HKD. Also Taiwan is not a
member country of UN but I don't think one would exclude TWD.

There'll also times a country may transit from one currency to another.
Even a currency (currency of most continental European countries before
Euro) is no more being used, it may still need to be supported.

xz


From: David Fetter <david(at)fetter(dot)org>
To: Xiaofeng Zhao <xf10036(at)hotmail(dot)com>
Cc: tomas(at)tuxteam(dot)de, Martijn van Oosterhout <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: New version of money type
Date: 2006-09-30 15:57:04
Message-ID: 20060930155703.GI24766@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Sep 30, 2006 at 11:36:04AM -0400, Xiaofeng Zhao wrote:
> >I feel silly for even mentioning this, but there are less than 256
> >countries in the UN, and as far as I know, each has at most one
> >currency, so you could use 8 bits instead of 15.
> >
> That's not always true, e.g. China has RMB and HKD. Also Taiwan is
> not a member country of UN but I don't think one would exclude TWD.

Right. There are several countries whose currency is USD, so I still
contend that at any given instant, there are fewer than 256
currencies, so we're back to 8 bits.

> There'll also times a country may transit from one currency to
> another. Even a currency (currency of most continental European
> countries before Euro) is no more being used, it may still need to
> be supported.

The "money" type is far too simplistic to model this kind of thing. A
really sophisticated representation of money would have to take time,
inflation/deflation, pairwise exchange rates, etc. into account. It
would look more like a schema with a large data set and a large body
of code loaded into it than it would a data type.

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: Xiaofeng Zhao <xf10036(at)hotmail(dot)com>, tomas(at)tuxteam(dot)de, Martijn van Oosterhout <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-09-30 17:00:05
Message-ID: 13689.1159635605@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Fetter <david(at)fetter(dot)org> writes:
> The "money" type is far too simplistic to model this kind of thing. A
> really sophisticated representation of money would have to take time,
> inflation/deflation, pairwise exchange rates, etc. into account. It
> would look more like a schema with a large data set and a large body
> of code loaded into it than it would a data type.

I don't think that's the appropriate functionality for a data type.
I used to be in the currency trading game (before I decided hacking
Postgres was more fun), and if you ask me, the people who want this
functionality are specifically interested in those exchange rates and
time variations --- it's exactly the purpose of their databases to
store, search, and manipulate that data, so burying it behind the scenes
in a datatype is exactly the wrong approach.

At least for what I was doing back then, a tagged type is exactly the
right thing: all we'd have wanted is for it to keep us from thinking
that adding 2 USD and 2 EUR directly was a sane computation.

Oh BTW: 10^14 is not enough dynamic range --- those guys push around
*serious* amounts of money. Bill Gates' net wealth is somewhere north
of 10^13 cents, and he's just a private citizen not a bank.

regards, tom lane


From: "Xiaofeng Zhao" <xf10036(at)hotmail(dot)com>
To: "David Fetter" <david(at)fetter(dot)org>
Cc: <tomas(at)tuxteam(dot)de>, "Martijn van Oosterhout" <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, <llonergan(at)greenplum(dot)com>, <sfrost(at)snowman(dot)net>, <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: New version of money type
Date: 2006-09-30 18:49:03
Message-ID: BAY124-DAV16FE779A47D43A842E3C1AE5190@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> There'll also times a country may transit from one currency to
>> another. Even a currency (currency of most continental European
>> countries before Euro) is no more being used, it may still need to
>> be supported.
>
> The "money" type is far too simplistic to model this kind of thing. A
> really sophisticated representation of money would have to take time,
> inflation/deflation, pairwise exchange rates, etc. into account. It
> would look more like a schema with a large data set and a large body
> of code loaded into it than it would a data type.

The statement of my bank account does not contain any of the quantities you
mentioned. But when some body open a statement from year 2000, most likely
he expect to see the balance and transcations are in, say, German Marks, not
in Euros.

xz


From: tomas(at)tuxteam(dot)de
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Fetter <david(at)fetter(dot)org>, Xiaofeng Zhao <xf10036(at)hotmail(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-01 04:41:39
Message-ID: 20061001044139.GB11842@www.trapp.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Sep 30, 2006 at 01:00:05PM -0400, Tom Lane wrote:
> David Fetter <david(at)fetter(dot)org> writes:
[...]
> Oh BTW: 10^14 is not enough dynamic range --- those guys push around
> *serious* amounts of money. Bill Gates' net wealth is somewhere north
> of 10^13 cents, and he's just a private citizen not a bank.

I do agree that a range in the 10^14 is too small. Even 10^16 seems to
be uncomfortably near to existing values. And thensome like to do things
with (decimal) sub-cent accuracy (think percents and prices per weight
unit). May be 64 bit is just not enough for a tagged money type?

Regards
- -- tomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFH0cDBcgs9XrR2kYRAhBfAJ9xvi1z8N73VpoiPSczZCUgBENKrgCdHGOd
fEY52y+um4jgW1oUkb8YQ64=
=0UGx
-----END PGP SIGNATURE-----


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: jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-12 16:36:46
Message-ID: 20061012123646.fb46105e.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sep 2006 23:23:30 -0400
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > The existing type is depricated and has been since at least 8.1; so yes,
> > it's slated for removal.
>
> Well, my perception of that has always been "it needs to be upgraded or
> removed". So if D'Arcy wants to work on the improvement angle, I have
> no problem with him doing so. The thing we need to negotiate is "how
> much improvement is needed to keep it in core".

Well, the patch I submitted is definitely an improvement over the
existing version. Are you saying that I have to make further
improvements before these ones can be imported? ISTM that going to 64
bit without any other change is big enough to warrant the change as
is. Once that is done I would be happy to work on other improvements
but my experience tells me not to make more than one major change at a
time.

The one issue I have with my existing patch though is the removal of
the currency symbol from the output. There have been many suggestions
that that just gets in the way but, following up on my own statement
above, this is two changes, not one, and perhaps should be left out of
the patch for that reason.

--
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.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-12 17:21:37
Message-ID: 14003.1160673697@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Well, my perception of that has always been "it needs to be upgraded or
>> removed". So if D'Arcy wants to work on the improvement angle, I have
>> no problem with him doing so. The thing we need to negotiate is "how
>> much improvement is needed to keep it in core".

> Well, the patch I submitted is definitely an improvement over the
> existing version. Are you saying that I have to make further
> improvements before these ones can be imported?

I didn't say that. I was responding to someone whose position seemed to
be "money is going to be removed, therefore you shouldn't work on it".
I wanted to know exactly what would need to be fixed before they'd not
want it removed.

regards, tom lane


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: jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-12 17:55:26
Message-ID: 20061012135526.2c666403.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 12 Oct 2006 13:21:37 -0400
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Well, the patch I submitted is definitely an improvement over the
> > existing version. Are you saying that I have to make further
> > improvements before these ones can be imported?
>
> I didn't say that. I was responding to someone whose position seemed to
> be "money is going to be removed, therefore you shouldn't work on it".
> I wanted to know exactly what would need to be fixed before they'd not
> want it removed.

Cool. So what do I do with the patch? Should I add the currency
symbol back in and commit or should I resubmit the patch to hackers for
further review?

--
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.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-12 18:17:33
Message-ID: 14802.1160677053@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> Cool. So what do I do with the patch? Should I add the currency
> symbol back in and commit or should I resubmit the patch to hackers for
> further review?

Well, one thing you definitely *don't* do is commit right now, because
we're in feature freeze, not to mention trying to avoid forced initdbs
now that beta has started. Sit on it till 8.3 is branched, and
meanwhile think about what you want to do with the currency-symbol
issue...

regards, tom lane


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: jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-12 18:24:22
Message-ID: 20061012142422.8427ea1f.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 12 Oct 2006 14:17:33 -0400
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> > Cool. So what do I do with the patch? Should I add the currency
> > symbol back in and commit or should I resubmit the patch to hackers for
> > further review?
>
> Well, one thing you definitely *don't* do is commit right now, because
> we're in feature freeze, not to mention trying to avoid forced initdbs
> now that beta has started. Sit on it till 8.3 is branched, and

OK. I hadn't thought of it as a new feature per se but I understand
the initdb issue. Holding at 30,000 feet, ground control.

> meanwhile think about what you want to do with the currency-symbol
> issue...

Personally I don't see a need for it but I am currently in favour of
adding it back in before committing just so that we can deal with the
issue separately. The same as the other changes being discussed.

--
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.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-10-12 22:03:38
Message-ID: 200610122203.k9CM3cn09337@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


This thread has been saved for the 8.3 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

D'Arcy J.M. Cain wrote:
> On Thu, 12 Oct 2006 14:17:33 -0400
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> > > Cool. So what do I do with the patch? Should I add the currency
> > > symbol back in and commit or should I resubmit the patch to hackers for
> > > further review?
> >
> > Well, one thing you definitely *don't* do is commit right now, because
> > we're in feature freeze, not to mention trying to avoid forced initdbs
> > now that beta has started. Sit on it till 8.3 is branched, and
>
> OK. I hadn't thought of it as a new feature per se but I understand
> the initdb issue. Holding at 30,000 feet, ground control.
>
> > meanwhile think about what you want to do with the currency-symbol
> > issue...
>
> Personally I don't see a need for it but I am currently in favour of
> adding it back in before committing just so that we can deal with the
> issue separately. The same as the other changes being discussed.
>
> --
> 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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net
Subject: Re: New version of money type
Date: 2006-12-21 01:44:07
Message-ID: 20061220204407.9de7b2ec.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 12 Oct 2006 14:24:22 -0400
"D'Arcy J.M. Cain" <darcy(at)druid(dot)net> wrote:
> On Thu, 12 Oct 2006 14:17:33 -0400
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> > > Cool. So what do I do with the patch? Should I add the currency
> > > symbol back in and commit or should I resubmit the patch to hackers for
> > > further review?
> >
> > Well, one thing you definitely *don't* do is commit right now, because
> > we're in feature freeze, not to mention trying to avoid forced initdbs
> > now that beta has started. Sit on it till 8.3 is branched, and
>
> OK. I hadn't thought of it as a new feature per se but I understand
> the initdb issue. Holding at 30,000 feet, ground control.
>
> > meanwhile think about what you want to do with the currency-symbol
> > issue...
>
> Personally I don't see a need for it but I am currently in favour of
> adding it back in before committing just so that we can deal with the
> issue separately. The same as the other changes being discussed.

Now that 8.3 has been branched shall I go ahead and commit? As
discussed I will put the currency symbol back in just so that it can be
discussed and worked on as a completely separate issue. I have
attached the current patch against HEAD.

--
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.

Attachment Content-Type Size
cash64_patch application/octet-stream 13.9 KB

From: David Fetter <david(at)fetter(dot)org>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, tgl(at)sss(dot)pgh(dot)pa(dot)us, jim(at)nasby(dot)net, kleptog(at)svana(dot)org, llonergan(at)greenplum(dot)com, sfrost(at)snowman(dot)net
Subject: Re: New version of money type
Date: 2006-12-21 08:21:08
Message-ID: 20061221082108.GC1928@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 20, 2006 at 08:44:07PM -0500, D'Arcy J.M. Cain wrote:
> On Thu, 12 Oct 2006 14:24:22 -0400
> "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> wrote:
> > On Thu, 12 Oct 2006 14:17:33 -0400
> > Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > > "D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> > > > Cool. So what do I do with the patch? Should I add the
> > > > currency symbol back in and commit or should I resubmit the
> > > > patch to hackers for further review?
> > >
> > > Well, one thing you definitely *don't* do is commit right now,
> > > because we're in feature freeze, not to mention trying to avoid
> > > forced initdbs now that beta has started. Sit on it till 8.3 is
> > > branched, and
> >
> > OK. I hadn't thought of it as a new feature per se but I
> > understand the initdb issue. Holding at 30,000 feet, ground
> > control.
> >
> > > meanwhile think about what you want to do with the
> > > currency-symbol issue...
> >
> > Personally I don't see a need for it but I am currently in favour
> > of adding it back in before committing just so that we can deal
> > with the issue separately. The same as the other changes being
> > discussed.
>
> Now that 8.3 has been branched shall I go ahead and commit? As
> discussed I will put the currency symbol back in just so that it can
> be discussed and worked on as a completely separate issue. I have
> attached the current patch against HEAD.

I noticed that all your numbers are in English. Is it necessary to
hard-code all that? Also, you're assuming that powers of 10 which are
divisible by 3 are the relevant ones. In China, it's powers of 10
divisible by 4, and in India, it's 0, 1, 2, 3, followed by odd numbers
up through 19.

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: David Fetter <david(at)fetter(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-12-21 13:39:19
Message-ID: 20061221083919.4a62eb77.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 21 Dec 2006 00:21:08 -0800
David Fetter <david(at)fetter(dot)org> wrote:
> On Wed, Dec 20, 2006 at 08:44:07PM -0500, D'Arcy J.M. Cain wrote:
> > Now that 8.3 has been branched shall I go ahead and commit? As
> > discussed I will put the currency symbol back in just so that it can
> > be discussed and worked on as a completely separate issue. I have
> > attached the current patch against HEAD.
>
> I noticed that all your numbers are in English. Is it necessary to
> hard-code all that? Also, you're assuming that powers of 10 which are
> divisible by 3 are the relevant ones. In China, it's powers of 10
> divisible by 4, and in India, it's 0, 1, 2, 3, followed by odd numbers
> up through 19.

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.

--
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.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: David Fetter <david(at)fetter(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-12-21 15:47:52
Message-ID: 19702.1166716072@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"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?
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.

One bug I see in it is that you'd better make the alignment 'd' if the
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.

(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.)

regards, tom lane


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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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.


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: david(at)fetter(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2006-12-22 10:30:41
Message-ID: 20061222053041.bdf58666.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 21 Dec 2006 10:47:52 -0500
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> One bug I see in it is that you'd better make the alignment 'd' if the
> type is to be int8. Also I much dislike these changes:
>
> - int32 i = PG_GETARG_INT32(1);
> + int64 i = PG_GETARG_INT32(1);

As I have made the few corrections that you pointed out, should I go
ahead and commit so that it can be tested in a wider group? Also,
there are further ideas out there to improve the type further that
would be easier to handle with this out of the way.

--
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.


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-31 20:49:38
Message-ID: 20061231154938.fa5f7b36.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 21 Dec 2006 10:47:52 -0500
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> One bug I see in it is that you'd better make the alignment 'd' if the
> type is to be int8. Also I much dislike these changes:
>
> - int32 i = PG_GETARG_INT32(1);
> + int64 i = PG_GETARG_INT32(1);

I changed this and a few other things. I didn't see any response to my
question though. Shall I go ahead and commit now so that we can test
in a wider setting? I haven't committed anything in years and I am
hesitant to do so now without consencus.

--
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.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: New version of money type
Date: 2007-01-02 06:55:41
Message-ID: 25982.1167720941@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"D'Arcy J.M. Cain" <darcy(at)druid(dot)net> writes:
> I changed this and a few other things. I didn't see any response to my
> question though. Shall I go ahead and commit now so that we can test
> in a wider setting? I haven't committed anything in years and I am
> hesitant to do so now without consencus.

FWIW, as long as you responded to my coding-style criticisms I don't
have any problem with your committing it. Perhaps someone else does...

regards, tom lane