Thread: L doesn't seem to be working in to_char()

L doesn't seem to be working in to_char()

From
Bill Moran
Date:
The user guide says that L should produce the currency symbol as defined
by the locale.  It doesn't seem to be working for me.

agelis=# select to_char(1257.5, 'LFM999G999G999G999D99');
  to_char
----------
   1,257.5
(1 row)

Can anyone confirm that this is a problem, or have I made a mistake
somewhere?  I'm running 7.4.1 on FreeBSD.

--
Bill Moran
Potential Technologies
http://www.potentialtech.com


Re: L doesn't seem to be working in to_char()

From
Tom Lane
Date:
Bill Moran <wmoran@potentialtech.com> writes:
> The user guide says that L should produce the currency symbol as defined
> by the locale.  It doesn't seem to be working for me.

Are you sure your locale defines one?  AFAICT, C locale doesn't.  The
to_char code seems to fall back to using a blank if there's no currency
symbol available from localeconv().

            regards, tom lane

Re: L doesn't seem to be working in to_char()

From
Bruce Momjian
Date:
Bill Moran wrote:
> The user guide says that L should produce the currency symbol as defined
> by the locale.  It doesn't seem to be working for me.
>
> agelis=# select to_char(1257.5, 'LFM999G999G999G999D99');
>   to_char
> ----------
>    1,257.5
> (1 row)
>
> Can anyone confirm that this is a problem, or have I made a mistake
> somewhere?  I'm running 7.4.1 on FreeBSD.

I got it working on FreeBSD 4.9.  The fix was to set lc_monetary
properly:

    template1=# set lc_monetary = 'en_US.ISO8859-1';
    SET
    template1=# select to_char(1257.5, 'LFM999G999G999G999D99');
     to_char
    ----------
     $1,257.5
    (1 row)


--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: L doesn't seem to be working in to_char()

From
Bill Moran
Date:
Bruce Momjian wrote:
> Bill Moran wrote:
>
>>The user guide says that L should produce the currency symbol as defined
>>by the locale.  It doesn't seem to be working for me.
>>
>>agelis=# select to_char(1257.5, 'LFM999G999G999G999D99');
>>  to_char
>>----------
>>   1,257.5
>>(1 row)
>>
>>Can anyone confirm that this is a problem, or have I made a mistake
>>somewhere?  I'm running 7.4.1 on FreeBSD.
>
> I got it working on FreeBSD 4.9.  The fix was to set lc_monetary
> properly:
>
>     template1=# set lc_monetary = 'en_US.ISO8859-1';
>     SET
>     template1=# select to_char(1257.5, 'LFM999G999G999G999D99');
>      to_char
>     ----------
>      $1,257.5
>     (1 row)

Yup, that's fixes it for me as well.  I'm guessing the reason this
works is contained in Tom's reply about the default 'C' locale not
having a monetary designator.

Thanks, Bruce.

--
Bill Moran
Potential Technologies
http://www.potentialtech.com