From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | Ingmar Brouns <swingi(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: to_char with locale decimal separator |
Date: | 2013-07-30 19:27:00 |
Message-ID: | 51F81384.70601@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 07/30/2013 08:34 AM, Ingmar Brouns wrote:
>
> Thanks for your time, appreciate it! As a dirty alternative, you could also do
> something like:
>
> select translate(5.000::text,'.',substr(to_char(.0),2,1));
>
> Not so nice, but would work. Though I still feel there should be a more
> elegant of doing this...
>
Two issues.
1) Leading and trailing zeros tend to be a personal preference and what
and how many, even more so. Pre-canned implementations for formatting
seem to best guess. I could see where trying to cover every conceivable
possibility would get complex.
2) You where looking at converting variable precision values, not
uncommon, but adds a layer of complexity. For instance using the Python
locale module it is possible to have it format a number according to
locale and have trailing zeros, but it will pad to the specified
precision(6 by default). So you still need to track something, in this
case precision.
You could take your quick and dirty solution and put it in a
function(to_char_trailing(numeric) and hide the dirty part:)
>> --
>> Adrian Klaver
>> adrian(dot)klaver(at)gmail(dot)com
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2013-07-30 21:57:53 | Re: How get column-wise table info from an arbitrary query? |
Previous Message | Gavin Flower | 2013-07-30 19:26:04 | Re: How get column-wise table info from an arbitrary query? |