vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| D'Arcy J.M. Cain wrote: > On Sat, 24 Nov 2007 11:27:38 -0500 (EST) > Bruce Momjian <bruce@momjian.us> wrote: > > I am confused about two other items with MONEY. First, why can't > > anything but a string be cast to this type? > > > > test=> select 871234872319489323::money; > > ERROR: cannot cast type bigint to money > > LINE 1: select 871234872319489323::money; > > ^ > > test=> select 871234872::money; > > ERROR: cannot cast type integer to money > > LINE 1: select 871234872::money; > > ^ > > test=> select 87123487231.3::money; > > ERROR: cannot cast type numeric to money > > LINE 1: select 87123487231.3::money; > > ^ > > I agree. I wasn't the one that added the meta information. OK, so the big question then is if we are un-depricating this data type, does it have the behavior we want? (And the regression addition will be helpful too.) -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://postgres.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
| |||
| Bruce Momjian wrote: > D'Arcy J.M. Cain wrote: > > On Sat, 24 Nov 2007 11:27:38 -0500 (EST) > > Bruce Momjian <bruce@momjian.us> wrote: > > > I am confused about two other items with MONEY. First, why can't > > > anything but a string be cast to this type? > > > > > > test=> select 871234872319489323::money; > > > ERROR: cannot cast type bigint to money > > > LINE 1: select 871234872319489323::money; > > > ^ > > > test=> select 871234872::money; > > > ERROR: cannot cast type integer to money > > > LINE 1: select 871234872::money; > > > ^ > > > test=> select 87123487231.3::money; > > > ERROR: cannot cast type numeric to money > > > LINE 1: select 87123487231.3::money; > > > ^ > > > > I agree. I wasn't the one that added the meta information. > > OK, so the big question then is if we are un-depricating this data type, > does it have the behavior we want? (And the regression addition will be > helpful too.) Added to TODO list: * Allow MONEY to be cast to/from other numeric data types -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://postgres.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| |||
| Bruce Momjian <bruce@momjian.us> writes: > Added to TODO list: > * Allow MONEY to be cast to/from other numeric data types So in other words, that's been added to the TODO list *purely* on your own say-so, and not because any users asked for it or anyone else thinks it's a good idea. Since MONEY really ought to be considered a tagged type, I'm not at all impressed with the idea that there should be default casts between it and plain numerics. There's a fundamental semantic gap there. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| |||
| "Joshua D. Drake" <jd@commandprompt.com> writes: > Well if we are going to continue to support money (which I am against) > we should support the casting to numeric as that is by far a more > common implementation of money and we will have mixed environments. So, you don't use MONEY, and you don't want to, but nonetheless you know better than the people who do use MONEY what they need. Aside from the semantic-gap issue, there is the point that providing a cast might actually mask application errors. I can well imagine cases where one of the reasons for using MONEY is *exactly* that it's not a plain number or easily convertible to one. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| |||
| Tom Lane wrote: > "Joshua D. Drake" <jd@commandprompt.com> writes: > > Well if we are going to continue to support money (which I am against) > > we should support the casting to numeric as that is by far a more > > common implementation of money and we will have mixed environments. > > So, you don't use MONEY, and you don't want to, but nonetheless you > know better than the people who do use MONEY what they need. I found out you can cast numerics to MONEY by using two casts: test=> SELECT 12321.12::text::money; money ------------ $12,321.12 (1 row) For some reason this doesn't work in 8.2 but does in 8.3. The reverse doesn't work: test=> SELECT '12321.12'::money::text::numeric; ERROR: invalid input syntax for type numeric: "$12,321.12" The big problem is that MONEY is a string so the dollar sign and commas are a problem. > Aside from the semantic-gap issue, there is the point that providing > a cast might actually mask application errors. I can well imagine > cases where one of the reasons for using MONEY is *exactly* that it's > not a plain number or easily convertible to one. Perhaps all we need is a way to accomplish the casting so it isn't automatic. This works: test=> SELECT regexp_replace('2343'::money::text, '[^$,]*', '', 'g')::numeric; regexp_replace ---------------- 2343.00 (1 row) but the '$' and ',' are locale-specific and I can't think of a way to do this generically. -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://postgres.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| ||||
| Tom Lane wrote: > Aside from the semantic-gap issue, there is the point that providing > a cast might actually mask application errors. *I can well imagine > cases where one of the reasons for using MONEY is *exactly* that it's > not a plain number or easily convertible to one. I'm always against casts, but I can hardly object to an explicit cast between money and numeric. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| Thread Tools | |
| Display Modes | |
|
|