pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tommaso Sala <tommaso.sala@cla-it.eu>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #12053: Strange behavior for numeric types with unspecified precision-scale
Date: Fri, 28 Nov 2014 19:17:34 -0500
Message-ID: <20726.1417220254@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPPt9DmSArf59pK3GU3pJgm1mZRnkUFBbsYnJDYmoVO4L_r2=g@mail.gmail.com>
References: <20141125111529.15508.34881@wrigleys.postgresql.org>
	<14914.1417017051@sss.pgh.pa.us>
	<CAPPt9DkAgK9MbLtLJB8B16N=5jyF4+-4jo9v2jqLudd5bwdPFQ@mail.gmail.com>
	<15613.1417121313@sss.pgh.pa.us>
	<CAPPt9DmSArf59pK3GU3pJgm1mZRnkUFBbsYnJDYmoVO4L_r2=g@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Tommaso Sala <tommaso.sala@cla-it.eu> writes:
> Hi, I already tried to log all, but it seems not to help a lot.
> In the StackOverflow question I originally linked in this bug report, I
> wrote the following:

>>>>> log_statement = 'all' gives a weirdER result:
>>>>> 
>>>>> UPDATE "TABLE" SET ... "WEIRD_FIELD"=$8 ... WHERE ...
>>>>> 
>>>>> DETAIL:  parameters: $1 = '7', $2 = '7', $3 = '18', $4 = '18', $5 = 'V03', $6 = 'Hz',
>>>>> $7 = 'Hz', $8 = '0.00', $9 = '0', $10 = '2', $11 = '0'

> The parameter for the weird field is printed as zero (0.00), but
> clearly it is not...

Ah, so you did have a parameterized statement and not just a plain-text
SQL command.  The log entry doesn't say whether the parameter value was
sent as text or binary, but if it had been sent as text, that would have
been exactly the string sent, and surely it'd have been read as plain old
zero.  If it had been sent as binary, this printout would be obtained the
same way as a regular "select *" would do, and we already know the bogus
value prints as 0.00 that way.

I did some experimentation and verified that if I manufacture a numeric
value that's really 0.001 but has dscale = 2, it will act precisely as
described in this report.  The commentary in numeric.c saith

 * dscale, or display scale, is the nominal precision expressed as number
 * of digits after the decimal point (it must always be >= 0 at present).
 * dscale may be more than the number of physically stored fractional digits,
 * implying that we have suppressed storage of significant trailing zeroes.
 * It should never be less than the number of stored digits, since that would
 * imply hiding digits that are present.

and that "hiding" is exactly what we're looking at.

So the question is whether it's worth adding logic to numeric_recv
to guard against bogus dscale values.  I think that detecting this
case would probably add a noticeable number of cycles to numeric_in.
(We can't just count the number of digits received, since (a) trailing
zeroes past dscale are OK, and (b) what we have at this point is
base-10000 digits not base-10 digits...)  I guess we're usually willing
to expend cycles to guard against client error, so maybe we should
do it here too.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (10+ messages)  latest in thread

Message-ID: <20726.1417220254@sss.pgh.pa.us>
Permalink:  ../20726.1417220254@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20726.1417220254@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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tommaso.sala@cla-it.eu
  Subject: Re: BUG #12053: Strange behavior for numeric types with unspecified precision-scale
  In-Reply-To: <20726.1417220254@sss.pgh.pa.us>
  References: <20141125111529.15508.34881@wrigleys.postgresql.org> <14914.1417017051@sss.pgh.pa.us> <CAPPt9DkAgK9MbLtLJB8B16N=5jyF4+-4jo9v2jqLudd5bwdPFQ@mail.gmail.com> <15613.1417121313@sss.pgh.pa.us> <CAPPt9DmSArf59pK3GU3pJgm1mZRnkUFBbsYnJDYmoVO4L_r2=g@mail.gmail.com> <20726.1417220254@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