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

From: Dave Cramer <davecramer(at)postgres(dot)rocks>
To: Ron <ronljohnsonjr(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: The same prepared query yield "-1" the first six times and then "-1.0"
Date: 2023-08-21 21:31:06
Message-ID: CADK3HH+7j80DH8BUuuavy+U4di23J8NFUnSZMO-A9jMCkcc_XQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 21 Aug 2023 at 17:17, Ron <ronljohnsonjr(at)gmail(dot)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.
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2023-08-21 22:05:05 Re: The same prepared query yield "-1" the first six times and then "-1.0"
Previous Message Ron 2023-08-21 20:00:31 Re: The same prepared query yield "-1" the first six times and then "-1.0"