From: | Joel Burton <joel(at)joelburton(dot)com> |
---|---|
To: | Szima Gábor <sygma(at)tesla(dot)hu> |
Cc: | Joel Burton <joel(at)joelburton(dot)com>, Rod Taylor <rbt(at)rbt(dot)ca>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: numeric to text (7.3) |
Date: | 2002-12-02 19:50:27 |
Message-ID: | 20021202195027.GA14132@temp.joelburton.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)joel=# select rtrim(rtrim('2.000'::numeric, '0'),'.');
rtrim
-------
2
(1 row)
joel(at)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(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Independent Knowledge Management Consultant
From | Date | Subject | |
---|---|---|---|
Next Message | Henner Zeller | 2002-12-02 19:50:42 | PG 7.3: Query Meta Data with the JDBC-driver |
Previous Message | Magnus Naeslund(f) | 2002-12-02 19:46:39 | Re: 7.4 Wishlist |