Re: extra_float_digits and casting from real to numeric

From: Christoph Berg <christoph(dot)berg(at)credativ(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: extra_float_digits and casting from real to numeric
Date: 2014-01-08 09:40:17
Message-ID: 20140108094017.GA20317@msgid.df7cb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Re: Tom Lane 2014-01-07 <14979(dot)1389112998(at)sss(dot)pgh(dot)pa(dot)us>
> > But if extra_float_digits > 0 is set, I'd expect not only the float4
> > output to be affected by it, but also casts to other datatypes,
>
> This proposal scares me. extra_float_digits is strictly a matter of
> I/O representation, it does not affect any internal calculations.
> Moreover, since one of the fundamental attributes of type numeric
> is that it's supposed to give platform-independent results, I don't
> like the idea that you're likely to get platform-dependent results
> of conversions from float4/float8.

I forgot to mention one bit here, and that's actually what made me
think "wtf" and post here. The server log is of course also affected
by this, so you even get different parameters depending on
extra_float_digits, yet the numeric result is the same "bad" one:

2014-01-08 10:13:53 CET LOG: execute <unnamed>: INSERT INTO s VALUES($1)
2014-01-08 10:13:53 CET DETAIL: parameters: $1 = '10000.2'
2014-01-08 10:14:18 CET LOG: execute <unnamed>: INSERT INTO s VALUES($1)
2014-01-08 10:14:18 CET DETAIL: parameters: $1 = '10000.1797'

Of course this is all consistent and in practice sums up to "don't use
real/single"...

> I think your customer got bit by his own bad coding practice, and
> that should be the end of it.

What about this patch to mention this gotcha more explicitely in the
documentation?

diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
new file mode 100644
index 0386330..968f4a7
*** a/doc/src/sgml/datatype.sgml
--- b/doc/src/sgml/datatype.sgml
*************** NUMERIC
*** 689,694 ****
--- 689,697 ----
<literal>0</literal>, the output is the same on every platform
supported by PostgreSQL. Increasing it will produce output that
more accurately represents the stored value, but may be unportable.
+ Casts to other numeric datatypes and the <literal>to_char</literal>
+ function are not affected by this setting, it affects only the text
+ representation.
</para>
</note>

Christoph
--
cb(at)df7cb(dot)de | http://www.df7cb.de/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-01-08 09:48:57 Re: Standalone synchronous master
Previous Message Pavel Raiskup 2014-01-08 09:27:34 Re: pg_upgrade: make the locale comparison more tolerating