Re: The same prepared query yield "-1" the first six times and then "-1.0" - Mailing list pgsql-general

From Dave Cramer
Subject Re: The same prepared query yield "-1" the first six times and then "-1.0"
Date
Msg-id CADK3HH+7j80DH8BUuuavy+U4di23J8NFUnSZMO-A9jMCkcc_XQ@mail.gmail.com
Whole thread Raw
In response to Re: The same prepared query yield "-1" the first six times and then "-1.0"  (Ron <ronljohnsonjr@gmail.com>)
Responses Re: The same prepared query yield "-1" the first six times and then "-1.0"  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
List pgsql-general


On Mon, 21 Aug 2023 at 17:17, Ron <ronljohnsonjr@gmail.com> wrote:
On 8/21/23 14:32, Dave Cramer wrote:
[snip]
It has to do with the way the data is being transferred. When the driver switches to a named statement it also switches to binary mode which means data will be transferred in binary. 

In text we get -1, in binary we get -1.0

That seems odd.  Why does it do that?

If we look at float8out_internal (text output)  https://github.com/postgres/postgres/blob/6fde2d9a005a5bc04aa059d3faeb865c8dd322ce/src/backend/utils/adt/float.c#L536 and the comment about extra float digits which states 

If >0, use shortest-decimal format for output; this is both the default and
allows for compatibility with clients that explicitly set a value here to
get round-trip-accurate results. If 0 or less, then use the old, slow,
decimal rounding method.

-1 would be the shortest-decimal format. 

whereas float8send sends the actual binary data on disk, hence -1.0

Dave
--
Born in Arizona, moved to Babylonia.

pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: The same prepared query yield "-1" the first six times and then "-1.0"
Next
From: "Peter J. Holzer"
Date:
Subject: Re: The same prepared query yield "-1" the first six times and then "-1.0"