money data type and conversions

Started by Bruce Momjianalmost 27 years ago13 messageshackers
Jump to latest
#1Bruce Momjian
bruce@momjian.us

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

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

test=> create table t(x money);
CREATE
test=> insert into t values (3.3);
ERROR: Attribute 'x' is of type 'money' but expression is of type 'float8'
You will need to rewrite or cast the expression
test=> insert into t values (3.33);
ERROR: Attribute 'x' is of type 'money' but expression is of type 'float8'
You will need to rewrite or cast the expression
test=> insert into t values (money(3.33));
ERROR: No such function 'money' with the specified attributes
test=> insert into t values (cash(3.33));
ERROR: No such function 'cash' with the specified attributes
test=> insert into t values (3.33);
ERROR: Attribute 'x' is of type 'money' but expression is of type 'float8'
You will need to rewrite or cast the expression
test=> insert into t values ('3.33');
INSERT 18569 1
test=> select int(x) from t;
ERROR: No such function 'int' with the specified attributes
test=> select int4(x) from t;
ERROR: No such function 'int4' with the specified attributes

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#2Duane Currie
dcurrie@sandman.acadiau.ca
In reply to: Bruce Momjian (#1)
Re: [HACKERS] money data type and conversions

Bruce,

TODO almost done:

I have three files which implement two functions to convert from
money to integer and from integer to money. Tested it out... works

Who should I send these to to have the changes applied to a later release?

Thanx,
Duane

Show quoted text

Thus spake Bruce Momjian

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

Good question. I wonder if #2 is the answer to #1.

Added to TODO:

* Money type requires quotes for input, and no coversion functions

-- 
Bruce Momjian                        |  http://www.op.net/~candle
maillist@candle.pha.pa.us            |  (610) 853-3000
+  If your life is a hard drive,     |  830 Blythe Avenue
+  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#3Vince Vielhaber
vev@michvhf.com
In reply to: Bruce Momjian (#1)
RE: [HACKERS] money data type and conversions

On 22-Jun-99 Bruce Momjian wrote:

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

Dunno about the int() stuff, but it seems that I've always had to quote
money. I ass-u-me d it had to do with the $ sign, 'cuze using a float
would cause it to crab about the wrong data type.

Vince.
--
==========================================================================
Vince Vielhaber -- KA8CSH email: vev@michvhf.com flame-mail: /dev/null
# include <std/disclaimers.h> TEAM-OS2
Online Campground Directory http://www.camping-usa.com
Online Giftshop Superstore http://www.cloudninegifts.com
==========================================================================

#4D'Arcy J.M. Cain
darcy@druid.net
In reply to: Bruce Momjian (#1)
Re: [HACKERS] money data type and conversions

Thus spake Bruce Momjian

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

Good question. I wonder if #2 is the answer to #1.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.
#5Bruce Momjian
bruce@momjian.us
In reply to: D'Arcy J.M. Cain (#4)
Re: [HACKERS] money data type and conversions

Thus spake Bruce Momjian

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

Good question. I wonder if #2 is the answer to #1.

Added to TODO:

* Money type requires quotes for input, and no coversion functions

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#6Bruce Momjian
bruce@momjian.us
In reply to: Duane Currie (#2)
Re: [HACKERS] money data type and conversions

Bruce,

TODO almost done:

I have three files which implement two functions to convert from
money to integer and from integer to money. Tested it out... works

Who should I send these to to have the changes applied to a later release?

Send them over to the patches list. We will apply them to 6.6 because
they will require a dump/restore. Thomas will probably do something
with them and binary compatible types.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#7Thomas Lockhart
lockhart@alumni.caltech.edu
In reply to: Bruce Momjian (#5)
Re: [HACKERS] money data type and conversions

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

Good question. I wonder if #2 is the answer to #1.

Added to TODO:
* Money type requires quotes for input, and no coversion functions

And while you are at it, add one more entry:

* Remove money type

NUMERIC and DECIMAL are (or should be, if there are rough edges since
they are so new) are the SQL92-way to represent currency. And, they
are compatible with all different conventions, since you can set the
decimal place and size of the fractional part as you want.

We didn't remove the money type for v6.5 since the newer types are so,
uh, new. But if there are no reported, unfixable problems we should
drop the money type for the next release.

As a sop to make the conversion easier, we can equivalence "money" to
"numeric(xx,2)" at that time.

- Thomas

--
Thomas Lockhart lockhart@alumni.caltech.edu
South Pasadena, California

#8Bruce Momjian
bruce@momjian.us
In reply to: Thomas Lockhart (#7)
Re: [HACKERS] money data type and conversions

Can someone explain why our money type in 6.5 requires quotes, and why
there is no int() function for it?

Good question. I wonder if #2 is the answer to #1.

Added to TODO:
* Money type requires quotes for input, and no coversion functions

And while you are at it, add one more entry:

* Remove money type

Added to TODO:

* Remove Money type and make synonym for decimal(x,2)

What about the printing of currency symbol?

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#9Thomas Lockhart
lockhart@alumni.caltech.edu
In reply to: Bruce Momjian (#8)
Re: [HACKERS] money data type and conversions

What about the printing of currency symbol?

Won't be missed, at least for anyone writing to SQL92 ;)

- Thomas

--
Thomas Lockhart lockhart@alumni.caltech.edu
South Pasadena, California

#10Bruce Momjian
bruce@momjian.us
In reply to: Vince Vielhaber (#3)
BeOS

For people wondering what BeOS is:

http://www.be.com/aboutbe/index.html

Seems it is an OS developed for digital media and network appliances.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#11D'Arcy J.M. Cain
darcy@druid.net
In reply to: Bruce Momjian (#8)
Re: [HACKERS] money data type and conversions

Thus spake Bruce Momjian

* Remove Money type and make synonym for decimal(x,2)

What about the printing of currency symbol?

That's the one thing that the new types don't offer but that was often
problematical anyway. In fact, I even submitted a patch to cash.c to
remove the currency symbol based on earlier discussions. The only
reason it wasn't added was that the type was supposed to be removed
soon anyway. Perhaps we should apply the patch anyway for now until
it is removed.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.
#12Bruce Momjian
bruce@momjian.us
In reply to: D'Arcy J.M. Cain (#11)
Re: [HACKERS] money data type and conversions

Thus spake Bruce Momjian

* Remove Money type and make synonym for decimal(x,2)

What about the printing of currency symbol?

That's the one thing that the new types don't offer but that was often
problematical anyway. In fact, I even submitted a patch to cash.c to
remove the currency symbol based on earlier discussions. The only
reason it wasn't added was that the type was supposed to be removed
soon anyway. Perhaps we should apply the patch anyway for now until
it is removed.

Not good to change behavour in a minor release if we can help it.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#13Don Baccus
dhogaza@pacifier.com
In reply to: Thomas Lockhart (#7)
Re: [HACKERS] money data type and conversions

At 01:52 AM 6/23/99 +0000, Thomas Lockhart wrote:

NUMERIC and DECIMAL are (or should be, if there are rough edges since
they are so new) are the SQL92-way to represent currency. And, they
are compatible with all different conventions, since you can set the
decimal place and size of the fractional part as you want.

This is an excellent point. The portable and standard numeric
and decimal types are the way to go.

- Don Baccus, Portland OR <dhogaza@pacifier.com>
Nature photos, on-line guides, and other goodies at
http://donb.photo.net