pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Edoardo Panfili <edoardopa@gmail.com>
To: Dave Cramer <davecramer@postgres.rocks>
Cc: pgsql-general@lists.postgresql.org, "Peter J. Holzer" <hjp-pgsql@hjp.at>
Subject: Re: The same prepared query yield "-1" the first six times and then "-1.0"
Date: Tue, 22 Aug 2023 07:54:15 +0200
Message-ID: <570F3DB4-CC9C-42EE-AF4A-DD8B811A5C5F@gmail.com> (raw)
In-Reply-To: <CADK3HH+2vG+-7Umic+v0kdTmQ-N8AejsX6C62Z1e03+Fu6kvFg@mail.gmail.com>
References: <5C40B9CC-40E4-4AC5-95A1-E5A521C282EF@gmail.com>
	<20230821181320.7wp52a747s5sehgu@hjp.at>
	<F1538417-A6F2-439E-B0C3-F74B7DDB353E@gmail.com>
	<CADK3HH+2vG+-7Umic+v0kdTmQ-N8AejsX6C62Z1e03+Fu6kvFg@mail.gmail.com>



> Il giorno 21 ago 2023, alle ore 21:37, Dave Cramer <davecramer@postgres.rocks> ha scritto:
> 
> 
> 
> On Mon, 21 Aug 2023 at 14:42, Edoardo Panfili <edoardopa@gmail.com <mailto:edoardopa@gmail.com>> wrote:
>> 
>> 
>> > Il giorno 21 ago 2023, alle ore 20:13, Peter J. Holzer <hjp-pgsql@hjp.at <mailto:hjp-pgsql@hjp.at>> ha scritto:
>> > 
>> > On 2023-08-21 17:27:20 +0200, Edoardo Panfili wrote:
>> >> The attended result was a sequence of ten equal values but this is the actual result:
>> >> p: -1
>> >> p: -1
>> >> p: -1
>> >> p: -1
>> >> p: -1
>> >> p: -1.0
>> >> p: -1.0
>> >> p: -1.0
>> >> p: -1.0
>> >> p: -1.0
>> > [...]
>> >> 2023-08-21 11:51:50.633 CEST [1511] user@testdb LOG: execute <unnamed>: SET extra_float_digits = 3
>> >> 2023-08-21 11:51:50.634 CEST [1511] user@testdb LOG: execute <unnamed>: SET application_name = 'PostgreSQL JDBC Driver'
>> >> 2023-08-21 11:51:50.644 CEST [1511] user@testdb LOG: execute <unnamed>: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.648 CEST [1511] user@testdb LOG: execute <unnamed>: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.649 CEST [1511] user@testdb LOG: execute <unnamed>: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.650 CEST [1511] user@testdb LOG: execute <unnamed>: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.651 CEST [1511] user@testdb LOG: execute S_1: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.651 CEST [1511] user@testdb LOG: execute S_1: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.653 CEST [1511] user@testdb LOG: execute S_1: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.653 CEST [1511] user@testdb LOG: execute S_1: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.654 CEST [1511] user@testdb LOG: execute S_1: SELECT dim1 FROM number WHERE name='first'
>> >> 2023-08-21 11:51:50.656 CEST [1511] user@testdb LOG: execute S_1: SELECT dim1 FROM number WHERE name=‘first'
>> > 
>> > Are these outputs from the same run?
>> Yes
>> 
>> > 
>> > I notice that the output from the program switches after 5 queries from
>> > "-1" to "-1-0", but the logged query name switches after 4 queries from
>> > "<unnamed>" to "S_1”.
>> 
>> You’re right.  It seem a JDBC side problem. I am doing some tests using suggestions from pgsql-jdbc list.
>> 
>> What sounds strange to me is that switching from “mode_X” to  “mode_Y” I obtain different representation of the same value,
>> 
>> I know the value is semantically the same.. but… in some way I like to see.. "a perfect postgresql env” (as it absolutely is)
>> 
>> Edoardo
>> 
> 
> I have confirmed that this behaviour is by design either by postgres or the driver. When postgres provides us the data using text mode we see -1 
> 
> (psql)
> select * from number ;
>  name  | dim1
> -------+------
>  first |   -1 
> 
> This is the way the data is presented by the text output function.
And I expected to obtain the same from the JDBC connection 


> In binary mode we see -1.0. This is an artifact of the binary output function.
> 
> If ResultSet.getDouble is used the data is the same ... -1 for both text and binary
> 
> Using getString we see the problem.
> 
> So you have a few options to stop this: Set prepareThreshold to 0 and the driver will not switch to named statements or binary,
Properties props = new Properties();
props.setProperty("prepareThreshold", "0");
Connection conn = DriverManager.getConnection(
	"jdbc:postgresql://192.168.64.7:5432/testdb?user=user&password=password”, props);

Obtains “-1” all the times

> Or remove double from binary transfer.

Thank you
Edoardo

view thread (19+ messages)  latest in thread

Message-ID: <570F3DB4-CC9C-42EE-AF4A-DD8B811A5C5F@gmail.com>
Permalink:  ../570F3DB4-CC9C-42EE-AF4A-DD8B811A5C5F@gmail.com/
Also on:    postgresql.org/message-id/570F3DB4-CC9C-42EE-AF4A-DD8B811A5C5F@gmail.com

 · 

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-general@postgresql.org
  Cc: edoardopa@gmail.com, davecramer@postgres.rocks, hjp-pgsql@hjp.at
  Subject: Re: The same prepared query yield "-1" the first six times and then "-1.0"
  In-Reply-To: <570F3DB4-CC9C-42EE-AF4A-DD8B811A5C5F@gmail.com>
  References: <5C40B9CC-40E4-4AC5-95A1-E5A521C282EF@gmail.com> <20230821181320.7wp52a747s5sehgu@hjp.at> <F1538417-A6F2-439E-B0C3-F74B7DDB353E@gmail.com> <CADK3HH+2vG+-7Umic+v0kdTmQ-N8AejsX6C62Z1e03+Fu6kvFg@mail.gmail.com> <570F3DB4-CC9C-42EE-AF4A-DD8B811A5C5F@gmail.com>

* 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