From: Tom Lane <tgl@sss.pgh.pa.us>
To: Graeme Merrall <gmerrall@email.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] round() and ||
Date: Thu, 20 Jan 2000 01:34:40 -0500
Message-ID: <20312.948350080@sss.pgh.pa.us> (raw)
In-Reply-To: <000f01bf62f0$0ebfff00$899d60cb@inspire.net.nz>
References: <000f01bf62f0$0ebfff00$899d60cb@inspire.net.nz>
"Graeme Merrall" <gmerrall@email.com> writes:
> SELECT round(services_cost,2) as test_field FROM services
> works fine but
> SELECT round(services_cost,2)::text as test_field FROM services
> as various other variations does not.
round() is actually a NUMERIC function --- implicitly, your float data
value is being converted to numeric, and then round() is applied.
The problem here is that there's no direct conversion from type numeric
to type text. There should be one :-(
In the meantime, it seems to work to coerce the numeric result back
to float:
select float8(round(33.337,2))::text;
33.34
select float8(round(33.337,2)) || ' more';
33.34 more
This depends on the reconversion to float not introducing an
unreasonable amount of error --- but if you were willing to store the
data as float in the first place, I hope that will be acceptable.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, gmerrall@email.com
Subject: Re: [SQL] round() and ||
In-Reply-To: <20312.948350080@sss.pgh.pa.us>
References: <000f01bf62f0$0ebfff00$899d60cb@inspire.net.nz> <20312.948350080@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox