![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, is this a bug or am I misunderstanding something? db_atm=# select length(to_char(552020, '000000000')); length -------- 10 (1 row) in my opinion it should give 9... I am getting ugly errors for this... |
|
000552020| (1 row) |
#3
| |||
| |||
|
|
db_atm=# select '|' || to_char(552020, '000000000') || '|' as culptrit; culptrit -------------- | 000552020| (1 row) |
#4
| |||
| |||
|
|
Hi, is this a bug or am I misunderstanding something? db_atm=# select length(to_char(552020, '000000000')); length -------- 10 (1 row) in my opinion it should give 9... I am getting ugly errors for this... |
#5
| |||
| |||
|
|
On 02/03/2010 05:25 PM, Anselmo Canfora wrote: Hi, is this a bug or am I misunderstanding something? db_atm=# select length(to_char(552020, '000000000')); length -------- 10 (1 row) in my opinion it should give 9... I am getting ugly errors for this... Yep, it's documented: http://www.postgresql.org/docs/8.1/s...ormatting.html FM suppresses leading zeroes and trailing blanks that would otherwise be added to make the output of a pattern be fixed-width. So you should use 'FM000000000' |
#6
| |||
| |||
|
|
db_atm=# select length(to_char(552020, '000000000')); length -------- 10 (1 row) in my opinion it should give 9... I am getting ugly errors for this... Yep, it's documented: http://www.postgresql.org/docs/8.1/s...ormatting.html FM suppresses leading zeroes and trailing blanks that would otherwise be added to make the output of a pattern be fixed-width. So you should use 'FM000000000' rather strange, this behavior it is not really clear from documentation, "that would otherwise be added to make the output of a pattern be fixed-width" it is a part not really clear for me, in my example the pattern is one of 9 chars, to_char is adding a blank, giving a 10 char wide string, I don't get the reason of such implementation. |
#7
| |||
| |||
|
|
Anselmo Canfora wrote: db_atm=# select length(to_char(552020, '000000000')); length -------- 10 (1 row) in my opinion it should give 9... I am getting ugly errors for this... Yep, it's documented: http://www.postgresql.org/docs/8.1/s...ormatting.html FM suppresses leading zeroes and trailing blanks that would otherwise be added to make the output of a pattern be fixed-width. So you should use 'FM000000000' rather strange, this behavior it is not really clear from documentation, "that would otherwise be added to make the output of a pattern be fixed-width" it is a part not really clear for me, in my example the pattern is one of 9 chars, to_char is adding a blank, giving a 10 char wide string, I don't get the reason of such implementation. Distinguish between "the pattern" and "the output of a pattern". For "to_char(-1, '0')" you get "-1", so to make the output of the pattern fixed-with no matter what the input is, "to_char(1, '0')" will produce " 1". |

|
The reason for the implementation is easily given: This is an Oracle compatibility function, so it will behave like Oracle as much as it can. If you think that the behaviour is silly, file an enhancement request with Oracle and come back when they have changed it :^) |

|
Yours, Laurenz Albe |
![]() |
| Thread Tools | |
| Display Modes | |
| |