Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gD8O5-0004xY-AN for pgsql-general@arkaria.postgresql.org; Thu, 18 Oct 2018 13:30:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gD8O2-0004zt-Lh for pgsql-general@arkaria.postgresql.org; Thu, 18 Oct 2018 13:30:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gD8O0-0004zm-NY for pgsql-general@lists.postgresql.org; Thu, 18 Oct 2018 13:30:50 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gD8Nw-00012h-C5 for pgsql-general@postgresql.org; Thu, 18 Oct 2018 13:30:47 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 1A5532292E; Thu, 18 Oct 2018 09:30:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 18 Oct 2018 09:30:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=G 8xmP6s06XaGftWmEZD+hVHfI4/bgkXtP+zVhyqUulM=; b=GkMDhJq9GsCsDd24V ELfcB19oGTUDrylSOUkAW/4je1ix+jQ38xtv8YQ6TyA9Ey4Z2c3impf3yOTiXAUR EAMEFmm4NtvcNvlqtl4vvDio2DVxgJsAkIBBOcU8L336ByZzkk+9Ci1jGcfkioJQ rck2z2Wi/wbf/oahloRr51VHRY3HJio3hjgAd53rHPqjaojbXad55rttr6BBRVKP dzere98pv6lAzR1ALqqVgly36sMV/RnpGJzycEa4tpU8Dvm6pTkpG6uAOSZYgUb+ FwTr+bL3VX411ipaXsoMVlfYT9LAo984Ory35Yrpuw+OKxzFXp0qjpYxwTm2kCOj IHLYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=G8xmP6s06XaGftWmEZD+hVHfI4/bgkXtP+zVhyqUu lM=; b=yEkR6LPjzibsrzBR24b9JmO4WB2v0zcgGEqinx9zJ8BtTvEw1RJCVtXW2 YfJSzuZG/iGDRPvYNp11bJ8PGtjiR9NcYdnT1cpRt998TNyUXh4W4GkKypKc7wbK 846pEcK3lnyT/QJojBbFO9dLd+gbSr8DFFZT98NNa8qqw+Lv3nu4jZURPa6hDblg XxxmV2aodDbDmEyIcKURPYNEc4OlUHaJ4gkFGR7DKYkvwxKrWBn77cVE7qyFfi6O AyMxmYLX8v8mliC6Wj1UWjuL5vb0XHN9+8gCiVQX0u54wKAXOxlPjFJybvLypdLY JsiE6XKw6TcgXjmrzuqxwp6sPw9Pg== X-ME-Sender: X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 5E034102DD; Thu, 18 Oct 2018 09:30:42 -0400 (EDT) Subject: Re: convert real to numeric. To: Alessandro Aste , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <8cb0ba69-db9c-0796-9198-fea8d3ad2354@aklaver.com> Date: Thu, 18 Oct 2018 06:30:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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