Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqRj1-0004vd-QD for psycopg@arkaria.postgresql.org; Thu, 25 Jul 2019 00:35:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqRj0-0000oP-LK for psycopg@arkaria.postgresql.org; Thu, 25 Jul 2019 00:35:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqRj0-0000oI-AO for psycopg@lists.postgresql.org; Thu, 25 Jul 2019 00:35:14 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqRiw-0000fP-V7 for psycopg@postgresql.org; Thu, 25 Jul 2019 00:35:13 +0000 Received: by mail-pg1-x542.google.com with SMTP id k189so3002236pgk.13 for ; Wed, 24 Jul 2019 17:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hbaspecto-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=MBNNUIq6caBugwqqSzPsqfstYDNm9kgvPRkAOtg4tqQ=; b=sCeO6ehRVPUR4oSGoNiAhSA4HEgxeCDiNDRvIEpncQnjjc+bKh+KVF00cHdkGKanZU DJaMqZez/793Jot293jshl5Cn5Fd82YiCN/z6kkAby2iSrdG6iCWG4JmHZudVTVWp+Fp vxrclpm/XGICGIbOpfxUSoVXWfJ3JT6zPJWI1+/eLJuxXXXjFM0Vp9KrTb8CtCNEnF0s l2YlxH1JvWskYcspEIP+N5cFnc8pN5vJP/RRRX3isMWp5c5xCRcKpZ2OShIiVz221x4m vQnUikwtozwJy6q87kZx9RMC+ORl/2jxeCuZUXru87SgMs7xK5rBV5NbIQFDrue/08jE vVYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=MBNNUIq6caBugwqqSzPsqfstYDNm9kgvPRkAOtg4tqQ=; b=WMPYbI778VDks0SdetXTsiIMmY7fLQcXt7lbLPxpEOTeytEaLeanjJUNlual+UKx9C MV+zqnl5DLbIsICpC9/PgsGwyKf7IL0suL8QeVE2c8gmvk2JqFXQKdcF5LHvIvBZOVd6 mGGDLGDUEPSrxXG5Jn9MGqiViA46IJgq2UXc6/EzaCEwhgTSElVLMdKE7EwkU7LnhRp8 8adJJh8Xal2RT+dpPQme1NYDNeqv4siZuS5OhgD1xrIjLh60iiqmAD+P642o8rwXL7jD HEOGhcBOOP4hS4jqPPuLK6SR9RfZbagFtmcZSMprR0ApCPU+93Tt3exxvb9JaUWYe1Yd DxBg== X-Gm-Message-State: APjAAAUJsOou4DqgFLgMlKuPPt2SC7S113qkHfU6zuwkxocxXEasRwj7 XEK3Lur7+qGeVylDkQUOs+cGSZg6 X-Google-Smtp-Source: APXvYqyWcVYGps6TT9M0VHMWhz5nLg2B1pvr0MI7f+oQHmtYOD++HFT9aXkbqmqacJiRiC5UuW55mA== X-Received: by 2002:a62:6044:: with SMTP id u65mr13620383pfb.15.1564014906786; Wed, 24 Jul 2019 17:35:06 -0700 (PDT) Received: from [128.189.211.70] (dhcp-128-189-211-70.ubcsecure.wireless.ubc.ca. [128.189.211.70]) by smtp.gmail.com with ESMTPSA id a21sm55136547pfi.27.2019.07.24.17.35.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 17:35:05 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: Rounding numbers from copy expert From: John Abraham X-Mailer: iPad Mail (16F203) In-Reply-To: Date: Wed, 24 Jul 2019 17:35:05 -0700 Cc: psycopg@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <046E2360-462C-4B55-8034-160E4612E493@hbaspecto.com> References: <8DC745DF-DDF9-4697-BAAF-23ABE78A1EB9@hbaspecto.com> To: Adrian Klaver List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jul 24, 2019, at 4:33 PM, Adrian Klaver wro= te: >=20 >> On 7/24/19 4:28 PM, John Abraham wrote: >> Hmm, I have two machines connecting to the same database running the same= query inside copy_expert. >> Both seem to have psycopg2 2.7.5 (based on pip3 freeze). >> One seems to be rounding the double precision number 696538951.985381 to 6= .96538944E8 whereas the other machine isn't rounding it. >=20 > First: >=20 > https://www.postgresql.org/docs/11/datatype-numeric.html#DATATYPE-FLOAT >=20 > 8.1.3. Floating-Point Types > "The data types real and double precision are inexact, variable-precision n= umeric types. ... >=20 > Inexact means that some values cannot be converted exactly to the internal= format and are stored as approximations, so that storing and retrieving a v= alue might show slight discrepancies. Managing these errors and how they pro= pagate through calculations is the subject of an entire branch of mathematic= s and computer science and will not be discussed here, except for the follow= ing points: ..." One of my proudest moments in my very first job in the late 80s was solving i= n just a few minutes a lack-of-precision problem my boss was fighting with f= or more than a day because he was subtracting two similar floating point num= bers. I=E2=80=99m enjoying the irony of fighting a similar problem now, myse= lf, 30 years later. Anyway, in this case it=E2=80=99s not the precision, it=E2=80=99s the repeat= ability. If you run the same program twice on two computers with the same s= oftware, you *should* get *exactly* the same answer. =20 >=20 > Second: >=20 > Where are you actually 'looking' at the values? I=E2=80=99m seeing the difference in a .CSV file produced by copy_expert, wh= ich as far as I can tell just streams the stdout from a database =E2=80=98co= py to stdout=E2=80=99 command to a text file. I=E2=80=99m trying to figure o= ut why the =E2=80=98copy to stdout=E2=80=99 SQL command would give different= interpretations of a number. >=20 >=20 >> This is causing auditability/repeatability problems, as the difference is= actually significant in this context. >> Is there some thing about the way psycopg2 connects to the database, or t= he way psycopg2 is configured, that could be causing this rounding? Is there= some way to express a preference for scientific notation? >> I'm at a complete loss as to why copy_expert (which basically does a 'cop= y to stdin' query) would be different when called from different machines. M= y next step in the madness is to see if the locale has an effect, one is set= to en_CA.UTF-8 and the other is set to en_US.UTF-8. But, perhaps someone e= lse has a better idea. >> Thanks for any help. >> -- >> John Abraham >> jea@hbaspecto.com >> 403-232-1060 >=20 >=20 > --=20 > Adrian Klaver > adrian.klaver@aklaver.com =E2=80=94 John Abraham