Обсуждение: Money locale currency symbol position

Поиск
Список
Период
Сортировка

Money locale currency symbol position

От
Marko Mikulicic
Дата:
============================================================================
                          POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name               : Marko Mikulicic
Your email address      : marko@seul.org


System Configuration
---------------------
    Architecture (example: Intel Pentium)         : *

    Operating System (example: Linux 2.0.26 ELF)  : Linux 2.4.18

    PostgreSQL version (example: PostgreSQL-7.2.1):   PostgreSQL-7.2.1

    Compiler used (example:  gcc 2.95.2)          : *


Please enter a FULL description of your problem:
------------------------------------------------
src/backend/utils/adt/cash.c doesn't handle currency position at all.
It assumes that the currency symbol is at beggining of the string.
This is not acceptable for localized application. The situation
is also aggravated by the absence of the separator whitespace:

good: 12,32 F
bad:  F12,32


Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
set a european locale (say fr_FR) and start the database.

select 0::money;

it should output: 0,00 F


If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

The more general soultion would be to use "strfmon" function to handle
monetary output and completely ignore currency from input (either at
beginning or at end) and use "strtod" for locale support (decimal point).

   The code in cash.c should be cleaned up completely from hand-made
locale handling because it is not conforming to the standards, and since
   glibc has done the job much better.

I'm not sure, but it seems that "strfmon" is POSIX.

I suggest that for platforms which does not support strfmon (if it is
really POSIX) either drop locale support or provide a "strfmon"/"strtod"
emulation in a separated file/lib in order to minimize dependencies with
cash. This emulation could be based on code from glibc, if possible.

Re: Money locale currency symbol position

От
Tom Lane
Дата:
Marko Mikulicic <marko@seul.org> writes:
>    The code in cash.c should be cleaned up completely

Such criticism is best expressed in the form of a patch ;-)

Note though that most of us think the current money type is a kluge
anyway; anything based on int4 storage doesn't have enough significant
digits.  It would be better rewritten as a thin locale-aware veneer
over type "numeric".

            regards, tom lane

Re: Money locale currency symbol position

От
Tom Lane
Дата:
Marko Mikulicic <marko@seul.org> writes:
> Tom Lane wrote:
>> Note though that most of us think the current money type is a kluge
>> anyway; anything based on int4 storage doesn't have enough significant
>> digits.  It would be better rewritten as a thin locale-aware veneer
>> over type "numeric".

> I agree.
> Is there an example of  how to inherit from a parametrized type ?

I think you could mostly do this with binary compatibility: if money
were binary-equivalenced to numeric then most of the right things
would happen.  (Compare type regproc to type oid --- regproc has
no behavior other than special I/O functions, and still manages to
inherit most of oid's other behaviors.)

One thing you would not get out of that is the ability to say
"money(m,n)" to specify precision --- that would take specialized
hacking in the parser.  But I'm not sure you want it.  The preferred
number of fractional digits should be determined from the monetary
locale, *not* from any SQL declaration.  And there's no good reason to
limit the total number of digits at all.

> Is possible to view the CREATE TYPE command which creates the
> internal type numeric?

There is no such command, because internal types are "created" by
direct insertions of rows into pg_type during initdb.  Look at
the contents of src/include/catalog/pg_type.h.

> If you want to use numeric I guess you cannot use strfmon because it uses
> float or double and it's not arbitrary precision.

Ugh.  Time to start writing code :-(

            regards, tom lane

Re: Money locale currency symbol position

От
Marko Mikulicic
Дата:
Tom Lane wrote:
> Marko Mikulicic <marko@seul.org> writes:
>
>>   The code in cash.c should be cleaned up completely
>
>
> Such criticism is best expressed in the form of a patch ;-)

No problem, I will send you a patch. However I want to do things
right, because for now my patches for pgsql are ugly hacks that
I keep for myself, mostly for a matter of shame :-)

>
> Note though that most of us think the current money type is a kluge
> anyway; anything based on int4 storage doesn't have enough significant
> digits.  It would be better rewritten as a thin locale-aware veneer
> over type "numeric".
>
>             regards, tom lane

I agree.
Is there an example of  how to inherit from a parametrized type ?
(just redefine input output, reshape the string and pass it to the
"super class")
  Is it possible to redefine only the _in and _out methods of the type
inheriting all other methods.
  How can I creeate a new type using two paramaters (size and precision).
Is possible to view the CREATE TYPE command which creates the
internal type numeric?

If you want to use numeric I guess you cannot use strfmon because it uses
float or double and it's not arbitrary precision.
  Things should be done by hand, like now.

Marko