Re: to_char() Question

From: Terry Lee Tucker <terry(at)esc1(dot)com>
To: PG-General General <pgsql-general(at)postgresql(dot)org>
Subject: Re: to_char() Question
Date: 2005-12-14 19:11:23
Message-ID: 200512141411.23742.terry@esc1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruno,

Thanks for the response. The only problem is that FM removes all the leading
spaces. I may have been unclear in stating my problem. I want the padding on
the left; however, I don't want the extra space for the sign (+,-) that gets
prepended to the string. This output shows what I mean:
rnd=# select to_char(1234, '"|"9999"|"');
to_char
---------
| 1234|
(1 row)
As you can see, not only do I get the four spaces I wanted, but I get one
additional. That is what I was trying to get rid of and John's solution
worked perfectly. It takes the extra space at the beginning out. I have a
couple overloaded functions handling this as well as ensuring that I'm not
dropping the negative sign on a number that actually is negative.

Anyway, thanks again for the response...

On Wednesday 14 December 2005 01:09 pm, Bruno Wolff III saith:
> On Tue, Dec 13, 2005 at 11:30:36 -0500,
>
> Terry Lee Tucker <terry(at)esc1(dot)com> wrote:
> > On Tuesday 13 December 2005 11:20 am, John Sidney-Woollett saith:
> > > Not sure if there is a numeric formatting option that allows what you
> > > want.
> > >
> > > But how about?
> > >
> > > substr(to_char(1029, '9,999'),2)
> >
> > That's so simple, I'm embarrased ;o)
> >
> > Thanks for the help...
>
> You can also us 'FM' to get rid of extra space. From the to_char docs:
> FM suppresses leading zeroes and trailing blanks that would otherwise be
> added to make the output of a pattern be fixed-width.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Juan Jose Siles Salinas 2005-12-14 19:18:05 Recuperar Base de datos
Previous Message Chris Browne 2005-12-14 19:06:57 Re: outdated (bad) information in pg_stat_activity