Re: Java : Postgres double precession issue with different data format text and binary

From: Chapman Flack <jcflack(at)acm(dot)org>
To: Rahul Uniyal <rahul(dot)uniyal00(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Java : Postgres double precession issue with different data format text and binary
Date: 2024-03-19 00:26:33
Message-ID: 65F8DBB9.9020107@acm.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-jdbc

Hi Rahul,

On 03/18/24 15:52, Rahul Uniyal wrote:
> Since the column format is text and not binary it converts the value
> to BigDecimal and give back the value as 40 .
> ...
> Now since the format is Binary ... it returns DOUBLE from there
> result in 40.0
>
> Now i am not sure for the same table and same column why we have two
> different format and this issue is intermittent.

I don't see, in this message or your earlier one, which public
ResultSet API method your Java client code is calling. It sounds as if
you are simply calling getObject, the flavor without a second parameter
narrowing the type, and you are finding that the object returned is
sometimes of class Double and sometimes of class BigDecimal. Is that
accurate? That would seem to be the nub of the issue.

You seem to have found that the class of the returned object is
influenced by whether text or binary format was used on the wire.
I will guess that would be worth reporting to the PGJDBC devs, using
the pgsql-jdbc list.

The question of why the driver might sometimes use one wire format
and sometimes the other seems secondary. There may be some technical
explanation, but it would not be very interesting except as an
implementation detail, if it did not have this visible effect of
changing the returned object's class.

For the time being, I assume that if your Java code calls a more
specific method, such as getObject(..., BigDecimal.class) or
getObject(..., Double.class), or simply getDouble, you will get
results of the desired class whatever wire format is used.

The issue of the wire format influencing what class of object
getObject returns (when a specific class hasn't been requested)
is probably worth raising on pgsql-jdbc.

Regards,
-Chap

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2024-03-19 00:33:44 Re: Have pg_basebackup write "dbname" in "primary_conninfo"?
Previous Message Tom Lane 2024-03-19 00:03:20 Re: Improving EXPLAIN's display of SubPlan nodes

Browse pgsql-jdbc by date

  From Date Subject
Next Message Rahul Uniyal 2024-03-19 03:21:44 Java - Inconsistent behaviour with double precession data type
Previous Message Rahul Uniyal 2024-03-18 19:52:00 Re: Java : Postgres double precession issue with different data format text and binary