Обсуждение: function to_char

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

function to_char

От
"Fontana Daniel C. \(Desartec S.R.L.\)"
Дата:

Hi, using postgres 12.5.

 

The to_char function has a problem with format length.

 

Example, select length (to_char (1, '990'))

 

returns 4 because?

 

if the format has length 3?

 




Avast logo

El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
www.avast.com


Re: function to_char

От
Guillaume Lelarge
Дата:
Hi,

Le sam. 17 avr. 2021 à 15:05, Fontana Daniel C. (Desartec S.R.L.) <desartecsrl@gmail.com> a écrit :

Hi, using postgres 12.5.

 

The to_char function has a problem with format length.

 

Example, select length (to_char (1, '990'))

 

returns 4 because?

 

if the format has length 3?

 


Actually, the format length isn't 3. It is 4 because you need one character to put the sign when needed.

postgres=# select '<'||to_char (+999, '990')||'>';
 ?column?
----------
 < 999>
(1 row)

postgres=# select '<'||to_char (-999, '990')||'>';
 ?column?
----------
 <-999>
(1 row)


--
Guillaume.