Re: Why length(to_char(1::integer, '9')) = 2 ?

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Dmitriy Igrishin <dmitigr(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, Sim Zacks <sim(at)compulab(dot)co(dot)il>
Subject: Re: Why length(to_char(1::integer, '9')) = 2 ?
Date: 2011-03-09 18:05:34
Message-ID: 4D77C16E.1080701@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/09/2011 09:59 AM, Dmitriy Igrishin wrote:
>
>
> 2011/3/9 Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com
> <mailto:adrian(dot)klaver(at)gmail(dot)com>>
>
> On Wednesday, March 09, 2011 5:34:41 am Dmitriy Igrishin wrote:
>
> >
> > But I am missing something or there is a documentation inaccuracy:
> >
> http://www.postgresql.org/docs/9.0/static/functions-formatting.html#FUNCTIO
> > NS-FORMATTING-NUMERICMOD-TABLEsays: fill mode (suppress padding
> blanks and
> > zeroes)
> >
> > Test:
> > dmitigr=> select to_char(12,'FM0009');
> > to_char
> > ---------
> > 0012
> >
> > dmitigr=> select length(to_char(12,'FM0009'));
> > length
> > --------
> > 4
> >
> > So, FM suppresses only padding blanks not zeroes...
> >
> > Any comments?
> >
>
> test(5432)aklaver=>select to_char(12,'9999');
> to_char
> ---------
> 12
>
> test(5432)aklaver=>select to_char(12,'FM9999');
> to_char
> ---------
> 12
>
> It is a little confusing, but you asked for the 0 in your
> specification so they
> are not considered padding.
>
> Look at the examples in the table listed below to get an idea of
> what I am
> talking about.
> http://www.postgresql.org/docs/9.0/static/functions-formatting.html
> Table 9-25
>
> Yes, I see, thanks!
>
> I just talking about phrase "fill mode (suppress padding blanks and zeroes)"
> in the documentation should be rephrased to "fill mode (suppress padding
> blanks)".

To get technical it means suppress unspecified padding O's. See below
for example.

>
> Or I misunderstood what is "padding zeroes" without explicitly
> specification "0" pattern in the format format template...

This combination from the example table shows that:

to_char(-0.1, 'FM9.99') '-.1'
to_char(0.1, '0.9') ' 0.1'

The 0 in 0.1 is not strictly needed, so if you use FM it will be suppressed.

>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)gmail(dot)com <mailto:adrian(dot)klaver(at)gmail(dot)com>
>
>
>
>
> --
> // Dmitriy.
>
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dmitriy Igrishin 2011-03-09 18:22:54 Re: Why length(to_char(1::integer, '9')) = 2 ?
Previous Message David Johnston 2011-03-09 18:01:13 Re: Copying data from one table to another - how to specify fields?