pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Carsten Klein <c.klein@datagis.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Strange results when casting string to double
Date: Sat, 19 Feb 2022 14:34:58 -0500
Message-ID: <80849.1645299298@sss.pgh.pa.us> (raw)
In-Reply-To: <99c8bac2-98e1-5315-7bca-d02d867c2b25@datagis.com>
References: <0d711ac6-6975-ae07-8963-aa91c6500776@datagis.com>
	<f3575aaf-98a8-6941-7843-ba1a0d78514f@enterprisedb.com>
	<4592fac1-05b2-f775-3332-c5a7d4c65b9d@datagis.com>
	<3950189.1645198347@sss.pgh.pa.us>
	<6593fee3-477b-6069-f91e-79f91075808f@datagis.com>
	<20220218214249.su6x5hi6ixauggku@hjp.at>
	<8c20dba1-4631-67c1-d317-a5e144acd821@sourcepole.ch>
	<99c8bac2-98e1-5315-7bca-d02d867c2b25@datagis.com>

Carsten Klein <c.klein@datagis.com> writes:
> @Tom Lane: you say, PostgreSQL does not / cannot change rounding mode at 
> any time? There is no function to do so? So, the script (it's more like 
> a module) must provide a Shared Object module with a C function in order 
> to change the FPU's rounding mode?

Per grep, there is no call of fesetround() in the Postgres source
tree.  I'm not sure offhand whether libc exposes any other APIs
that could change the rounding mode, but I am quite sure that we
wouldn't be intentionally changing it anywhere.

> I will try a restart of the DB ASAP. However, in order to prove the 
> rounding mode thesis: someone knows whether fesetround(FE_DOWNWARD) just 
> sets a flag in the C runtime environment or does this call actually set 
> the rounding mode in the FPU's control word? Is there any chance to get 
> that current rounding mode with or even without a debugger? (Maybe some 
> file in /proc filesystem?)

The OS would surely allow each process to have its own setting of the
rounding mode, so I doubt you can see it from outside.

Another point to keep in mind is that no matter how invasive that
import script might be, it's still hard to explain how it'd affect
the rounding mode in other backend processes.  You have to postulate
either that the rounding mode has been changed in the postmaster
process (and then inherited by session backends via fork()), or that
some code running at the time of child process creation changes the
mode, or that they replaced numeric_float8 with something else.

I think the only way that the postmaster's rounding mode could change
after postmaster start is the cosmic-ray hypothesis; while we do have
features that'd allow loading extra code into the postmaster, I'm
pretty sure they only take effect at postmaster start.  So even if
that import script tried to do that, it wouldn't have succeeded yet.

Of the other two hypotheses, "substitute numeric_float8" seems like
the most likely, especially given the other stuff you mentioned the
script doing.  Have you checked the relevant pg_cast entry to see
if it's been changed?  It'd also be interesting to see if the odd
rounding behavior happens in all databases of the cluster or just
one.

			regards, tom lane





view thread (24+ messages)  latest in thread

Message-ID: <80849.1645299298@sss.pgh.pa.us>
Permalink:  ../80849.1645299298@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/80849.1645299298@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, c.klein@datagis.com
  Subject: Re: Strange results when casting string to double
  In-Reply-To: <80849.1645299298@sss.pgh.pa.us>
  References: <0d711ac6-6975-ae07-8963-aa91c6500776@datagis.com> <f3575aaf-98a8-6941-7843-ba1a0d78514f@enterprisedb.com> <4592fac1-05b2-f775-3332-c5a7d4c65b9d@datagis.com> <3950189.1645198347@sss.pgh.pa.us> <6593fee3-477b-6069-f91e-79f91075808f@datagis.com> <20220218214249.su6x5hi6ixauggku@hjp.at> <8c20dba1-4631-67c1-d317-a5e144acd821@sourcepole.ch> <99c8bac2-98e1-5315-7bca-d02d867c2b25@datagis.com> <80849.1645299298@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