pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Alessandro Aste <alessandro.aste@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: convert real to numeric.
Date: Thu, 18 Oct 2018 06:30:41 -0700
Message-ID: <8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com> (raw)
In-Reply-To: <CAM9F+O2m9nV7F95P3g5ymmxTTvdiB-s2F1KJqVZTKjE0ZvW2uw@mail.gmail.com>
References: <CAM9F+O2m9nV7F95P3g5ymmxTTvdiB-s2F1KJqVZTKjE0ZvW2uw@mail.gmail.com>

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.klaver@aklaver.com




view thread (6+ messages)  latest in thread

Message-ID: <8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com>
Permalink:  ../8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com/
Also on:    postgresql.org/message-id/8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com

 · 

reply

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-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, alessandro.aste@gmail.com
  Subject: Re: convert real to numeric.
  In-Reply-To: <8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com>
  References: <CAM9F+O2m9nV7F95P3g5ymmxTTvdiB-s2F1KJqVZTKjE0ZvW2uw@mail.gmail.com> <8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com>

* 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