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

From Peter J. Holzer
Subject Re: The same prepared query yield "-1" the first six times and then "-1.0"
Date
Msg-id 20230821220505.xxeql573gtnuvccn@hjp.at
Whole thread Raw
In response to Re: The same prepared query yield "-1" the first six times and then "-1.0"  (Dave Cramer <davecramer@postgres.rocks>)
List pgsql-general
On 2023-08-21 17:31:06 -0400, Dave Cramer wrote:
> 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?
[...]
> whereas float8send sends the actual binary data on disk, hence -1.0

It should be noted that the binary representation is not "-1.0", but
something like
1 01111111 00000000000000000000000 (in binary or)
B    F   8    0   0   0   0   0    (in hex)
(big endian for better readability)

The decimal representation "-1.0" is created by the binary to string
conversion (Java's Float.toString()?). That could also produce "-1" or
"-1E0" or any other equivalent representation. The author of that
routine decided in include ".0" in the output, possibly to signify that
it's a floating point value, not an integer.

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Dave Cramer
Date:
Subject: Re: The same prepared query yield "-1" the first six times and then "-1.0"
Next
From: Amn Ojee Uw
Date:
Subject: Re: JDBC + PG-15 but not psql