to_char bug?

Поиск
Список
Период
Сортировка
Искать

to_char bug?

От:
"Ben Trewern" <bendottrewern@mowlem.com>
Дата:
Is there any reason why :

SELECT char_length(to_char(1, '000'));

Gives a result

 char_length
-------------
           4
(1 row)

It seems that to_char(1, '000') gives a string " 001" with a space in front. 
Is this a bug?

Regards,

Ben 


Re: to_char bug?

От:
Bricklen Anderson <BAnderson@PresiNET.com>
Дата:
Ben Trewern wrote:
> Is there any reason why :
> 
> SELECT char_length(to_char(1, '000'));
> 
> Gives a result
> 
>  char_length
> -------------
>            4
> (1 row)
> 
> It seems that to_char(1, '000') gives a string " 001" with a space in front. 
> Is this a bug?
> 
> Regards,
> 
> Ben 
> 
Try formatting the result:
SELECT char_length(to_char(1, 'fm000'));

char_length
-------------
            3

Re: to_char bug?

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Ben Trewern"  writes:
> It seems that to_char(1, '000') gives a string " 001" with a space in front. 
> Is this a bug?

No.

Possibly you want 'FM000'.

			regards, tom lane

Re: to_char bug?

От:
"Ben Trewern" <bendottrewern@mowlem.com>
Дата:
From the docs:

"FM suppresses leading zeroes and trailing blanks that would otherwise be 
added to make the output of a pattern be fixed-width"

It works now but for one I don't understand why the space is added in the 
firs place and two I think the docs don't tell the whole story ie leading 
blanks and I assume trailing zeros if applicable.

Regards,

Ben

"Tom Lane"  wrote in message 
news:794.1109627049@sss.pgh.pa.us...
> "Ben Trewern"  writes:
>> It seems that to_char(1, '000') gives a string " 001" with a space in 
>> front.
>> Is this a bug?
>
> No.
>
> Possibly you want 'FM000'.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 


Re: to_char bug?

От:
Martijn van Oosterhout <kleptog@svana.org>
Дата:
Вложения:
If the number is negative there needs to be room for the minus sign...

On Tue, Mar 01, 2005 at 09:25:02AM -0000, Ben Trewern wrote:
> >From the docs:
> 
> "FM suppresses leading zeroes and trailing blanks that would otherwise be 
> added to make the output of a pattern be fixed-width"
> 
> It works now but for one I don't understand why the space is added in the 
> firs place and two I think the docs don't tell the whole story ie leading 
> blanks and I assume trailing zeros if applicable.

-- 
Martijn van Oosterhout      http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Re: to_char bug?

От:
"Ben Trewern" <bendottrewern@mowlem.com>
Дата:


Thanks,  sometimes the obvious just passes me by. :-(

>If the number is negative there needs to be room for the minus sign...

"Martijn van Oosterhout"  wrote in message 
news:20050302103212.GA4567@svana.org... 


FAQ