Re: numeric to text (7.3)

Поиск
Список
Период
Сортировка
От Joel Burton
Тема Re: numeric to text (7.3)
Дата
Msg-id 20021202195027.GA14132@temp.joelburton.com
обсуждение исходный текст
Ответ на numeric to text (7.3)  (Szima Gábor <sygma@tesla.hu>)
Список pgsql-hackers
On Mon, Dec 02, 2002 at 08:23:24PM +0100, Szima Gábor wrote:
> OK, but:
> 
> template1=# select round('2.001'::numeric);
>  round
> -------
>      2
> (1 row)
> 
> template1=# select round('2.001'::numeric,2);
>  round
> -------
>   2.00
> (1 row)
> 
> 
> The good idea (in 7.2):
> 
> template1=# select text('2.000'::numeric);
>  text
> ------
>  2
> (1 row)
> 
> template1=# select text('2.001'::numeric);
>  text
> -------
>  2.001
> (1 row)
> 
> 
> This feature is missing from 7.3..

Not sure I'd call it a feature -- ISTM that text(numeric) should show
all the precision you gave it, and not shave it down to the
least-precise number that is still equal.

Anyhoo, you can get what you want with some ugly-but-straightforward
trimming:

(in 7.3):

joel@joel=# select rtrim(rtrim('2.000'::numeric, '0'),'.');rtrim
-------2
(1 row)

joel@joel=# select rtrim(rtrim('2.001'::numeric, '0'),'.');rtrim
-------2.001
(1 row)


Easy enough to make this into a function trim_as_much(numeric) or
somesuch.
   
-- 

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Magnus Naeslund(f)"
Дата:
Сообщение: Re: 7.4 Wishlist
Следующее
От: Henner Zeller
Дата:
Сообщение: PG 7.3: Query Meta Data with the JDBC-driver