Re: convert real to numeric.

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Alessandro Aste <alessandro(dot)aste(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: convert real to numeric.
Date: 2018-10-18 13:30:41
Message-ID: 8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/18/18 3:28 AM, Alessandro Aste wrote:
> Hi,
>
>
>
> Postresql version: 10.5
>
> I need to convert an SQL field from real to numeric, but I’m getting a
> strange behavior.
>
> See the following query in preprod:
>
> select amount, amount::numeric, amount::numeric(16,4),
> amount::varchar::numeric from mytable where id = 32560545;
>
> Result:
>
> 17637.75, 17637.8, 17637.8000, 17637.75
>
> As you can see, the conversion to ::numeric is truncating the number to
> just 1 decimal digit.
>
> Also we tried to  change the schema definition of this table, from real
> to numeric, and the value was truncated.
>
> Is the ::varchar::numeric workaround a good option in your opinion? Any
> other ideas to fix this issue?

select 17637.75::real::numeric;
numeric
---------
17637.8

select 17637.75::float::numeric;
numeric
----------
17637.75

>
> Thank you,
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jehan-Guillaume (ioguix) de Rorthais 2018-10-18 13:45:04 Re: BUG: Incorrect working with POSIX locale if database in UTF-8 encoding
Previous Message Ozz Nixon 2018-10-18 12:33:48 Re: pg_dump backup utility is taking more time around 24hrs to take the backup of 28GB