Re: to_number, to_char inconsistency.

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeremy Lowery <jslowery(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: to_number, to_char inconsistency.
Date: 2015-05-14 17:02:01
Message-ID: 20150514170201.GC23739@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Feb 10, 2013 at 06:27:02PM -0500, Tom Lane wrote:
> Jeremy Lowery <jslowery(at)gmail(dot)com> writes:
> > I load and dump text files with currency values in it. The decimal in these
> > input and output formats in implied. The V format character works great for
> > outputing numeric data:
>
> > # select to_char(123.45, '999V99');
> > to_char
> > ---------
> > 12345
> > (1 row)
>
> > However, when importing data, the V doesn't do the same thing:
>
> > # select to_number('12345', '999V99');
>
> A look at the source code shows that to_number doesn't do anything at
> all with the V format code, so this isn't terribly surprising. It
> wouldn't be very hard to make it do the right thing, probably, but
> nobody's had that particular itch yet. Feel free to scratch it and
> send a patch ...

(This is for 9.6.)

I have developed the attached patch to support 'V' with to_number().
Oracle doesn't support that, so we are on our own in defining the API.

The patch doesn't handle non-whole-number strings very well as there is
no way for the user to specify decimal precision because we have
overridden the decimal digit meaning, but that seems fine to me as most
users will be using whole numbers.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachment Content-Type Size
multi_to_char.diff text/x-diff 2.8 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2015-05-14 17:35:02 Re: ECPG SET CONNECTION
Previous Message Igor Neyman 2015-05-14 14:59:10 Re: Connection question